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 );
}
c->c_write_event = event;
c->c_private = listener;
+ ldap_pvt_thread_mutex_unlock( &c->c_mutex );
return c;
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;
}
event_del( c->c_write_event );
event_free( c->c_write_event );
+ c->c_struct_state = SLAP_C_UNINITIALIZED;
connection_destroy( c );
}
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 );
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 );
}
#endif
+ c->c_next_msgid = 1;
+
ldap_pvt_thread_mutex_init( &c->c_mutex );
ldap_pvt_thread_mutex_init( &c->c_io_mutex );
"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;
}
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 */
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;