NNTPC: 1.0.6: Detecting disconnected servers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The strategy that nntpcache appears to use to detect if a previously
used server has gone away (idled out) is flawed.

In attachServer, the (apparent) strategy used is to call getpeername()
on the socket to see if it is still valid.  However, if the remote
server has idled out the connection, the socket is in CLOSE_WAIT, and
getpeername() actually succeeds (at least under Linux 2.0.30).

This means that nntp commands, that could be satisfied by simply
reconnecting to the remote server, return errors to the readers.

As an alternative approach, the following patch uses select on the
server fd that is about to be attempted to be reused.  It selects for
read with a zero timeout on the assumption that a closed socket will
return ready for reading, and there should not be any data to be read
from previous commands.

There is still the small possibility that between calling attachServer,
and actually sending a command the remote news server could idle
the connection, but dealing with this mean changing the structure of
nntpcache significantly.

--- sockets.c~	Sun Apr 13 19:11:11 1997
+++ sockets.c	Sun Apr 13 19:19:35 1997
@@ -51,9 +51,16 @@
 	 */
 	if (scfg->fd >= 0)
 	{
-	       struct sockaddr_in sa;
-	       int sa_len = sizeof sa;
-	       if (getpeername (scfg->fd, (struct sockaddr *) &sa, &sa_len) == 0)
+		fd_set rdfs;
+		struct timeval tv;
+
+		FD_ZERO (&rdfs);
+		FD_SET (scfg->fd, &rdfs);
+
+		tv.tv_sec = 0;
+		tv.tv_usec = 0;
+
+	        if (select (scfg->fd + 1, &rdfs, NULL, NULL, &tv) == 0)
 	       {
 	       		/* we have delayed group binding. make sure group is bound, but only
 			 * if this server is the current server. non-current servers do not

-- 
 `O O'  | Nick.Holloway@alfie.demon.co.uk  http://www.alfie.demon.co.uk/
// ^ \\ | Nick.Holloway@parallax.co.uk  http://www.parallax.co.uk/~alfie/


[Index of Archives]     [Yosemite]     [Yosemite Campsites]     [Bugtraq]     [Linux]     [Trn]

Powered by Linux