Index: src/ngircd/conf.c
===================================================================
RCS file: /usr/local/CVS/ngircd/ngircd/src/ngircd/conf.c,v
retrieving revision 1.87
diff -u -r1.87 conf.c
--- src/ngircd/conf.c	24 Sep 2005 17:06:54 -0000	1.87
+++ src/ngircd/conf.c	11 Oct 2005 16:06:27 -0000
@@ -254,6 +254,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++ ) {
@@ -267,10 +268,14 @@
 			Init_Server_Struct( &Conf_Server[i] );
 		} 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: /usr/local/CVS/ngircd/ngircd/src/ngircd/conn.c,v
retrieving revision 1.183
diff -u -r1.183 conn.c
--- src/ngircd/conn.c	24 Sep 2005 02:48:46 -0000	1.183
+++ src/ngircd/conn.c	11 Oct 2005 16:06:28 -0000
@@ -138,25 +138,30 @@
 	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 )) {
-		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 */
-			c = Client_GetFromConn( idx );
-			if( c ) Client_DestroyNow( c );
-			io_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 );
-			return;
+	/* 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;
 	}
 
 	Conn_OPTION_DEL( &My_Connections[idx], CONN_ISCONNECTING );
@@ -731,9 +736,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( ! io_close( My_Connections[Idx].sock ))
 	{
