comparison src/dnsbl.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 9ab51896447f
children df355d117199
comparison
equal deleted inserted replaced
128:9ab51896447f 129:c5cd1261394d
86 pthread_mutex_t syslog_mutex; 86 pthread_mutex_t syslog_mutex;
87 pthread_mutex_t resolve_mutex; 87 pthread_mutex_t resolve_mutex;
88 pthread_mutex_t fd_pool_mutex; 88 pthread_mutex_t fd_pool_mutex;
89 89
90 std::set<int> fd_pool; 90 std::set<int> fd_pool;
91 int NULL_SOCKET = -1; 91 const int NULL_SOCKET = -1;
92 char *resolver_port = NULL; // unix domain socket to talk to the dns resolver process 92 const time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open a socket to the dns resolver process
93 int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests 93 char *resolver_port = NULL; // unix domain socket to talk to the dns resolver process
94 time_t ERROR_SOCKET_TIME = 60; // number of seconds between attempts to open a socket to the dns resolver process 94 int resolver_socket = NULL_SOCKET; // socket used to listen for resolver requests
95 time_t last_error_time; 95 time_t last_error_time;
96 int resolver_sock_count = 0; // protected with fd_pool_mutex 96 int resolver_sock_count = 0; // protected with fd_pool_mutex
97 int resolver_pool_size = 0; // protected with fd_pool_mutex 97 int resolver_pool_size = 0; // protected with fd_pool_mutex
98 98
99 99
186 // return fd connected to the dns resolver process 186 // return fd connected to the dns resolver process
187 // 187 //
188 int my_connect(); 188 int my_connect();
189 int my_connect() { 189 int my_connect() {
190 // if we have had recent errors, don't even try to open the socket 190 // if we have had recent errors, don't even try to open the socket
191 time_t now = time(NULL); 191 if ((time(NULL) - last_error_time) < ERROR_SOCKET_TIME) return NULL_SOCKET;
192 if ((now - last_error_time) < ERROR_SOCKET_TIME) return NULL_SOCKET;
193 192
194 // nothing recent, maybe this time it will work 193 // nothing recent, maybe this time it will work
195 int sock = NULL_SOCKET; 194 int sock = NULL_SOCKET;
196 sockaddr_un server; 195 sockaddr_un server;
197 memset(&server, '\0', sizeof(server)); 196 memset(&server, '\0', sizeof(server));
201 if (sock != NULL_SOCKET) { 200 if (sock != NULL_SOCKET) {
202 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); 201 bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0);
203 if (!rc) { 202 if (!rc) {
204 my_disconnect(sock, false); 203 my_disconnect(sock, false);
205 sock = NULL_SOCKET; 204 sock = NULL_SOCKET;
206 last_error_time = now; 205 last_error_time = time(NULL);
207 } 206 }
208 } 207 }
209 else last_error_time = now; 208 else last_error_time = time(NULL);
210 if (sock != NULL_SOCKET) { 209 if (sock != NULL_SOCKET) {
211 pthread_mutex_lock(&fd_pool_mutex); 210 pthread_mutex_lock(&fd_pool_mutex);
212 resolver_sock_count++; 211 resolver_sock_count++;
213 pthread_mutex_unlock(&fd_pool_mutex); 212 pthread_mutex_unlock(&fd_pool_mutex);
214 } 213 }