Re: how to handle socket timeout?
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Fri, 11 Jan 2008 22:38:49 -0500
In article
<45b2a0bb-cc60-4a45-8aa3-8b62ed7b6636@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Arkadiy <vertleyb@xxxxxxxxx> wrote:
Hi all,
My client code connects a TCP socket, and then uses it to send
requests and recieve responces many times. What should I do when I
get a timeout? The examples I saw so far seem to suggest to continue
using the socket, however somehow I doubt this is correct, at least in
my case.
If recv() times out, this just means socket didn't get readable -- no
data in the TCP buffer. This doesn't necessarily mean this data won't
appear in this buffer after the timeout have happened. So, if I
continue using the socket, and send another request, the next response
I get (if I get it) will be to my old request...
recv() doesn't time out by default. So if you don't know what to do
about a timeout, don't use the SO_RECVTIMEO option in the first place.
So, my options would be to either keep track of the number of timed-
out requests, so that I can discard correct number of responses, or re-
create and re-connect the socket.
Or just wait for the response and process it when you get it, rather
than timing out.
Is this correct? Am I missing something?
The full answer is that it depends on the application protocol you're
implementing.
Also, with UDP, my server in its responce echoes the request ID that I
send. If I just discard the datagrams with request ID that doesn't
match, will it handle the timeout?
Again, it depends on the application. If you only care about the
response to the most recent request, this will work. But if you
pipeline requests, you may need to process all the responses even if
they arrive out of order.
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- Follow-Ups:
- Re: how to handle socket timeout?
- From: Arkadiy
- Re: how to handle socket timeout?
- References:
- how to handle socket timeout?
- From: Arkadiy
- how to handle socket timeout?
- Prev by Date: Incorrect function address placed in function pointer in dynamically linked shared library
- Next by Date: Re: Incorrect function address placed in function pointer in dynamically linked shared library
- Previous by thread: how to handle socket timeout?
- Next by thread: Re: how to handle socket timeout?
- Index(es):
Relevant Pages
|