changeset 64:6add229288a8 stable-4-3

only keep 20% of the open resolver sockets in the ready pool.
author carl
date Sun, 16 Jan 2005 09:20:50 -0800
parents 579dc5955cbe
children 1ab70970c8c8
files src/dnsbl.cpp
diffstat 1 files changed, 12 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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