Hi, I am trying to set something like this up but it doesn't seem to work as I expect it (unless I expect wrong): timeout.tv_sec = 4; timeout.tv_usec = 0; if(setsockopt(listenSocket, SOL_SOCKET, SO_RCVTIMEO, (void *)&timeout, sizeof(timeout)) == -1) fprintf(stdout, "setsockopt SO_RCVTIMEO failed: %s\n", strerror(errno)); if(setsockopt(listenSocket, SOL_SOCKET, SO_SNDTIMEO, (void *)&timeout, sizeof(timeout)) == -1) fprintf(stdout, "setsockopt SO_SNDTIMEO failed: %s\n", strerror(errno)); When I telnet to the socket, the socket always stays connected. The timer doesn't seem to work right. Am I missing anything here or is this broken? Please CC Thnx, Lefteris
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
Gleb Smirnoff wrote:> > You are expecting wrong from these socket options. They do not specify > time after which socket should be closed, if no IO is done.Is there any easy build in functionality for that? Thnx, Lefteris
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. -- Totus tuus, Glebius. GLEBIUS-RIPN GLEB-RIPE
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.Is there any easy way to setup IO timeouts (read/write) for a socket to close in case of inactivity?
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