comparison src/context.cpp @ 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 d9d2f8699621
children f4746d8a12a3
comparison
equal deleted inserted replaced
128:9ab51896447f 129:c5cd1261394d
65 verify_map verifiers; 65 verify_map verifiers;
66 string_set all_strings; // owns all the strings, only modified by the config loader thread 66 string_set all_strings; // owns all the strings, only modified by the config loader thread
67 const int maxlen = 1000; // used for snprintf buffers 67 const int maxlen = 1000; // used for snprintf buffers
68 const int maxage = 120; // smtp verify sockets older than this are ancient 68 const int maxage = 120; // smtp verify sockets older than this are ancient
69 extern int NULL_SOCKET; 69 extern int NULL_SOCKET;
70 extern time_t ERROR_SOCKET_TIME; // number of seconds between attempts to open a socket an smtp host for address verification 70 const time_t ERROR_SMTP_SOCKET_TIME = 600; // number of seconds between attempts to open a socket to an smtp server
71 71
72 72
73 int SMTP::writer() { 73 int SMTP::writer() {
74 #ifdef VERIFY_DEBUG 74 #ifdef VERIFY_DEBUG
75 log("writer() sees buffer with %s", buffer); 75 log("writer() sees buffer with %s", buffer);
291 conn->log("get_connection() %d from cache", conn->get_fd()); 291 conn->log("get_connection() %d from cache", conn->get_fd());
292 #endif 292 #endif
293 } 293 }
294 pthread_mutex_unlock(&mutex); 294 pthread_mutex_unlock(&mutex);
295 if (conn) return conn; 295 if (conn) return conn;
296 time_t now = time(NULL);
297 int sock = NULL_SOCKET; 296 int sock = NULL_SOCKET;
298 if ((now - last_err) > ERROR_SOCKET_TIME) { 297 if ((time(NULL) - last_err) > ERROR_SMTP_SOCKET_TIME) {
299 // nothing recent, maybe this time it will work 298 // nothing recent, maybe this time it will work
300 hostent *h = gethostbyname(host); 299 hostent *h = gethostbyname(host);
301 if (h) { 300 if (h) {
302 sockaddr_in server; 301 sockaddr_in server;
303 server.sin_family = h->h_addrtype; 302 server.sin_family = h->h_addrtype;
308 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); 307 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0);
309 if (!rc) { 308 if (!rc) {
310 shutdown(sock, SHUT_RDWR); 309 shutdown(sock, SHUT_RDWR);
311 close(sock); 310 close(sock);
312 sock = NULL_SOCKET; 311 sock = NULL_SOCKET;
313 last_err = now; 312 last_err = time(NULL);
314 } 313 }
315 } 314 }
316 else last_err = now; 315 else last_err = time(NULL);
317 } 316 }
318 else last_err = now; 317 else last_err = time(NULL);
319 } 318 }
320 if (sock != NULL_SOCKET) { 319 if (sock != NULL_SOCKET) {
321 conn = new SMTP(sock); 320 conn = new SMTP(sock);
322 #ifdef VERIFY_DEBUG 321 #ifdef VERIFY_DEBUG
323 conn->log("get_connection() %d new socket", conn->get_fd()); 322 conn->log("get_connection() %d new socket", conn->get_fd());