Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost::asio - how to detect if a remote sockets client has disconnected
From: Scott Gifford (sgifford_at_[hidden])
Date: 2009-07-25 15:42:39


"Alex Black" <alex_at_[hidden]> writes:

> Is there a good way to do this?
>
> My server is a basic HTTP server, and if the client has disconnected
> while I'm still processing their request I'd like to abort the
> processing (e.g. no point doing work if the client is not there waiting
> for the data).

If the client closes the connection cleanly, you will get an
end-of-file if you try to read from the socket. You should be able to
get a notification of that if you have an asynchronous read
outstanding. If the client just disappears, you won't get any
notification until you try to send data (including the OS sending TCP
Keepalives, if they are enabled); then when that data send times out,
you will get an error, probably on your read or the next time you try
to write.

> I've read I can try to read from the socket, but in HTTP the client
> sends the request, and doesn't write any more to the socket.

You can still try to do an asynchronous read from the socket; it will
just never fire the event as long as there is no data to read.

Hope this helps,

----Scott.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net