Click to See Complete Forum and Search --> : IO Completion Ports for WSAConnect
menny_ed
December 29th, 2004, 04:06 AM
Hello,
i'm trying to build a client that can connect to many server.
i want the connection process (i.e., using WSAConnect) to be non-blocking.
i've already build the entire program. It uses IOCompletionPort for Send and Recv,
but the connect process is in non-blocking.
any ideas how i can fix that?
thanks
NoHero
December 29th, 2004, 08:16 AM
I think to create a non blocking socket you must use the 'WSASocket' function and specify WSA_FLAG_OVERLAPPED as flag. Refering to MSDN:
This flag causes an overlapped socket to be created. Overlapped sockets can utilize WSASend, WSASendTo, WSARecv, WSARecvFrom, and WSAIoctl for overlapped I/O operations, which allow multiple operations to be initiated and in progress simultaneously. All functions that allow overlapped operation (WSASend, WSARecv, WSASendTo, WSARecvFrom, WSAIoctl) also support nonoverlapped usage on an overlapped socket if the values for parameters related to overlapped operations are NULL.
menny_ed
December 29th, 2004, 08:36 AM
Hi.
i've my sockets are using the OVERLAPPED flag.
they do recv and send without blocking.
but the connect IS blocking. as you noticed from teh quote, MSDN did not talk about WSAConnect.
any ideas?
NoHero
December 29th, 2004, 08:49 AM
I cannot find anything that allows you create non-blocking sockets, but I think you should read this:
For connection-oriented, nonblocking sockets, it is often not possible to complete the connection immediately. In such cases, this function returns the error WSAEWOULDBLOCK. However, the operation proceeds. When the success or failure outcome becomes known, it may be reported in one of several ways depending on how the client registers for notification. If the client uses select, success is reported in the writefds set and failure is reported in the exceptfds set. If the client uses WSAAsyncSelect or WSAEventSelect, the notification is announced with FD_CONNECT and the error code associated with the FD_CONNECT indicates either success or a specific reason for failure.
Mathew Joy
December 29th, 2004, 01:39 PM
The only way to use overlapped calls in connect is to use ConnectEx(). There is a more detailed explanation of its use in the following FAQ.
Winsock: How do I use a timeout for 'connect()'? (http://www.codeguru.com/forum/showthread.php?t=312668)
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.