def perform_accept(act, overlapped): act.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) act.cbuff = create_string_buffer((sizeof(sockaddr_in) + 16) * 2) nbytes = c_ulong() prot_info = WSAPROTOCOL_INFO() prot_info_len = c_int(sizeof(prot_info)) getsockopt(act.sock.fileno(), SOL_SOCKET, SO_PROTOCOL_INFOA, cast(byref(prot_info), c_char_p), byref(prot_info_len)) # BOOL return AcceptEx( act.sock._fd.fileno(), # SOCKET sListenSocket act.conn.fileno(), # SOCKET sAcceptSocket cast(act.cbuff, c_void_p), # PVOID lpOutputBuffer 0, # DWORD dwReceiveDataLength prot_info.iMaxSockAddr + 16, # DWORD dwLocalAddressLength prot_info.iMaxSockAddr + 16, # DWORD dwRemoteAddressLength nbytes, # LPDWORD lpdwBytesReceived overlapped # LPOVERLAPPED lpOverlapped ), 0
#~ ) act.conn = act.sock.__class__(_sock=act.conn) return act def perform_connect(act, overlapped): # ConnectEx requires that the socket be bound beforehand try: # just in case we get a already-bound socket act.sock.bind(('0.0.0.0', 0)) except socket.error, exc: if exc[0] not in (errno.EINVAL, errno.WSAEINVAL): raise fileno = act.sock._fd.fileno() prot_info = WSAPROTOCOL_INFO() prot_info_len = c_int(sizeof(prot_info)) getsockopt(fileno, SOL_SOCKET, SO_PROTOCOL_INFOA, cast(byref(prot_info), c_char_p), byref(prot_info_len)) hints = addrinfo() hints.ai_family = prot_info.iAddressFamily hints.ai_socktype = prot_info.iSocketType hints.ai_protocol = prot_info.iProtocol result = addrinfo_p() getaddrinfo(act.addr[0], str(act.addr[1]), byref(hints), byref(result)); act.flags = result #~ act.sock.bind(('0.0.0.0', 0)) return ConnectEx( fileno, # SOCKET s