# HG changeset patch # User carl # Date 1105896050 28800 # Node ID 6add229288a808e88b38afc979dc0d6f70bc18e3 # Parent 579dc5955cbe3f2528a5a2aacdceb3a6deeecf39 only keep 20% of the open resolver sockets in the ready pool. diff -r 579dc5955cbe -r 6add229288a8 src/dnsbl.cpp --- a/src/dnsbl.cpp Sun Jan 16 08:33:55 2005 -0800 +++ b/src/dnsbl.cpp Sun Jan 16 09:20:50 2005 -0800 @@ -288,13 +288,15 @@ //////////////////////////////////////////////// // disconnect the fd from the dns resolver process // -void my_disconnect(int sock); -void my_disconnect(int sock) +void my_disconnect(int sock, bool decrement = true); +void my_disconnect(int sock, bool decrement) { if (sock != NULL_SOCKET) { + if (decrement) { pthread_mutex_lock(&fd_pool_mutex); resolver_sock_count--; pthread_mutex_unlock(&fd_pool_mutex); + } shutdown(sock, SHUT_RDWR); close(sock); } @@ -321,7 +323,7 @@ if (sock != NULL_SOCKET) { bool rc = (connect(sock, (sockaddr *)&server, sizeof(server)) == 0); if (!rc) { - my_disconnect(sock); + my_disconnect(sock, false); sock = NULL_SOCKET; last_error_time = now; } @@ -420,13 +422,14 @@ fd = *i; fd_pool.erase(fd); resolver_pool_size--; + pthread_mutex_unlock(&fd_pool_mutex); } else { // pool is empty, get a new fd + pthread_mutex_unlock(&fd_pool_mutex); fd = my_connect(); err = (fd == NULL_SOCKET); } - pthread_mutex_unlock(&fd_pool_mutex); } else { // cannot lock the pool, just get a new fd @@ -448,13 +451,14 @@ // return the fd to the pool fd_pool.insert(fd); resolver_pool_size++; + pthread_mutex_unlock(&fd_pool_mutex); } else { // more than 20% of the open resolver sockets are in the pool, and the // pool as at least 5 sockets. that is enough, so just close this one. + pthread_mutex_unlock(&fd_pool_mutex); my_disconnect(fd); } - pthread_mutex_unlock(&fd_pool_mutex); } else { // could not lock the pool, so just close the fd