Re: Question about howto do proper timeout checking on connections

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alun Jones [MSFT] (alunj_at_online.microsoft.com)
Date: 06/30/04


Date: Tue, 29 Jun 2004 17:39:03 -0700


"Onemangang" <theonemangang@hotmail.com> wrote in message
news:uL2ZR2cXEHA.1656@TK2MSFTNGP09.phx.gbl...
> Setsockopt returns zero, indicating that the so_rcvtimeo was
> set sucessfully. I used a timeout of 2500 ms to test this.

Implementing your own timeouts is a better way of doing this, because you
can include the timeout processing in your regular worker thread pools. I
don't know if so_rcvtimeo is supported for all non-blocking sockets, but the
documentation for setsockopt does state that so_rcvtimeo is supported for
recv(). You are using WSARecv().

On the topic of the way you're timing out, why not simply build a sorted
structure (a list or something), on the basis of how soon the socket will
time-out? Each time data is received or sent on a socket, just pump it to
the end of the list, and when it's time to check for timeouts, you just
remove those sockets at the front that are timed out, and don't search if
the front socket isn't ready to be timed out. And you use the timeout value
of the first socket as being the next time to wait.

Alun.
~~~~



Relevant Pages

  • Re: CreateTimerQueueTimer fails unexpectedly
    ... I send a command to a device and the device does not respond, ... So, in case of timeout I don't call shutdown, ... but a key point is that when the timer runs, ... written to deal with socket disconnect. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: CreateTimerQueueTimer fails unexpectedly
    ... Consider that if the IOOPs are file IO, then timeout is irrelevant; and if stream socket based, then a transport issue; and if datagram socket based, conflict with the stateless completion processing model that underlies IOCP. ... For cases where the protocol is very complex, a dedicated thread sync IO model often works well, but if you opt for stateless IO, then you must implement application protocol level timeouts using an out-of-band mechanism (ie a timer) that will trigger a logical close. ... Because overlapped WSARecvhas no integrated timeout mechanism and it only completes when some data is available for read, I should keep track of time so that I can inform clients if the respond does not arrive in the desired time period. ...
    (microsoft.public.win32.programmer.kernel)
  • Re: CreateTimerQueueTimer fails unexpectedly
    ... I send a command to a device over the same socket and expect response in a certain time interval. ... Because overlapped WSARecv() has no integrated timeout mechanism and it only completes when some data is available for read, I should keep track of time ... // break out of loop ...
    (microsoft.public.win32.programmer.kernel)
  • Re: proper way to close a socket?
    ... has a 20-30 second timeout with two results: ... // which means you need a loop here. ... err = WSAETIMEDOUT; ... The bottom line is that all socket implementations is synchronous ...
    (microsoft.public.vc.mfc)
  • Re: GetStream.Read behavior changed in .Net 2.0 with respect to ReceiveTimeout
    ... I only mentioned alternatives to implementing a timeout. ... Most socket i/o code does not bother with a timeout at all. ... Via a BeginXXX method you tell .NET to call a specific method when the i/o completes, and when it completes, your method is called. ...
    (microsoft.public.dotnet.framework)