From fa81f43f04fd8956fff6ceeba3ec9e8fde62afe4 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 16 Mar 1999 02:59:59 +0000 Subject: [PATCH] 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. --- servers/slapd/connection.c | 6 +++--- servers/slapd/daemon.c | 37 ++++++++++++++++++++++--------------- servers/slapd/main.c | 2 ++ servers/slapd/monitor.c | 9 ++++++--- servers/slapd/result.c | 1 + servers/slapd/slap.h | 19 +++++++++++++++---- 6 files changed, 49 insertions(+), 25 deletions(-) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 1d772edcf2..7246a17b2f 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -27,7 +27,7 @@ connection_operation( void *arg_v ) struct co_arg *arg = arg_v; 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_lock( &ops_mutex ); @@ -87,7 +87,7 @@ connection_operation( void *arg_v ) } 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 ); arg->co_op = NULL; @@ -191,7 +191,7 @@ connection_activity( ldap_pvt_thread_mutex_lock( &conn->c_opsmutex ); 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 ); if ( tmpdn != NULL ) { diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index c58ed25bca..0b0cfe6b4d 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -83,8 +83,6 @@ slapd_daemon( c[i].c_domain = NULL; c[i].c_ops = NULL; 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_opsmutex ); ldap_pvt_thread_mutex_init( &c[i].c_pdumutex ); @@ -168,7 +166,12 @@ slapd_daemon( ldap_pvt_thread_mutex_lock( &new_conn_mutex ); 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), &readfds ); if (lber_pvt_sb_data_ready(&c[i].c_sb)) @@ -181,6 +184,7 @@ slapd_daemon( c[i].c_writewaiter ? "w" : "", 0 ); } } + Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 ); ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); @@ -240,14 +244,6 @@ slapd_daemon( 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, 0, 0 ); @@ -297,8 +293,6 @@ slapd_daemon( client_addr == NULL ? "unknown" : client_addr, 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 ); continue; } @@ -338,9 +332,22 @@ slapd_daemon( c[ns].c_cdn = NULL; } ldap_pvt_thread_mutex_unlock( &c[ns].c_dnmutex ); + c[ns].c_starttime = currenttime; - c[ns].c_opsinitiated = 0; - c[ns].c_opscompleted = 0; + c[ns].c_ops_received = 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 ); diff --git a/servers/slapd/main.c b/servers/slapd/main.c index 0d13c4be68..10e14d7fb5 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -282,6 +282,8 @@ main( int argc, char **argv ) 0, 0, 0 ); } + c.c_state = SLAP_C_ACTIVE; + ber_init_w_nullc( &ber, 0 ); while ( (tag = ber_get_next( &c.c_sb, &len, &ber )) diff --git a/servers/slapd/monitor.c b/servers/slapd/monitor.c index f065df6975..5554d81c3d 100644 --- a/servers/slapd/monitor.c +++ b/servers/slapd/monitor.c @@ -89,11 +89,14 @@ monitor_info( Connection *conn, Operation *op ) ldap_pvt_thread_mutex_unlock( ¤ttime_mutex ); ldap_pvt_thread_mutex_lock( &c[i].c_dnmutex ); - sprintf( buf, "%d : %s : %d : %d : %s : %s%s", i, - buf2, c[i].c_opsinitiated, c[i].c_opscompleted, + sprintf( buf, "%d : %s : %d : %d : %s : %s%s%s%s", i, + buf2, c[i].c_ops_received, c[i].c_ops_completed, c[i].c_cdn ? c[i].c_cdn : "NULLDN", 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 ); val.bv_val = buf; val.bv_len = strlen( buf ); diff --git a/servers/slapd/result.c b/servers/slapd/result.c index e23b518b04..6d30c29b6d 100644 --- a/servers/slapd/result.c +++ b/servers/slapd/result.c @@ -455,6 +455,7 @@ close_connection( Connection *conn, int opconnid, int opid ) lber_pvt_sb_destroy( &conn->c_sb ); conn->c_version = 0; conn->c_protocol = 0; + conn->c_state = SLAP_C_INACTIVE; } ldap_pvt_thread_mutex_unlock( &new_conn_mutex ); } diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index b1f6739dc4..3457eddc80 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -411,7 +411,13 @@ typedef struct slap_op { * 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 { + int c_state; /* connection state */ Sockbuf c_sb; /* ber connection stuff */ char *c_cdn; /* DN provided by the client */ char *c_dn; /* DN bound to this conn */ @@ -423,7 +429,8 @@ typedef struct slap_conn { #endif char *c_addr; /* address 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_pdumutex; /* only one pdu written at a time */ ldap_pvt_thread_cond_t c_wcv; /* used to wait for sd write-ready*/ @@ -432,9 +439,13 @@ typedef struct slap_conn { int c_writewaiter; /* signals write-ready sd waiter */ int c_pduwaiters; /* signals threads waiting 4 pdu */ 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 */ - int c_opscompleted; /* # ops completed */ + + long c_connid; /* id of this connection for stats*/ + + 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; #if defined(LDAP_SYSLOG) && defined(LDAP_DEBUG) -- 2.39.5