X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fconnection.c;h=6afc81bbc6d3bfeb961f5b5960105ac8fba8c19d;hb=2bfe79fe884565801600e309d1fcbefa41fb0f4b;hp=f067714cd8c88df9bbec81537856ada270d3f853;hpb=f26bef66c60f97197ea28a1101c93550e9cb72cf;p=openldap diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index f067714cd8..6afc81bbc6 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -731,22 +731,17 @@ connection_destroy( Connection *c ) } ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd ); - slapd_sd_lock(); - - ber_sockbuf_free( sb ); /* c must be fully reset by this point; when we call slapd_remove * it may get immediately reused by a new connection. */ if ( sd != AC_SOCKET_INVALID ) { - slapd_remove( sd, 1, 0, 1 ); + slapd_remove( sd, sb, 1, 0, 0 ); Statslog( LDAP_DEBUG_STATS, (close_reason ? "conn=%lu fd=%ld closed (%s)\n" : "conn=%lu fd=%ld closed\n"), connid, (long) sd, close_reason, 0, 0 ); - } else { - slapd_sd_unlock(); } } @@ -834,9 +829,15 @@ void connection_closing( Connection *c, const char *why ) connection_abandon( c ); /* wake write blocked operations */ - slapd_clr_write( sd, 1 ); if ( c->c_writewaiter ) { ldap_pvt_thread_cond_signal( &c->c_write_cv ); + ldap_pvt_thread_mutex_unlock( &c->c_mutex ); + slapd_clr_write( sd, 1 ); + ldap_pvt_thread_mutex_lock( &c->c_write_mutex ); + ldap_pvt_thread_mutex_lock( &c->c_mutex ); + ldap_pvt_thread_mutex_unlock( &c->c_write_mutex ); + } else { + slapd_clr_write( sd, 1 ); } } else if( why == NULL && c->c_close_reason == conn_lost_str ) { @@ -845,19 +846,26 @@ void connection_closing( Connection *c, const char *why ) } } -static void connection_close( Connection *c ) +static void +connection_close( Connection *c ) { - ber_socket_t sd; + ber_socket_t sd = AC_SOCKET_INVALID; assert( connections != NULL ); assert( c != NULL ); assert( c->c_struct_state == SLAP_C_USED ); assert( c->c_conn_state == SLAP_C_CLOSING ); - /* note: c_mutex should be locked by caller */ + /* NOTE: c_mutex should be locked by caller */ - ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd ); - if( !LDAP_STAILQ_EMPTY(&c->c_ops) ) { + /* NOTE: don't get the file descriptor if not needed */ + if ( LogTest( LDAP_DEBUG_TRACE ) ) { + ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_GET_FD, &sd ); + } + + if ( !LDAP_STAILQ_EMPTY(&c->c_ops) || + !LDAP_STAILQ_EMPTY(&c->c_pending_ops) ) + { Debug( LDAP_DEBUG_TRACE, "connection_close: deferring conn=%lu sd=%d\n", c->c_connid, sd, 0 ); @@ -866,6 +874,7 @@ static void connection_close( Connection *c ) Debug( LDAP_DEBUG_TRACE, "connection_close: conn=%lu sd=%d\n", c->c_connid, sd, 0 ); + connection_destroy( c ); } @@ -911,9 +920,14 @@ Connection* connection_next( Connection *c, ber_socket_t *index ) ldap_pvt_thread_mutex_lock( &connections_mutex ); for(; *index < dtblsize; (*index)++) { + int c_struct; if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) { assert( connections[*index].c_conn_state == SLAP_C_INVALID ); +#ifdef HAVE_WINSOCK break; +#else + continue; +#endif } if( connections[*index].c_struct_state == SLAP_C_USED ) { @@ -933,7 +947,10 @@ Connection* connection_next( Connection *c, ber_socket_t *index ) break; } - assert( connections[*index].c_struct_state == SLAP_C_UNUSED ); + c_struct = connections[*index].c_struct_state; + if ( c_struct == SLAP_C_PENDING ) + continue; + assert( c_struct == SLAP_C_UNUSED ); assert( connections[*index].c_conn_state == SLAP_C_INVALID ); } @@ -1003,7 +1020,7 @@ connection_operation( void *ctx, void *arg_v ) Operation *op = arg_v; SlapReply rs = {REP_RESULT}; ber_tag_t tag = op->o_tag; - int opidx = -1; + slap_op_t opidx = SLAP_OP_LAST; Connection *conn = op->o_conn; void *memctx = NULL; void *memctx_null = NULL; @@ -1086,53 +1103,8 @@ connection_operation( void *ctx, void *arg_v ) } } - switch ( tag ) { - case LDAP_REQ_BIND: - opidx = SLAP_OP_BIND; - break; - - case LDAP_REQ_UNBIND: - opidx = SLAP_OP_UNBIND; - break; - - case LDAP_REQ_ADD: - opidx = SLAP_OP_ADD; - break; - - case LDAP_REQ_DELETE: - opidx = SLAP_OP_DELETE; - break; - - case LDAP_REQ_MODRDN: - opidx = SLAP_OP_MODRDN; - break; - - case LDAP_REQ_MODIFY: - opidx = SLAP_OP_MODIFY; - break; - - case LDAP_REQ_COMPARE: - opidx = SLAP_OP_COMPARE; - break; - - case LDAP_REQ_SEARCH: - opidx = SLAP_OP_SEARCH; - break; - - case LDAP_REQ_ABANDON: - opidx = SLAP_OP_ABANDON; - break; - - case LDAP_REQ_EXTENDED: - opidx = SLAP_OP_EXTENDED; - break; - - default: - /* not reachable */ - assert( 0 ); - } - - assert( opidx > -1 ); + opidx = slap_req2op( tag ); + assert( opidx != SLAP_OP_LAST ); INCR_OP_INITIATED( opidx ); rc = (*(opfun[opidx]))( op, &rs ); @@ -1140,7 +1112,7 @@ operations_error: if ( rc == SLAPD_DISCONNECT ) { tag = LBER_ERROR; - } else if ( opidx > -1 ) { + } else if ( opidx != SLAP_OP_LAST ) { /* increment completed operations count * only if operation was initiated * and rc != SLAPD_DISCONNECT */ @@ -1154,6 +1126,7 @@ operations_error: op->o_cancel = LDAP_TOO_LATE; } } + while ( op->o_cancel != SLAP_CANCEL_NONE && op->o_cancel != SLAP_CANCEL_DONE ) { @@ -1218,6 +1191,7 @@ void connection_client_stop( ber_socket_t s ) { Connection *c; + Sockbuf *sb; /* get (locked) connection */ c = connection_get( s ); @@ -1228,14 +1202,13 @@ void connection_client_stop( c->c_conn_state = SLAP_C_INVALID; c->c_struct_state = SLAP_C_UNUSED; c->c_close_reason = "?"; /* should never be needed */ - slapd_sd_lock(); - ber_sockbuf_free( c->c_sb ); - slapd_remove( s, 0, 1, 1 ); + sb = c->c_sb; c->c_sb = ber_sockbuf_alloc( ); { ber_len_t max = sockbuf_max_incoming; ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_MAX_INCOMING, &max ); } + slapd_remove( s, sb, 0, 1, 0 ); connection_return( c ); }