Hi, all I try to add nonblocking connect for libevent-iocp backend.
Currently, when we use nonblocking connect with libevent, the source maybe like this: s = socket( ... ); setnonblock( s ); connect(s,(struct sockaddr *)&dest_addr,(socklen_t)sizeof(dest_addr)); event_add( ... ); event_loop(); If it use win32 select backend, it is OK. But if it use win32 iocp backend, it seems GQCS will never return this socket. The source maybe like this: s = socket( ... ); setnonblock( s ); connect(s,(struct sockaddr *)&dest_addr,(socklen_t)sizeof(dest_addr)); event_add( ... ) { .... WASRecv( s, ... ); } event_loop( ... ) { GetQueuedCompletionStatus( ... ); } I think we need to use the same way as the nonblocking accept. http://monkeymail.org/archives/libevent-users/2008-June/001269.html The first time, the iocp backend requires a EV_ACCEPT flag. At the last, it use getsockopt(SO_ACCEPTCONN) to distinguish accept/read. http://monkeymail.org/archives/libevent-users/2008-June/001309.html Is there any getsockopt options to distinguish connect/write event? http://msdn.microsoft.com/en-us/library/ms737625(VS.85).aspx With a nonblocking socket, the connection attempt cannot be completed immediately. In this case, connect will return SOCKET_ERROR, and WSAGetLastError will return WSAEWOULDBLOCK. In this case, there are three possible scenarios: * Use the select function to determine the completion of the connection request by checking to see if the socket is writeable. * If the application is using WSAAsyncSelect to indicate interest in connection events, then the application will receive an FD_CONNECT notification indicating that the connect operation is complete (successfully or not). * If the application is using WSAEventSelect to indicate interest in connection events, then the associated event object will be signaled indicating that the connect operation is complete (successfully or not). Best Regards, Stephen Liu _______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkeymail.org/mailman/listinfo/libevent-users