Index: src/ngircd/conf.c
===================================================================
RCS file: /srv/cvs/ngircd/ngircd/src/ngircd/conf.c,v
retrieving revision 1.77
diff -u -r1.77 conf.c
--- src/ngircd/conf.c	17 Jun 2005 19:16:53 -0000	1.77
+++ src/ngircd/conf.c	11 Oct 2005 15:34:14 -0000
@@ -204,6 +204,7 @@
 	 * Non-Server-Connections will be silently ignored. */
 
 	int i;
+	time_t t;
 
 	/* Check all our configured servers */
 	for( i = 0; i < MAX_SERVERS; i++ )
@@ -221,11 +222,14 @@
 		else
 		{
 			/* Set time for next connect attempt */
-			if( Conf_Server[i].lasttry <  time( NULL ) - Conf_ConnectRetry )
-			{
-				/* Okay, the connection was established "long enough": */
-				Conf_Server[i].lasttry = time( NULL ) - Conf_ConnectRetry + RECONNECT_DELAY;
-			}
+			t = time(NULL);
+			if (Conf_Server[i].lasttry < t - Conf_ConnectRetry) {
+				/* The connection has been "long", so we don't
+				 * require the next attempt to be delayed. */
+				Conf_Server[i].lasttry =
+					t - Conf_ConnectRetry + RECONNECT_DELAY;
+			} else
+				Conf_Server[i].lasttry = t;
 		}
 	}
 } /* Conf_UnsetServer */
Index: src/ngircd/conn.c
===================================================================
RCS file: /srv/cvs/ngircd/ngircd/src/ngircd/conn.c,v
retrieving revision 1.155.2.2
diff -u -r1.155.2.2 conn.c
--- src/ngircd/conn.c	25 Aug 2005 09:04:23 -0000	1.155.2.2
+++ src/ngircd/conn.c	11 Oct 2005 15:34:15 -0000
@@ -713,9 +713,15 @@
 			Conn_WriteStr(Idx, "ERROR :Closing connection.");
 	}
 
-	/* Try to write out the write buffer */
+	/* Try to write out the write buffer. Note: Handle_Write() eventually
+	 * removes the CLIENT structure associated with this connection if an
+	 * error occurs! So we have to re-check if there is still an valid
+	 * CLIENT structure after calling Handle_Write() ...*/
 	(void)Handle_Write( Idx );
 
+	/* Search client, if any (re-check!) */
+	c = Client_GetFromConn( Idx );
+
 	/* Shut down socket */
 	if( close( My_Connections[Idx].sock ) != 0 )
 	{
@@ -859,23 +865,28 @@
 		res = getsockopt( My_Connections[Idx].sock, SOL_SOCKET, SO_ERROR, &err, &sock_len );
 		assert( sock_len == sizeof( err ));
 
-		/* Fehler aufgetreten? */
-		if(( res != 0 ) || ( err != 0 ))
-		{
-			/* Fehler! */
-			if( res != 0 ) Log( LOG_CRIT, "getsockopt (connection %d): %s!", Idx, strerror( errno ));
-			else Log( LOG_CRIT, "Can't connect socket to \"%s:%d\" (connection %d): %s!", My_Connections[Idx].host, Conf_Server[Conf_GetServer( Idx )].port, Idx, strerror( err ));
-
-			/* Clean up socket, connection and client structures */
-			FD_CLR( My_Connections[Idx].sock, &My_Sockets );
-			c = Client_GetFromConn( Idx );
-			if( c ) Client_DestroyNow( c );
-			close( My_Connections[Idx].sock );
-			Init_Conn_Struct( Idx );
-
-			/* Bei Server-Verbindungen lasttry-Zeitpunkt auf "jetzt" setzen */
-			Conf_Server[Conf_GetServer( Idx )].lasttry = time( NULL );
-			Conf_UnsetServer( Idx );
+		/* Error while connecting? */
+		if ((res != 0) || (err != 0)) {
+			if (res != 0)
+				Log(LOG_CRIT, "getsockopt (connection %d): %s!",
+				    Idx, strerror(errno));
+			else
+				Log(LOG_CRIT,
+				    "Can't connect socket to \"%s:%d\" (connection %d): %s!",
+				    My_Connections[Idx].host,
+				    Conf_Server[Conf_GetServer(Idx)].port,
+				    Idx, strerror(err));
+
+			/* Clean up the CLIENT structure (to avoid silly log
+			 * messages) and call Conn_Close() to do the rest. */
+			c = Client_GetFromConn(Idx);
+			if (c)
+				Client_DestroyNow(c);
+
+			Conn_Close(Idx, "Can't connect!", NULL, false);
+
+			/* Set the timestamp of the last connect attempt */
+			Conf_UnsetServer(Idx);
 
 			return false;
 		}
