Re: Question about howto do proper timeout checking on connections

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: 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)
  • Re: Socket recv() question?
    ... You might be doing something crazy, writing the data to the file one byte ... socket function correctly? ... The PC would send the data and Pocket PC would receive it. ... Configure tx timeout ...
    (microsoft.public.windowsce.app.development)
  • Re: Threads and socket.setdefaulttimeout
    ... settimeout on the socket) was because it seemed like the only way (and ... > their timeout period to allow other runnable threads to proceed. ... making the since-bad choice of using setdefaulttimeout to get timeouts ... code needs to check the lock to avoid conflict. ...
    (comp.lang.python)
  • Re: GetStream.Read behavior changed in .Net 2.0 with respect to ReceiveTimeout
    ... underlying mechanism for the ReceiveTimeout property): ... socket, the socket state is indeterminate, and ... than using the ReceiveTimeout property. ... a timeout explicitly, rather than having the socket manage the timeout ...
    (microsoft.public.dotnet.framework)
  • Re: GetStream.Read behavior changed in .Net 2.0 with respect to ReceiveTimeout
    ... I only mentioned alternatives to implementing a timeout. ... socket i/o code does not bother with a timeout at all. ... you call the BeginXXX method again to repeat the sequence. ...
    (microsoft.public.dotnet.framework)