/* * Timeout idle connections. */ int connections_timeout_idle(time_t now) { int i = 0; int connindex; Connection* c; for( c = connection_first( &connindex ); c != NULL; c = connection_next( c, &connindex ) ) { /* Don't timeout a slow-running request or a persistent * outbound connection */ if( c->c_n_ops_executing || c->c_conn_state == SLAP_C_CLIENT ) { continue; } if( difftime( c->c_activitytime+global_idletimeout, now) < 0 ) { /* close it */ connection_closing( c, "idletimeout" ); connection_close( c ); i++; } } connection_done( c ); return i; }
static int monitor_subsys_conn_update( Operation *op, SlapReply *rs, Entry *e ) { monitor_info_t *mi = ( monitor_info_t * )op->o_bd->be_private; long n = -1; static struct berval total_bv = BER_BVC( "cn=total" ), current_bv = BER_BVC( "cn=current" ); struct berval rdn; assert( mi != NULL ); assert( e != NULL ); dnRdn( &e->e_nname, &rdn ); if ( dn_match( &rdn, &total_bv ) ) { n = connections_nextid(); } else if ( dn_match( &rdn, ¤t_bv ) ) { Connection *c; ber_socket_t connindex; for ( n = 0, c = connection_first( &connindex ); c != NULL; n++, c = connection_next( c, &connindex ) ) { /* No Op */ ; } connection_done( c ); } if ( n != -1 ) { Attribute *a; char buf[LDAP_PVT_INTTYPE_CHARS(long)]; ber_len_t len; a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter ); if ( a == NULL ) { return( -1 ); } snprintf( buf, sizeof( buf ), "%ld", n ); len = strlen( buf ); if ( len > a->a_vals[ 0 ].bv_len ) { a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 ); } a->a_vals[ 0 ].bv_len = len; memcpy( a->a_vals[ 0 ].bv_val, buf, len + 1 ); /* FIXME: touch modifyTimestamp? */ }
static int monitor_subsys_readw_update_internal( struct monitorinfo *mi, Entry *e, int rw ) { Connection *c; int connindex; int nconns, nwritewaiters, nreadwaiters; Attribute *a; struct berval bv[2], *b = NULL; char buf[1024]; char *str = NULL; int num = 0; assert( mi != NULL ); assert( e != NULL ); bv[1].bv_val = NULL; nconns = nwritewaiters = nreadwaiters = 0; for ( c = connection_first( &connindex ); c != NULL; c = connection_next( c, &connindex ), nconns++ ) { if ( c->c_writewaiter ) { nwritewaiters++; } if ( c->c_currentber != NULL ) { nreadwaiters++; } } connection_done(c); switch ( rw ) { case 0: str = "read waiters"; num = nreadwaiters; break; case 1: str = "write waiters"; num = nwritewaiters; break; } snprintf( buf, sizeof( buf ), "%s=%d", str, num ); if ( ( a = attr_find( e->e_attrs, monitor_ad_desc ) ) != NULL ) { for ( b = a->a_vals; b[0].bv_val != NULL; b++ ) { if ( strncmp( b[0].bv_val, str, strlen( str ) ) == 0 ) { free( b[0].bv_val ); ber_str2bv( buf, 0, 1, b ); break; } } } if ( b == NULL || b[0].bv_val == NULL ) { bv[0].bv_val = buf; bv[0].bv_len = strlen( buf ); attr_merge( e, monitor_ad_desc, bv ); } return( 0 ); }
static int monitor_subsys_rww_update( Operation *op, SlapReply *rs, Entry *e ) { monitor_info_t *mi = (monitor_info_t *)op->o_bd->be_private; Connection *c; int connindex; long nconns, nwritewaiters, nreadwaiters; int i; struct berval nrdn; Attribute *a; char buf[LDAP_PVT_INTTYPE_CHARS(long)]; long num = 0; ber_len_t len; assert( mi != NULL ); assert( e != NULL ); dnRdn( &e->e_nname, &nrdn ); for ( i = 0; !BER_BVISNULL( &monitor_rww[ i ].nrdn ); i++ ) { if ( dn_match( &nrdn, &monitor_rww[ i ].nrdn ) ) { break; } } if ( i == MONITOR_RWW_LAST ) { return SLAP_CB_CONTINUE; } nconns = nwritewaiters = nreadwaiters = 0; for ( c = connection_first( &connindex ); c != NULL; c = connection_next( c, &connindex ), nconns++ ) { if ( c->c_writewaiter ) { nwritewaiters++; } /* FIXME: ?!? */ if ( c->c_currentber != NULL ) { nreadwaiters++; } } connection_done(c); switch ( i ) { case MONITOR_RWW_READ: num = nreadwaiters; break; case MONITOR_RWW_WRITE: num = nwritewaiters; break; default: assert( 0 ); } snprintf( buf, sizeof( buf ), "%ld", num ); a = attr_find( e->e_attrs, mi->mi_ad_monitorCounter ); assert( a != NULL ); len = strlen( buf ); if ( len > a->a_vals[ 0 ].bv_len ) { a->a_vals[ 0 ].bv_val = ber_memrealloc( a->a_vals[ 0 ].bv_val, len + 1 ); if ( BER_BVISNULL( &a->a_vals[ 0 ] ) ) { BER_BVZERO( &a->a_vals[ 0 ] ); return SLAP_CB_CONTINUE; } } AC_MEMCPY( a->a_vals[ 0 ].bv_val, buf, len + 1 ); a->a_vals[ 0 ].bv_len = len; /* FIXME: touch modifyTimestamp? */ return SLAP_CB_CONTINUE; }