Skip to content
Snippets Groups Projects
Commit fa81f43f authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Initial check of connection states. Have only implemented

SLAP_C_ACTIVE vs SLAP_C_INACTIVE.  Need to implement BINDING and CLOSING.
Added fields tracking pending (on bind) ops.  Could also be used to
implement per-connection thread limits.
parent 70555f85
No related branches found
No related tags found
No related merge requests found
...@@ -27,7 +27,7 @@ connection_operation( void *arg_v ) ...@@ -27,7 +27,7 @@ connection_operation( void *arg_v )
struct co_arg *arg = arg_v; struct co_arg *arg = arg_v;
ldap_pvt_thread_mutex_lock( &arg->co_conn->c_opsmutex ); ldap_pvt_thread_mutex_lock( &arg->co_conn->c_opsmutex );
arg->co_conn->c_opsinitiated++; arg->co_conn->c_ops_received++;
ldap_pvt_thread_mutex_unlock( &arg->co_conn->c_opsmutex ); ldap_pvt_thread_mutex_unlock( &arg->co_conn->c_opsmutex );
ldap_pvt_thread_mutex_lock( &ops_mutex ); ldap_pvt_thread_mutex_lock( &ops_mutex );
...@@ -87,7 +87,7 @@ connection_operation( void *arg_v ) ...@@ -87,7 +87,7 @@ connection_operation( void *arg_v )
} }
ldap_pvt_thread_mutex_lock( &arg->co_conn->c_opsmutex ); ldap_pvt_thread_mutex_lock( &arg->co_conn->c_opsmutex );
arg->co_conn->c_opscompleted++; arg->co_conn->c_ops_completed++;
slap_op_delete( &arg->co_conn->c_ops, arg->co_op ); slap_op_delete( &arg->co_conn->c_ops, arg->co_op );
arg->co_op = NULL; arg->co_op = NULL;
...@@ -191,7 +191,7 @@ connection_activity( ...@@ -191,7 +191,7 @@ connection_activity(
ldap_pvt_thread_mutex_lock( &conn->c_opsmutex ); ldap_pvt_thread_mutex_lock( &conn->c_opsmutex );
arg->co_op = slap_op_add( &conn->c_ops, ber, msgid, tag, tmpdn, arg->co_op = slap_op_add( &conn->c_ops, ber, msgid, tag, tmpdn,
conn->c_opsinitiated, conn->c_connid ); conn->c_ops_received, conn->c_connid );
ldap_pvt_thread_mutex_unlock( &conn->c_opsmutex ); ldap_pvt_thread_mutex_unlock( &conn->c_opsmutex );
if ( tmpdn != NULL ) { if ( tmpdn != NULL ) {
......
...@@ -83,8 +83,6 @@ slapd_daemon( ...@@ -83,8 +83,6 @@ slapd_daemon(
c[i].c_domain = NULL; c[i].c_domain = NULL;
c[i].c_ops = NULL; c[i].c_ops = NULL;
lber_pvt_sb_init( &c[i].c_sb ); lber_pvt_sb_init( &c[i].c_sb );
c[i].c_writewaiter = 0;
c[i].c_connid = 0;
ldap_pvt_thread_mutex_init( &c[i].c_dnmutex ); ldap_pvt_thread_mutex_init( &c[i].c_dnmutex );
ldap_pvt_thread_mutex_init( &c[i].c_opsmutex ); ldap_pvt_thread_mutex_init( &c[i].c_opsmutex );
ldap_pvt_thread_mutex_init( &c[i].c_pdumutex ); ldap_pvt_thread_mutex_init( &c[i].c_pdumutex );
...@@ -168,7 +166,12 @@ slapd_daemon( ...@@ -168,7 +166,12 @@ slapd_daemon(
ldap_pvt_thread_mutex_lock( &new_conn_mutex ); ldap_pvt_thread_mutex_lock( &new_conn_mutex );
for ( i = 0; i < dtblsize; i++ ) { for ( i = 0; i < dtblsize; i++ ) {
if ( lber_pvt_sb_in_use( &c[i].c_sb )) { if ( (c[i].c_state != SLAP_C_INACTIVE)
&& (c[i].c_state != SLAP_C_CLOSING) )
{
#ifdef LDAP_DEBUG
assert(lber_pvt_sb_in_use( &c[i].c_sb ));
#endif
FD_SET( lber_pvt_sb_get_desc(&c[i].c_sb), FD_SET( lber_pvt_sb_get_desc(&c[i].c_sb),
&readfds ); &readfds );
if (lber_pvt_sb_data_ready(&c[i].c_sb)) if (lber_pvt_sb_data_ready(&c[i].c_sb))
...@@ -181,6 +184,7 @@ slapd_daemon( ...@@ -181,6 +184,7 @@ slapd_daemon(
c[i].c_writewaiter ? "w" : "", 0 ); c[i].c_writewaiter ? "w" : "", 0 );
} }
} }
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 ); Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
...@@ -240,14 +244,6 @@ slapd_daemon( ...@@ -240,14 +244,6 @@ slapd_daemon(
continue; continue;
} }
lber_pvt_sb_set_desc( &c[ns].c_sb, ns );
lber_pvt_sb_set_io( &c[ns].c_sb, &lber_pvt_sb_io_tcp, NULL );
if (lber_pvt_sb_set_nonblock( &c[ns].c_sb, 1)<0) {
Debug( LDAP_DEBUG_ANY,
"FIONBIO ioctl on %d failed\n", ns, 0, 0 );
}
Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns, Debug( LDAP_DEBUG_CONNS, "new connection on %d\n", ns,
0, 0 ); 0, 0 );
...@@ -297,8 +293,6 @@ slapd_daemon( ...@@ -297,8 +293,6 @@ slapd_daemon(
client_addr == NULL ? "unknown" : client_addr, client_addr == NULL ? "unknown" : client_addr,
0, 0 ); 0, 0 );
lber_pvt_sb_close( &c[ns].c_sb );
lber_pvt_sb_destroy( &c[ns].c_sb );
ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
continue; continue;
} }
...@@ -338,9 +332,22 @@ slapd_daemon( ...@@ -338,9 +332,22 @@ slapd_daemon(
c[ns].c_cdn = NULL; c[ns].c_cdn = NULL;
} }
ldap_pvt_thread_mutex_unlock( &c[ns].c_dnmutex ); ldap_pvt_thread_mutex_unlock( &c[ns].c_dnmutex );
c[ns].c_starttime = currenttime; c[ns].c_starttime = currenttime;
c[ns].c_opsinitiated = 0; c[ns].c_ops_received = 0;
c[ns].c_opscompleted = 0; c[ns].c_ops_executing = 0;
c[ns].c_ops_pending = 0;
c[ns].c_ops_completed = 0;
lber_pvt_sb_set_desc( &c[ns].c_sb, ns );
lber_pvt_sb_set_io( &c[ns].c_sb, &lber_pvt_sb_io_tcp, NULL );
if (lber_pvt_sb_set_nonblock( &c[ns].c_sb, 1)<0) {
Debug( LDAP_DEBUG_ANY,
"FIONBIO ioctl on %d failed\n", ns, 0, 0 );
}
c[ns].c_state = SLAP_C_ACTIVE;
} }
ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
......
...@@ -282,6 +282,8 @@ main( int argc, char **argv ) ...@@ -282,6 +282,8 @@ main( int argc, char **argv )
0, 0, 0 ); 0, 0, 0 );
} }
c.c_state = SLAP_C_ACTIVE;
ber_init_w_nullc( &ber, 0 ); ber_init_w_nullc( &ber, 0 );
while ( (tag = ber_get_next( &c.c_sb, &len, &ber )) while ( (tag = ber_get_next( &c.c_sb, &len, &ber ))
......
...@@ -89,11 +89,14 @@ monitor_info( Connection *conn, Operation *op ) ...@@ -89,11 +89,14 @@ monitor_info( Connection *conn, Operation *op )
ldap_pvt_thread_mutex_unlock( &currenttime_mutex ); ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
ldap_pvt_thread_mutex_lock( &c[i].c_dnmutex ); ldap_pvt_thread_mutex_lock( &c[i].c_dnmutex );
sprintf( buf, "%d : %s : %d : %d : %s : %s%s", i, sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i,
buf2, c[i].c_opsinitiated, c[i].c_opscompleted, buf2, c[i].c_ops_received, c[i].c_ops_completed,
c[i].c_cdn ? c[i].c_cdn : "NULLDN", c[i].c_cdn ? c[i].c_cdn : "NULLDN",
c[i].c_gettingber ? "r" : "", c[i].c_gettingber ? "r" : "",
c[i].c_writewaiter ? "w" : "" ); c[i].c_writewaiter ? "w" : "",
c[i].c_ops_executing ? "x" : "",
c[i].c_ops_pending ? "p" : ""
);
ldap_pvt_thread_mutex_unlock( &c[i].c_dnmutex ); ldap_pvt_thread_mutex_unlock( &c[i].c_dnmutex );
val.bv_val = buf; val.bv_val = buf;
val.bv_len = strlen( buf ); val.bv_len = strlen( buf );
......
...@@ -455,6 +455,7 @@ close_connection( Connection *conn, int opconnid, int opid ) ...@@ -455,6 +455,7 @@ close_connection( Connection *conn, int opconnid, int opid )
lber_pvt_sb_destroy( &conn->c_sb ); lber_pvt_sb_destroy( &conn->c_sb );
conn->c_version = 0; conn->c_version = 0;
conn->c_protocol = 0; conn->c_protocol = 0;
conn->c_state = SLAP_C_INACTIVE;
} }
ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); ldap_pvt_thread_mutex_unlock( &new_conn_mutex );
} }
...@@ -411,7 +411,13 @@ typedef struct slap_op { ...@@ -411,7 +411,13 @@ typedef struct slap_op {
* represents a connection from an ldap client * represents a connection from an ldap client
*/ */
#define SLAP_C_INACTIVE 0x0
#define SLAP_C_ACTIVE 0x1
#define SLAP_C_BINDING 0x2
#define SLAP_C_CLOSING 0x3
typedef struct slap_conn { typedef struct slap_conn {
int c_state; /* connection state */
Sockbuf c_sb; /* ber connection stuff */ Sockbuf c_sb; /* ber connection stuff */
char *c_cdn; /* DN provided by the client */ char *c_cdn; /* DN provided by the client */
char *c_dn; /* DN bound to this conn */ char *c_dn; /* DN bound to this conn */
...@@ -423,7 +429,8 @@ typedef struct slap_conn { ...@@ -423,7 +429,8 @@ typedef struct slap_conn {
#endif #endif
char *c_addr; /* address of client on this conn */ char *c_addr; /* address of client on this conn */
char *c_domain; /* domain of client on this conn */ char *c_domain; /* domain of client on this conn */
Operation *c_ops; /* list of pending operations */ Operation *c_ops; /* list of operations being processed */
Operation *c_pending_ops; /* list of pending operations */
ldap_pvt_thread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */ ldap_pvt_thread_mutex_t c_opsmutex; /* mutex for c_ops list & stats */
ldap_pvt_thread_mutex_t c_pdumutex; /* only one pdu written at a time */ ldap_pvt_thread_mutex_t c_pdumutex; /* only one pdu written at a time */
ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/ ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/
...@@ -432,9 +439,13 @@ typedef struct slap_conn { ...@@ -432,9 +439,13 @@ typedef struct slap_conn {
int c_writewaiter; /* signals write-ready sd waiter */ int c_writewaiter; /* signals write-ready sd waiter */
int c_pduwaiters; /* signals threads waiting 4 pdu */ int c_pduwaiters; /* signals threads waiting 4 pdu */
time_t c_starttime; /* when the connection was opened */ time_t c_starttime; /* when the connection was opened */
int c_connid; /* id of this connection for stats*/
int c_opsinitiated; /* # ops initiated/next op id */ long c_connid; /* id of this connection for stats*/
int c_opscompleted; /* # ops completed */
long c_ops_received; /* num of ops received (next op_id) */
long c_ops_executing; /* num of ops currently executing */
long c_ops_pending; /* num of ops pending execution */
long c_ops_completed; /* num of ops completed */
} Connection; } Connection;
#if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG) #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment