def perform_recv(act, overlapped): wsabuf = WSABUF() buf = create_string_buffer(act.len) wsabuf.buf = cast(buf, c_char_p) wsabuf.len = act.len nbytes = c_ulong(0) flags = c_ulong(0) act.flags = buf rc = WSARecv( act.sock._fd.fileno(), # SOCKET s byref(wsabuf), # LPWSABUF lpBuffers 1, # DWORD dwBufferCount byref(nbytes), # LPDWORD lpNumberOfBytesRecvd byref(flags), # LPDWORD lpFlags overlapped, # LPWSAOVERLAPPED lpOverlapped None # LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ) return rc, nbytes.value
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