/* protected by connections_mutex */
static ldap_pvt_thread_mutex_t connections_mutex;
static Connection *connections = NULL;
-static int conn_index = -1;
static long conn_nextid = 0;
/* structure state (protected by connections_mutex) */
-#define SLAP_C_UNINITIALIZED 0x0 /* MUST BE ZERO (0) */
-#define SLAP_C_UNUSED 0x1
-#define SLAP_C_USED 0x2
+#define SLAP_C_UNINITIALIZED 0x00 /* MUST BE ZERO (0) */
+#define SLAP_C_UNUSED 0x01
+#define SLAP_C_USED 0x02
/* connection state (protected by c_mutex ) */
-#define SLAP_C_INVALID 0x0 /* MUST BE ZERO (0) */
-#define SLAP_C_INACTIVE 0x1 /* zero threads */
-#define SLAP_C_ACTIVE 0x2 /* one or more threads */
-#define SLAP_C_BINDING 0x3 /* binding */
-#define SLAP_C_CLOSING 0x4 /* closing */
+#define SLAP_C_INVALID 0x00 /* MUST BE ZERO (0) */
+#define SLAP_C_INACTIVE 0x01 /* zero threads */
+#define SLAP_C_ACTIVE 0x02 /* one or more threads */
+#define SLAP_C_BINDING 0x03 /* binding */
+#define SLAP_C_CLOSING 0x04 /* closing */
void slapd_remove(int s);
static Connection* connection_get( int s );
*/
int connections_init(void)
{
- int i;
-
assert( connections == NULL );
if( connections != NULL) {
return -1;
}
+ assert( connections[0].c_struct_state == SLAP_C_UNINITIALIZED );
+ assert( connections[dtblsize-1].c_struct_state == SLAP_C_UNINITIALIZED );
+
/*
* per entry initialization of the Connection array initialization
* will be done by connection_init()
static Connection* connection_get( int s )
{
+ /* connections_mutex should be locked by caller */
+
Connection *c = NULL;
assert( connections != NULL );
int connection_state_closing( Connection *c )
{
- /* connection must be locked by caller */
+ /* c_mutex must be locked by caller */
+
int state;
assert( c != NULL );
assert( c->c_struct_state == SLAP_C_USED );
assert( c->c_struct_state == SLAP_C_USED );
assert( c->c_conn_state != SLAP_C_INVALID );
+ /* c_mutex must be locked by caller */
+
if( c->c_conn_state != SLAP_C_CLOSING ) {
Operation *o;
assert( c->c_struct_state == SLAP_C_USED );
assert( c->c_conn_state == SLAP_C_CLOSING );
- /* note: connections_mutex should be locked by caller */
+ /* note: connections_mutex and c_mutex should be locked by caller */
if( c->c_ops != NULL ) {
Debug( LDAP_DEBUG_TRACE,
return id;
}
-Connection* connection_first(void)
+Connection* connection_first( int *index )
{
assert( connections != NULL );
+ assert( index != NULL );
ldap_pvt_thread_mutex_lock( &connections_mutex );
- assert( conn_index == -1 );
- conn_index = 0;
+ *index = 0;
- return connection_next(NULL);
+ return connection_next(NULL, index);
}
-Connection* connection_next(Connection *c)
+Connection* connection_next( Connection *c, int *index )
{
assert( connections != NULL );
- assert( conn_index != -1 );
- assert( conn_index <= dtblsize );
+ assert( index != NULL );
+ assert( *index <= dtblsize );
if( c != NULL ) {
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
c = NULL;
- for(; conn_index < dtblsize; conn_index++) {
- if( connections[conn_index].c_struct_state == SLAP_C_UNINITIALIZED ) {
- assert( connections[conn_index].c_conn_state == SLAP_C_INVALID );
+ for(; *index < dtblsize; (*index)++) {
+ if( connections[*index].c_struct_state == SLAP_C_UNINITIALIZED ) {
+ assert( connections[*index].c_conn_state == SLAP_C_INVALID );
#ifndef HAVE_WINSOCK
continue;
#else
#endif
}
- if( connections[conn_index].c_struct_state == SLAP_C_USED ) {
- assert( connections[conn_index].c_conn_state != SLAP_C_INVALID );
- c = &connections[conn_index++];
+ if( connections[*index].c_struct_state == SLAP_C_USED ) {
+ assert( connections[*index].c_conn_state != SLAP_C_INVALID );
+ c = &connections[(*index)++];
break;
}
- assert( connections[conn_index].c_struct_state == SLAP_C_UNUSED );
- assert( connections[conn_index].c_conn_state == SLAP_C_INVALID );
+ assert( connections[*index].c_struct_state == SLAP_C_UNUSED );
+ assert( connections[*index].c_conn_state == SLAP_C_INVALID );
}
if( c != NULL ) {
return c;
}
-void connection_done(Connection *c)
+void connection_done( Connection *c )
{
assert( connections != NULL );
- assert( conn_index != -1 );
- assert( conn_index <= dtblsize );
if( c != NULL ) {
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
}
- conn_index = -1;
ldap_pvt_thread_mutex_unlock( &connections_mutex );
}