]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Update connection init
authorOndřej Kuzník <ondra@mistotebe.net>
Thu, 16 Mar 2017 11:41:07 +0000 (11:41 +0000)
committerOndřej Kuzník <okuznik@symas.com>
Tue, 17 Nov 2020 17:15:40 +0000 (17:15 +0000)
servers/lloadd/client.c
servers/lloadd/connection.c
servers/lloadd/slap.h

index 13926891d0a82a65868fa09b20ad221f364d0168..d40fe49d87359534b2b1620fa2608d7d7ac4e8a8 100644 (file)
@@ -30,10 +30,11 @@ static void
 client_read_cb( evutil_socket_t s, short what, void *arg )
 {
     Connection *c = arg;
+
+    ldap_pvt_thread_mutex_lock( &c->c_mutex );
     Debug( LDAP_DEBUG_CONNS, "client_read_cb: "
             "connection %lu ready to read\n",
             c->c_connid );
-    evutil_closesocket( s );
     client_destroy( c );
 }
 
@@ -75,6 +76,7 @@ client_init(
     c->c_write_event = event;
 
     c->c_private = listener;
+    ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 
     return c;
 fail:
@@ -86,6 +88,7 @@ fail:
         event_del( c->c_read_event );
         event_free( c->c_read_event );
     }
+    c->c_struct_state = SLAP_C_UNINITIALIZED;
     connection_destroy( c );
     return NULL;
 }
@@ -99,5 +102,6 @@ client_destroy( Connection *c )
     event_del( c->c_write_event );
     event_free( c->c_write_event );
 
+    c->c_struct_state = SLAP_C_UNINITIALIZED;
     connection_destroy( c );
 }
index f1d4ea55c0d165d3bd947844f1b27f7f37b8506f..9824de22844c2c94d888b5f00508bbc159d624dc 100644 (file)
@@ -54,6 +54,14 @@ void
 connection_destroy( Connection *c )
 {
     assert( c );
+    Debug( LDAP_DEBUG_CONNS, "connection_destroy: "
+            "destroying connection %lu.\n",
+            c->c_connid );
+
+    assert( c->c_struct_state == SLAP_C_UNINITIALIZED );
+    evutil_closesocket( c->c_fd );
+
+    ldap_pvt_thread_mutex_unlock( &c->c_mutex );
 
     ldap_pvt_thread_mutex_destroy( &c->c_io_mutex );
     ldap_pvt_thread_mutex_destroy( &c->c_mutex );
@@ -84,6 +92,7 @@ connection_init( ber_socket_t s, const char *peername, int flags )
 
     c = ch_calloc( 1, sizeof(Connection) );
 
+    c->c_fd = s;
     c->c_sb = ber_sockbuf_alloc();
     ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
 
@@ -132,6 +141,8 @@ connection_init( ber_socket_t s, const char *peername, int flags )
     }
 #endif
 
+    c->c_next_msgid = 1;
+
     ldap_pvt_thread_mutex_init( &c->c_mutex );
     ldap_pvt_thread_mutex_init( &c->c_io_mutex );
 
@@ -141,8 +152,8 @@ connection_init( ber_socket_t s, const char *peername, int flags )
             "connection connid=%lu allocated for socket fd=%d\n",
             c->c_connid, s );
 
+    ldap_pvt_thread_mutex_lock( &c->c_mutex );
+    c->c_struct_state = SLAP_C_USED;
+
     return c;
-fail:
-    connection_destroy( c );
-    return NULL;
 }
index c79fae79e231b34d257756d7ebfd0e5bb628ca70..bceed14bacffbaa4c99206789c234bdca345e7bd 100644 (file)
@@ -265,7 +265,7 @@ enum sc_conn_state {
 struct Connection {
     enum sc_struct_state c_struct_state; /* structure management state */
     enum sc_conn_state c_conn_state;     /* connection state */
-    ber_socket_t c_sd;
+    ber_socket_t c_fd;
 
     ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
     Sockbuf *c_sb;                   /* ber connection stuff */
@@ -275,7 +275,8 @@ struct Connection {
     struct berval c_peer_name; /* peer name (trans=addr:port) */
     time_t c_starttime;        /* when the connection was opened */
 
-    time_t c_activitytime; /* when the connection was last used */
+    time_t c_activitytime;  /* when the connection was last used */
+    ber_int_t c_next_msgid; /* msgid of the next message */
 
     struct event *c_read_event, *c_write_event;