1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
5 def connect(long s, object addr, object obj):
7 CAUTION: unlike system ConnectEx(), this function returns 0 on success
11 cdef sockaddr_in ipv4_name
12 cdef sockaddr_in6 ipv6_name
16 if not have_connectex:
17 raise ValueError, 'ConnectEx is not available on this system'
19 family = getAddrFamily(s)
21 name = <sockaddr *>&ipv4_name
22 namelen = sizeof(ipv4_name)
23 fillinetaddr(&ipv4_name, addr)
24 elif family == AF_INET6:
25 name = <sockaddr *>&ipv6_name
26 namelen = sizeof(ipv6_name)
27 fillinet6addr(&ipv6_name, addr)
29 raise ValueError, 'unsupported address family'
30 name.sa_family = family
34 ov.obj = <PyObject *>obj
36 rc = lpConnectEx(s, name, namelen, NULL, 0, NULL, <OVERLAPPED *>ov)
39 rc = WSAGetLastError()
40 if rc != ERROR_IO_PENDING:
44 # operation is in progress