mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-12 10:54:48 +08:00
Update connection init
This commit is contained in:
parent
8e0a6119fa
commit
1a45249054
@ -30,10 +30,11 @@ static void
|
|||||||
client_read_cb( evutil_socket_t s, short what, void *arg )
|
client_read_cb( evutil_socket_t s, short what, void *arg )
|
||||||
{
|
{
|
||||||
Connection *c = arg;
|
Connection *c = arg;
|
||||||
|
|
||||||
|
ldap_pvt_thread_mutex_lock( &c->c_mutex );
|
||||||
Debug( LDAP_DEBUG_CONNS, "client_read_cb: "
|
Debug( LDAP_DEBUG_CONNS, "client_read_cb: "
|
||||||
"connection %lu ready to read\n",
|
"connection %lu ready to read\n",
|
||||||
c->c_connid );
|
c->c_connid );
|
||||||
evutil_closesocket( s );
|
|
||||||
client_destroy( c );
|
client_destroy( c );
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +76,7 @@ client_init(
|
|||||||
c->c_write_event = event;
|
c->c_write_event = event;
|
||||||
|
|
||||||
c->c_private = listener;
|
c->c_private = listener;
|
||||||
|
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
fail:
|
fail:
|
||||||
@ -86,6 +88,7 @@ fail:
|
|||||||
event_del( c->c_read_event );
|
event_del( c->c_read_event );
|
||||||
event_free( c->c_read_event );
|
event_free( c->c_read_event );
|
||||||
}
|
}
|
||||||
|
c->c_struct_state = SLAP_C_UNINITIALIZED;
|
||||||
connection_destroy( c );
|
connection_destroy( c );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -99,5 +102,6 @@ client_destroy( Connection *c )
|
|||||||
event_del( c->c_write_event );
|
event_del( c->c_write_event );
|
||||||
event_free( c->c_write_event );
|
event_free( c->c_write_event );
|
||||||
|
|
||||||
|
c->c_struct_state = SLAP_C_UNINITIALIZED;
|
||||||
connection_destroy( c );
|
connection_destroy( c );
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,14 @@ void
|
|||||||
connection_destroy( Connection *c )
|
connection_destroy( Connection *c )
|
||||||
{
|
{
|
||||||
assert( 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_io_mutex );
|
||||||
ldap_pvt_thread_mutex_destroy( &c->c_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 = ch_calloc( 1, sizeof(Connection) );
|
||||||
|
|
||||||
|
c->c_fd = s;
|
||||||
c->c_sb = ber_sockbuf_alloc();
|
c->c_sb = ber_sockbuf_alloc();
|
||||||
ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
|
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
|
#endif
|
||||||
|
|
||||||
|
c->c_next_msgid = 1;
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_init( &c->c_mutex );
|
ldap_pvt_thread_mutex_init( &c->c_mutex );
|
||||||
ldap_pvt_thread_mutex_init( &c->c_io_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",
|
"connection connid=%lu allocated for socket fd=%d\n",
|
||||||
c->c_connid, s );
|
c->c_connid, s );
|
||||||
|
|
||||||
|
ldap_pvt_thread_mutex_lock( &c->c_mutex );
|
||||||
|
c->c_struct_state = SLAP_C_USED;
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
fail:
|
|
||||||
connection_destroy( c );
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
@ -265,7 +265,7 @@ enum sc_conn_state {
|
|||||||
struct Connection {
|
struct Connection {
|
||||||
enum sc_struct_state c_struct_state; /* structure management state */
|
enum sc_struct_state c_struct_state; /* structure management state */
|
||||||
enum sc_conn_state c_conn_state; /* connection 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 */
|
ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */
|
||||||
Sockbuf *c_sb; /* ber connection stuff */
|
Sockbuf *c_sb; /* ber connection stuff */
|
||||||
@ -275,7 +275,8 @@ struct Connection {
|
|||||||
struct berval c_peer_name; /* peer name (trans=addr:port) */
|
struct berval c_peer_name; /* peer name (trans=addr:port) */
|
||||||
time_t c_starttime; /* when the connection was opened */
|
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;
|
struct event *c_read_event, *c_write_event;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user