setsockopt and SO_RCV/SNDTIMEO
Chuck Swiger
cswiger at mac.com
Fri Oct 7 08:31:21 PDT 2005
Gleb Smirnoff wrote:
> On Fri, Oct 07, 2005 at 05:04:40PM +0300, Lefteris Tsintjelis wrote:
> L> >You are expecting wrong from these socket options. They do not specify
> L> >time after which socket should be closed, if no IO is done.
> L>
> L> Is there any easy build in functionality for that?
>
> Pardon, but I do not understand the question.
He wants the connection to be closed after a certain number of seconds if it is
idle.
Lefterius, when you read() from the socket, call time(). If you read more than
zero bytes, save that time in a variable. If you read zero bytes, compare what
time it is now to the saved value, and if the delta is greater than when you
want an idle connection to close, well, call close() and exit or whatever.
Details like initializing the variable to now beforehand are probably needed.
--
-Chuck
More information about the freebsd-stable
mailing list