MCPcopy Index your code
hub / github.com/python/cpython / connect

Method connect

Lib/asyncio/windows_events.py:577–606  ·  view source on GitHub ↗
(self, conn, address)

Source from the content-addressed store, hash-verified

575 return future
576
577 def connect(self, conn, address):
578 if conn.type == socket.SOCK_DGRAM:
579 # WSAConnect will complete immediately for UDP sockets so we don't
580 # need to register any IOCP operation
581 _overlapped.WSAConnect(conn.fileno(), address)
582 fut = self._loop.create_future()
583 fut.set_result(None)
584 return fut
585
586 self._register_with_iocp(conn)
587 # The socket needs to be locally bound before we call ConnectEx().
588 try:
589 _overlapped.BindLocal(conn.fileno(), conn.family)
590 except OSError as e:
591 if e.winerror != errno.WSAEINVAL:
592 raise
593 # Probably already locally bound; check using getsockname().
594 if conn.getsockname()[1] == 0:
595 raise
596 ov = _overlapped.Overlapped(NULL)
597 ov.ConnectEx(conn.fileno(), address)
598
599 def finish_connect(trans, key, ov):
600 ov.getresult()
601 # Use SO_UPDATE_CONNECT_CONTEXT so getsockname() etc work.
602 conn.setsockopt(socket.SOL_SOCKET,
603 _overlapped.SO_UPDATE_CONNECT_CONTEXT, 0)
604 return conn
605
606 return self._register(ov, conn, finish_connect)
607
608 def sendfile(self, sock, file, offset, count):
609 self._register_with_iocp(sock)

Callers 2

_sock_connectMethod · 0.45
sock_connectMethod · 0.45

Calls 6

_register_with_iocpMethod · 0.95
_registerMethod · 0.95
filenoMethod · 0.45
create_futureMethod · 0.45
set_resultMethod · 0.45
getsocknameMethod · 0.45

Tested by

no test coverage detected