src/server/daemon/httplistener.c

changeset 440
d77b8f3e14e2
parent 438
22eca559aded
child 441
797aeb31a2c6
--- a/src/server/daemon/httplistener.c	Sat Nov 26 19:14:29 2022 +0100
+++ b/src/server/daemon/httplistener.c	Sat Nov 26 19:15:33 2022 +0100
@@ -465,6 +465,24 @@
     }
 }
 
+int http_listener_socket_eq(HttpListener *l1, HttpListener *l2) {
+    if(l1->server_socket && l2->server_socket && l1->server_socket == l2->server_socket) {
+        return TRUE;
+    }
+    if(l1->server_socket6 && l2->server_socket6 && l1->server_socket6 == l2->server_socket6) {
+        return TRUE;
+    }
+    return FALSE;
+}
+
+void http_listener_set_next(HttpListener *listener, HttpListener *next) {
+    while(listener->next) {
+        listener = listener->next;
+    }
+    
+    http_listener_ref(next);
+    listener->next = next;
+}
 
 
 Acceptor* acceptor_new(HttpListener *listener) {
@@ -522,6 +540,7 @@
                 server_socket,
                 ca_ptr,
                 &length);
+        log_ereport(LOG_DEBUG, "acceptor: %p listener: %p: accept(): %d", acceptor, acceptor->listener, clientfd);
         if (clientfd == -1) {
             log_ereport(LOG_FAILURE, "accept %s failed: %s", acceptor->ipv6 ? "ipv6" : "ipv4", strerror(errno));
             continue;
@@ -535,7 +554,7 @@
             acceptor_exit = 1;
         }
         
-        /* create Connection object */
+        // create Connection object
         Connection *conn = malloc(sizeof(Connection));
         conn->address = ca;
         conn->addr_type = addr_type;
@@ -571,13 +590,13 @@
         if(conn) {
             cfg_ref(ls->cfg);
 
-            /* enqueue the connection */
+            // enqueue the connection
             ls->session_handler->enqueue_connection(
                     ls->session_handler,
                     conn);
         }
 
-        /* ready for new connection */
+        // ready for new connection
         
         if(acceptor_exit) {
             // this acceptor is outdated
@@ -586,7 +605,9 @@
         }
     }
     
-    http_listener_unref(listener->next);
+    if(listener->next) {
+        http_listener_unref(listener->next);
+    }
     http_listener_unref(listener);
     
     return NULL;

mercurial