> Is there any way we can control the timeout on connect()? I
requested
> Winsock 2.0 and got it, and thus tried using setsockopt() with
SO_SNDTIMEO
> and SO_RCVTIMEO:
Wow... not often I can answer my own
question, but here's how it can be done:
Old code:
Result = connect(m_Sock,(SOCKADDR_T
*)&m_PeerAddr,sizeof(m_PeerAddr));
if(Result !=
0)
// React to
failure here...
New code:
// V1.93: Try to use events to timeout
the connect(), since the
// above clearly does not work.
hEvent =
::WSACreateEvent();
::WSAEventSelect(m_Sock, hEvent, FD_CONNECT);
// This automatically makes the socket non-blocking.
Cool.
Result = connect(m_Sock,(SOCKADDR_T
*)&m_PeerAddr,sizeof(m_PeerAddr));
// V1.93: Now
wait with timeout.
dwResult = ::WSAWaitForMultipleEvents(1,
&hEvent, FALSE, 5000, FALSE);
if (dwResult !=
WSA_WAIT_EVENT_0) //
I.e., the event did not
occur
// (did not connect [in time]
).
// React to failure
here...
// V1.93: Disable the event system for this
socket again.
::WSAEventSelect(m_Sock, hEvent,
0);
::WSACloseEvent(hEvent);
// Set back to
blocking.
ulNonBlocking = 0 ;
ioctlsocket(m_Sock, FIONBIO,
&ulNonBlocking);
Hope that helps someone else fighting the same issue.
--
Jason Teagle
[EMAIL PROTECTED]
_______________________________________________ msvc mailing list [email protected] See http://beginthread.com/mailman/listinfo/msvc_beginthread.com for subscription changes, and list archive.
