diff --git a/servers/lloadd/backend.c b/servers/lloadd/backend.c index 17d0ec51df..53fbd41459 100644 --- a/servers/lloadd/backend.c +++ b/servers/lloadd/backend.c @@ -87,7 +87,7 @@ backend_select( Operation *op ) ldap_pvt_thread_mutex_lock( &b->b_lock ); c = b->b_conns; ldap_pvt_thread_mutex_lock( &c->c_mutex ); - if ( c->c_struct_state != SLAP_C_UNINITIALIZED && !c->c_pendingber ) { + if ( c->c_state == SLAP_C_READY && !c->c_pendingber ) { ldap_pvt_thread_mutex_unlock( &b->b_lock ); return b->b_conns; } diff --git a/servers/lloadd/client.c b/servers/lloadd/client.c index c1d94fcbfa..c8c41cb79e 100644 --- a/servers/lloadd/client.c +++ b/servers/lloadd/client.c @@ -130,6 +130,8 @@ client_init( c = connection_init( s, peername, flags ); + c->c_state = SLAP_C_READY; + event = event_new( base, s, EV_READ|EV_PERSIST, client_read_cb, c ); if ( !event ) { Debug( LDAP_DEBUG_ANY, "Read event could not be allocated\n" ); @@ -159,7 +161,7 @@ fail: event_del( c->c_read_event ); event_free( c->c_read_event ); } - c->c_struct_state = SLAP_C_UNINITIALIZED; + c->c_state = SLAP_C_INVALID; connection_destroy( c ); return NULL; } @@ -173,6 +175,6 @@ client_destroy( Connection *c ) event_del( c->c_write_event ); event_free( c->c_write_event ); - c->c_struct_state = SLAP_C_UNINITIALIZED; + c->c_state = SLAP_C_INVALID; connection_destroy( c ); } diff --git a/servers/lloadd/config.c b/servers/lloadd/config.c index d464ffba52..9b6e82fd9a 100644 --- a/servers/lloadd/config.c +++ b/servers/lloadd/config.c @@ -154,7 +154,7 @@ static ConfigTable config_back_cf_table[] = { ARG_INT|ARG_MAGIC|CFG_CONCUR, &config_generic, }, - { "backend", "type", 2, 2, 0, + { "backend", "type", 2, 0, 0, ARG_MAGIC|CFG_DATABASE, &config_backend, }, diff --git a/servers/lloadd/connection.c b/servers/lloadd/connection.c index f86cce3f12..e270bdc0bc 100644 --- a/servers/lloadd/connection.c +++ b/servers/lloadd/connection.c @@ -58,7 +58,7 @@ connection_destroy( Connection *c ) "destroying connection %lu.\n", c->c_connid ); - assert( c->c_struct_state == SLAP_C_UNINITIALIZED ); + assert( c->c_state == SLAP_C_INVALID ); ber_sockbuf_free( c->c_sb ); if ( c->c_currentber ) { @@ -156,7 +156,7 @@ connection_init( ber_socket_t s, const char *peername, int flags ) c->c_connid, s ); ldap_pvt_thread_mutex_lock( &c->c_mutex ); - c->c_struct_state = SLAP_C_USED; + c->c_state = SLAP_C_ACTIVE; return c; } diff --git a/servers/lloadd/slap.h b/servers/lloadd/slap.h index 27cfc4b17a..5925f55edc 100644 --- a/servers/lloadd/slap.h +++ b/servers/lloadd/slap.h @@ -243,29 +243,19 @@ struct Backend { LDAP_STAILQ_ENTRY(Backend) b_next; }; -/* - * represents a connection from an ldap client - */ -/* structure state (protected by connections_mutex) */ -enum sc_struct_state { - SLAP_C_UNINITIALIZED = 0, /* MUST BE ZERO (0) */ - SLAP_C_UNUSED, - SLAP_C_USED, - SLAP_C_PENDING -}; - /* connection state (protected by c_mutex) */ -enum sc_conn_state { +enum sc_state { SLAP_C_INVALID = 0, /* MUST BE ZERO (0) */ - SLAP_C_INACTIVE, /* zero threads */ + SLAP_C_READY, /* ready */ SLAP_C_CLOSING, /* closing */ - SLAP_C_ACTIVE, /* one or more threads */ + SLAP_C_ACTIVE, /* exclusive operation (tls setup, ...) in progress */ SLAP_C_BINDING, /* binding */ - SLAP_C_CLIENT /* outbound client conn */ }; +/* + * represents a connection from an ldap client/to ldap server + */ struct Connection { - enum sc_struct_state c_struct_state; /* structure management state */ - enum sc_conn_state c_conn_state; /* connection state */ + enum sc_state c_state; /* connection state */ ber_socket_t c_fd; ldap_pvt_thread_mutex_t c_mutex; /* protect the connection */ diff --git a/servers/lloadd/upstream.c b/servers/lloadd/upstream.c index 4d87ee5fc5..bdc62acfab 100644 --- a/servers/lloadd/upstream.c +++ b/servers/lloadd/upstream.c @@ -194,6 +194,8 @@ upstream_init( ber_socket_t s, Backend *backend ) c->c_write_event = event; c->c_private = backend; + + c->c_state = SLAP_C_READY; ldap_pvt_thread_mutex_unlock( &c->c_mutex ); return c; @@ -215,7 +217,7 @@ upstream_destroy( Connection *c ) { Backend *b = c->c_private; - c->c_struct_state = SLAP_C_UNINITIALIZED; + c->c_state = SLAP_C_INVALID; ldap_pvt_thread_mutex_unlock( &c->c_mutex ); ldap_pvt_thread_mutex_lock( &b->b_lock );