changeset 129:c5cd1261394d

ignore smtp connection attempts for 10 minutes when getting connection errors on verify hosts
author carl
date Tue, 06 Jun 2006 08:45:07 -0700
parents 9ab51896447f
children e316f6fd9c39
files src/context.cpp src/dnsbl.cpp
diffstat 2 files changed, 12 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/context.cpp	Thu Apr 27 10:05:43 2006 -0700
+++ b/src/context.cpp	Tue Jun 06 08:45:07 2006 -0700
@@ -67,7 +67,7 @@
 const int maxlen = 1000;	// used for snprintf buffers
 const int maxage = 120; 	// smtp verify sockets older than this are ancient
 extern int	  NULL_SOCKET;
-extern time_t ERROR_SOCKET_TIME;	// number of seconds between attempts to open a socket an smtp host for address verification
+const time_t  ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server
 
 
 int SMTP::writer() {
@@ -293,9 +293,8 @@
 		}
 	pthread_mutex_unlock(&mutex);
 	if (conn) return conn;
-	time_t now = time(NULL);
 	int sock = NULL_SOCKET;
-	if ((now - last_err) > ERROR_SOCKET_TIME) {
+	if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) {
 		// nothing recent, maybe this time it will work
 		hostent *h = gethostbyname(host);
 		if (h) {
@@ -310,12 +309,12 @@
 					shutdown(sock, SHUT_RDWR);
 					close(sock);
 					sock = NULL_SOCKET;
-					last_err = now;
+					last_err = time(NULL);
 				}
 			}
-			else last_err = now;
+			else last_err = time(NULL);
 		}
-		else last_err = now;
+		else last_err = time(NULL);
 	}
 	if (sock != NULL_SOCKET) {
 		conn = new SMTP(sock);
--- a/src/dnsbl.cpp	Thu Apr 27 10:05:43 2006 -0700
+++ b/src/dnsbl.cpp	Tue Jun 06 08:45:07 2006 -0700
@@ -88,10 +88,10 @@
 pthread_mutex_t  fd_pool_mutex;
 
 std::set<int>	 fd_pool;
-int    NULL_SOCKET		 = -1;
+const int	 NULL_SOCKET	   = -1;
+const time_t ERROR_SOCKET_TIME = 60;			// number of seconds between attempts to open a socket to the dns resolver process
 char  *resolver_port	 = NULL;		 // unix domain socket to talk to the dns resolver process
 int    resolver_socket	 = NULL_SOCKET;  // socket used to listen for resolver requests
-time_t ERROR_SOCKET_TIME = 60;			 // number of seconds between attempts to open a socket to the dns resolver process
 time_t last_error_time;
 int    resolver_sock_count = 0; 		 // protected with fd_pool_mutex
 int    resolver_pool_size  = 0; 		 // protected with fd_pool_mutex
@@ -188,8 +188,7 @@
 int my_connect();
 int my_connect() {
 	// if we have had recent errors, don't even try to open the socket
-	time_t now = time(NULL);
-	if ((now - last_error_time) < ERROR_SOCKET_TIME) return NULL_SOCKET;
+	if ((time(NULL) - last_error_time) < ERROR_SOCKET_TIME) return NULL_SOCKET;
 
 	// nothing recent, maybe this time it will work
 	int sock = NULL_SOCKET;
@@ -203,10 +202,10 @@
 		if (!rc) {
 			my_disconnect(sock, false);
 			sock = NULL_SOCKET;
-			last_error_time = now;
+			last_error_time = time(NULL);
 		}
 	}
-	else last_error_time = now;
+	else last_error_time = time(NULL);
 	if (sock != NULL_SOCKET) {
 		pthread_mutex_lock(&fd_pool_mutex);
 			resolver_sock_count++;