Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Oct 2005 14:31:38 +0400
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        Lefteris Tsintjelis <lefty@ene.asda.gr>
Cc:        freebsd-stable@FreeBSD.org
Subject:   Re: setsockopt and SO_RCV/SNDTIMEO
Message-ID:  <20051007103138.GN14542@cell.sick.ru>
In-Reply-To: <4345A3DA.1020803@ene.asda.gr>
References:  <4345A3DA.1020803@ene.asda.gr>

next in thread | previous in thread | raw e-mail | index | archive | help
  Lefteris,

On Fri, Oct 07, 2005 at 01:23:22AM +0300, Lefteris Tsintjelis wrote:
L> I am trying to set something like this up but it doesn't seem to work
L> as I expect it (unless I expect wrong):
L> 
L> timeout.tv_sec = 4;
L> timeout.tv_usec = 0;
L> if(setsockopt(listenSocket, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout, 
L> sizeof(timeout)) == -1)
L> 	fprintf(stdout, "setsockopt SO_RCVTIMEO failed: %s\n", 
L> 	strerror(errno));
L> if(setsockopt(listenSocket, SOL_SOCKET, SO_SNDTIMEO, (void *)&timeout, 
L> sizeof(timeout)) == -1)
L> 	fprintf(stdout, "setsockopt SO_SNDTIMEO failed: %s\n", 
L> 	strerror(errno));
L> 
L> When I telnet to the socket, the socket always stays connected. The
L> timer doesn't seem to work right. Am I missing anything here or is
L> this broken?

You are expecting wrong from these socket options. They do not specify
time after which socket should be closed, if no IO is done.

The do limit time the process can block on the socket. So, if you
do read() from this socket and it blocks, it will resume after 4 seconds
even if no input is present.

-- 
Totus tuus, Glebius.
GLEBIUS-RIPN GLEB-RIPE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051007103138.GN14542>