rework operations in a table-driven manner; better exception handling

This commit is contained in:
Pierangelo Masarati 2004-12-29 12:31:06 +00:00
parent 564d1a6aff
commit 4b8e57e11f

View File

@ -888,9 +888,31 @@ void connection_done( Connection *c )
} while (0) } while (0)
#else /* !SLAPD_MONITOR */ #else /* !SLAPD_MONITOR */
#define INCR_OP_INITIATED(index) #define INCR_OP_INITIATED(index)
#define INCR_OP_COMPLETED(index) #define INCR_OP_COMPLETED(index) \
do { \
ldap_pvt_thread_mutex_lock( &slap_counters.sc_ops_mutex ); \
ldap_pvt_mp_add_ulong(slap_counters.sc_ops_completed, 1); \
ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex ); \
} while (0)
#endif /* !SLAPD_MONITOR */ #endif /* !SLAPD_MONITOR */
/*
* NOTE: keep in sync with enum in slapd.h
*/
static int (*opfun[])( Operation *op, SlapReply *rs ) = {
do_bind,
do_unbind,
do_add,
do_delete,
do_modrdn,
do_modify,
do_compare,
do_search,
do_abandon,
do_extended,
NULL
};
static void * static void *
connection_operation( void *ctx, void *arg_v ) connection_operation( void *ctx, void *arg_v )
{ {
@ -898,9 +920,7 @@ connection_operation( void *ctx, void *arg_v )
Operation *op = arg_v; Operation *op = arg_v;
SlapReply rs = {REP_RESULT}; SlapReply rs = {REP_RESULT};
ber_tag_t tag = op->o_tag; ber_tag_t tag = op->o_tag;
#ifdef SLAPD_MONITOR int opidx = -1;
ber_tag_t oldtag = tag;
#endif /* SLAPD_MONITOR */
Connection *conn = op->o_conn; Connection *conn = op->o_conn;
void *memctx = NULL; void *memctx = NULL;
void *memctx_null = NULL; void *memctx_null = NULL;
@ -918,7 +938,7 @@ connection_operation( void *ctx, void *arg_v )
case LDAP_REQ_UNBIND: case LDAP_REQ_UNBIND:
case LDAP_REQ_ADD: case LDAP_REQ_ADD:
case LDAP_REQ_DELETE: case LDAP_REQ_DELETE:
case LDAP_REQ_MODRDN: case LDAP_REQ_MODDN:
case LDAP_REQ_MODIFY: case LDAP_REQ_MODIFY:
case LDAP_REQ_COMPARE: case LDAP_REQ_COMPARE:
case LDAP_REQ_SEARCH: case LDAP_REQ_SEARCH:
@ -969,53 +989,43 @@ connection_operation( void *ctx, void *arg_v )
switch ( tag ) { switch ( tag ) {
case LDAP_REQ_BIND: case LDAP_REQ_BIND:
INCR_OP_INITIATED(SLAP_OP_BIND); opidx = SLAP_OP_BIND;
rc = do_bind( op, &rs );
break; break;
case LDAP_REQ_UNBIND: case LDAP_REQ_UNBIND:
INCR_OP_INITIATED(SLAP_OP_UNBIND); opidx = SLAP_OP_UNBIND;
rc = do_unbind( op, &rs );
break; break;
case LDAP_REQ_ADD: case LDAP_REQ_ADD:
INCR_OP_INITIATED(SLAP_OP_ADD); opidx = SLAP_OP_ADD;
rc = do_add( op, &rs );
break; break;
case LDAP_REQ_DELETE: case LDAP_REQ_DELETE:
INCR_OP_INITIATED(SLAP_OP_DELETE); opidx = SLAP_OP_DELETE;
rc = do_delete( op, &rs );
break; break;
case LDAP_REQ_MODRDN: case LDAP_REQ_MODRDN:
INCR_OP_INITIATED(SLAP_OP_MODRDN); opidx = SLAP_OP_MODRDN;
rc = do_modrdn( op, &rs );
break; break;
case LDAP_REQ_MODIFY: case LDAP_REQ_MODIFY:
INCR_OP_INITIATED(SLAP_OP_MODIFY); opidx = SLAP_OP_MODIFY;
rc = do_modify( op, &rs );
break; break;
case LDAP_REQ_COMPARE: case LDAP_REQ_COMPARE:
INCR_OP_INITIATED(SLAP_OP_COMPARE); opidx = SLAP_OP_COMPARE;
rc = do_compare( op, &rs );
break; break;
case LDAP_REQ_SEARCH: case LDAP_REQ_SEARCH:
INCR_OP_INITIATED(SLAP_OP_SEARCH); opidx = SLAP_OP_SEARCH;
rc = do_search( op, &rs );
break; break;
case LDAP_REQ_ABANDON: case LDAP_REQ_ABANDON:
INCR_OP_INITIATED(SLAP_OP_ABANDON); opidx = SLAP_OP_ABANDON;
rc = do_abandon( op, &rs );
break; break;
case LDAP_REQ_EXTENDED: case LDAP_REQ_EXTENDED:
INCR_OP_INITIATED(SLAP_OP_EXTENDED); opidx = SLAP_OP_EXTENDED;
rc = do_extended( op, &rs );
break; break;
default: default:
@ -1023,52 +1033,20 @@ connection_operation( void *ctx, void *arg_v )
assert( 0 ); assert( 0 );
} }
assert( opidx > -1 );
INCR_OP_INITIATED( opidx );
rc = (*(opfun[opidx]))( op, &rs );
operations_error: operations_error:
if( rc == SLAPD_DISCONNECT ) tag = LBER_ERROR; if ( rc == SLAPD_DISCONNECT ) {
tag = LBER_ERROR;
#ifdef SLAPD_MONITOR } else if ( opidx > -1 ) {
switch (oldtag) { /* increment completed operations count
case LDAP_REQ_BIND: * only if operation was initiated
INCR_OP_COMPLETED(SLAP_OP_BIND); * and rc != SLAPD_DISCONNECT */
break; INCR_OP_COMPLETED( opidx );
case LDAP_REQ_UNBIND:
INCR_OP_COMPLETED(SLAP_OP_UNBIND);
break;
case LDAP_REQ_ADD:
INCR_OP_COMPLETED(SLAP_OP_ADD);
break;
case LDAP_REQ_DELETE:
INCR_OP_COMPLETED(SLAP_OP_DELETE);
break;
case LDAP_REQ_MODDN:
INCR_OP_COMPLETED(SLAP_OP_MODRDN);
break;
case LDAP_REQ_MODIFY:
INCR_OP_COMPLETED(SLAP_OP_MODIFY);
break;
case LDAP_REQ_COMPARE:
INCR_OP_COMPLETED(SLAP_OP_COMPARE);
break;
case LDAP_REQ_SEARCH:
INCR_OP_COMPLETED(SLAP_OP_SEARCH);
break;
case LDAP_REQ_ABANDON:
INCR_OP_COMPLETED(SLAP_OP_ABANDON);
break;
case LDAP_REQ_EXTENDED:
INCR_OP_COMPLETED(SLAP_OP_EXTENDED);
break;
default:
/* this is reachable */
#if 0
/* not reachable */
assert( 0 )
#endif
;
} }
#endif /* SLAPD_MONITOR */
ldap_pvt_thread_mutex_unlock( &slap_counters.sc_ops_mutex );
if ( op->o_cancel == SLAP_CANCEL_REQ ) { if ( op->o_cancel == SLAP_CANCEL_REQ ) {
op->o_cancel = LDAP_TOO_LATE; op->o_cancel = LDAP_TOO_LATE;