static Connection **connections = NULL;
/* set to the number of processors */
-#define NUM_CONNECTION_ARRAY 2
+# define NUM_CONNECTION_ARRAY 4
/* partition the array in a modulo manner */
-#define MCA_conn_array_id( fd ) ((int)fd%NUM_CONNECTION_ARRAY)
-#define MCA_conn_array_element_id( fd ) ((int)fd/NUM_CONNECTION_ARRAY)
+# define MCA_conn_array_id(fd) ((int)(fd)%NUM_CONNECTION_ARRAY)
+# define MCA_conn_array_element_id(fd) ((int)(fd)/NUM_CONNECTION_ARRAY)
+# define MCA_GET_CONNECTION(fd) (&(connections[MCA_conn_array_id(fd)])\
+ [MCA_conn_array_element_id(fd)])
+# define MCA_GET_CONN_MUTEX(fd) (&connections_mutex[MCA_conn_array_id(fd)])
-#define MCA_GET_CONNECTION(fd) &(connections[MCA_conn_array_id(fd)])[MCA_conn_array_element_id( fd )]
-#define MCA_GET_CONN_MUTEX(fd) &connections_mutex[MCA_conn_array_id(fd)]
#else
/* protected by connections_mutex */
static ldap_pvt_thread_mutex_t connections_mutex;
static Connection *connections = NULL;
+
+# define MCA_GET_CONNECTION(fd) (&connections[s])
+# define MCA_GET_CONN_MUTEX(fd) (&connections_mutex)
#endif
static ldap_pvt_thread_mutex_t conn_nextid_mutex;
}
#ifndef HAVE_WINSOCK
-#ifdef SLAP_MULTI_CONN_ARRAY
c = MCA_GET_CONNECTION(s);
-#else
- c = &connections[s];
-#endif
assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
assert( s < dtblsize );
#endif
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_lock( &connections_mutex );
-#endif
#ifndef HAVE_WINSOCK
-#ifdef SLAP_MULTI_CONN_ARRAY
c = MCA_GET_CONNECTION(s);
-#else
- c = &connections[s];
-#endif
-
#else
{
ber_socket_t i;
c->c_close_reason = "?"; /* should never be needed */
ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
slap_sasl_external( c, ssf, authid );
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
backend_connection_init(c);
assert( connections != NULL );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_lock( &connections_mutex );
-#endif
/* get (locked) connection */
c = connection_get( s );
(long) s, 0, 0 );
slapd_remove(s, 1, 0);
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return -1;
}
"connection_read(%d): closing, ignoring input for id=%lu\n",
s, c->c_connid, 0 );
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume( s );
c->c_clientfunc, c->c_clientarg );
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
!ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_DATA_READY, NULL ) )
{
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume( s );
/* If previous layer is not removed yet, give up for now */
if ( !c->c_sasl_sockctx ) {
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
#ifdef SLAP_LIGHTWEIGHT_LISTENER
slapd_resume( s );
connection_closing( c, "SASL layer install failure" );
connection_close( c );
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
}
connection_closing( c, conn_lost_str );
connection_close( c );
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
}
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
ber_sockbuf_ctrl( conn->c_sb, LBER_SB_OPT_GET_FD, &sd );
/* use trylock to avoid possible deadlock */
-#ifdef SLAP_MULTI_CONN_ARRAY
rc = ldap_pvt_thread_mutex_trylock( MCA_GET_CONN_MUTEX( sd ) );
-#else
- rc = ldap_pvt_thread_mutex_trylock( &connections_mutex );
-#endif
if( rc ) {
Debug( LDAP_DEBUG_TRACE,
* so recheck state below.
*/
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock( MCA_GET_CONN_MUTEX ( sd ) );
-#else
- ldap_pvt_thread_mutex_lock( &connections_mutex );
-#endif
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
}
connection_close( conn );
}
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX( sd ) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
assert( connections != NULL );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_lock( MCA_GET_CONN_MUTEX( s ) );
-#else
- ldap_pvt_thread_mutex_lock( &connections_mutex );
-#endif
c = connection_get( s );
if( c == NULL ) {
"connection_write(%ld): no connection!\n",
(long)s, 0, 0 );
slapd_remove(s, 1, 0);
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX( s ) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return -1;
}
}
connection_return( c );
-#ifdef SLAP_MULTI_CONN_ARRAY
ldap_pvt_thread_mutex_unlock( MCA_GET_CONN_MUTEX(s) );
-#else
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-#endif
return 0;
}
ber_socket_t sd_nactives;
int sd_nwriters;
-#ifdef SLAP_LIGHTWEIGHT_LISTENER
- /*
- * 0: reading on a FD is suspended
- * 1: reading on a FD is allowed
- */
- int *sd_suspend;
-#endif
-
#ifdef HAVE_EPOLL
struct epoll_event *sd_epolls;
int sd_nepolls;
int *sd_index;
int sd_epfd;
int sd_nfds;
+# ifdef SLAP_LIGHTWEIGHT_LISTENER
+ int *sd_suspend; /* 0: suspended, 1: not suspended */
+# endif
+
#else
#ifndef HAVE_WINSOCK
/* In winsock, accept() returns values higher than dtblsize
fd_set sd_actives;
fd_set sd_readers;
fd_set sd_writers;
+# ifdef SLAP_LIGHTWEIGHT_LISTENER
+ fd_set sd_suspend; /* unset: suspended, set: not suspended */
+# endif
#endif
} slap_daemon;
# ifdef SLAP_LIGHTWEIGHT_LISTENER
# define SLAP_SOCK_SET_INIT do { \
CHK_SETSIZE; \
- slap_daemon.sd_suspend = ch_malloc(sizeof(int) * dtblsize); \
- for (i=0; i<dtblsize; i++) slap_daemon.sd_suspend[i] = 0; \
FD_ZERO(&slap_daemon.sd_readers); \
FD_ZERO(&slap_daemon.sd_writers); \
+ FD_ZERO(&slap_daemon.sd_suspend); \
} while (0)
# else
# define SLAP_SOCK_SET_INIT do { \
!SLAP_SOCK_IS_READ(fd) && !SLAP_SOCK_IS_WRITE(fd))
# ifdef SLAP_LIGHTWEIGHT_LISTENER
-# define SLAP_SOCK_SET_SUSPEND(s) ( slap_daemon.sd_suspend[(s)] = 1 )
-# define SLAP_SOCK_CLR_SUSPEND(s) ( slap_daemon.sd_suspend[(s)] = 0 )
-# define SLAP_SOCK_IS_SUSPEND(s) ( slap_daemon.sd_suspend[(s)] == 1 )
+# define SLAP_SOCK_SET_SUSPEND(s) FD_SET((s), &slap_daemon.sd_suspend)
+# define SLAP_SOCK_CLR_SUSPEND(s) FD_CLR((s), &slap_daemon.sd_suspend)
+# define SLAP_SOCK_IS_SUSPEND(s) FD_ISSET((s), &slap_daemon.sd_suspend)
# endif
# ifdef HAVE_WINSOCK
int rc;
if ( ns <= 0 ) break;
-
- if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID )
- continue;
-
- if ( !SLAP_EVENT_IS_READ( slap_listeners[l]->sl_sd ))
- continue;
+ if ( slap_listeners[l]->sl_sd == AC_SOCKET_INVALID ) continue;
+ if ( !SLAP_EVENT_IS_READ( slap_listeners[l]->sl_sd )) continue;
#ifdef SLAP_LIGHTWEIGHT_LISTENER
if ( SLAP_EVENT_IS_LISTENER(i)
#ifdef LDAP_CONNECTIONLESS
- && !((SLAP_EVENT_LISTENER(i))->sl_is_udp)
+ && !((SLAP_EVENT_LISTENER(i))->sl_is_udp)
#endif
- ) continue;
+ )
+ {
+ continue;
+ }
/* Don't log internal wake events */
- if ( SLAP_EVENT_FD( i ) == wake_sds[0] )
- continue;
+ if ( SLAP_EVENT_FD( i ) == wake_sds[0] ) continue;
r = SLAP_EVENT_IS_READ( i );
w = SLAP_EVENT_IS_WRITE( i );
if ( SLAP_EVENT_IS_LISTENER(i) ) {
#ifdef SLAP_LIGHTWEIGHT_LISTENER
- rc = new_connection_activate(SLAP_EVENT_LISTENER( i ));
+ rc = new_connection_activate( SLAP_EVENT_LISTENER( i ));
#else
rc = slapd_handle_listener( SLAP_EVENT_LISTENER( i ));
#endif
fd = SLAP_EVENT_FD( i );
/* Ignore wake events, they were handled above */
- if ( fd == wake_sds[0] )
- continue;
+ if ( fd == wake_sds[0] ) continue;
if( SLAP_EVENT_IS_WRITE( i ) ) {
Debug( LDAP_DEBUG_CONNS,
connection_processing_activate( fd );
}
#else
- if ( connection_read( fd ) < 0 ) {
- slapd_close( fd );
- }
+ if ( connection_read( fd ) < 0 ) slapd_close( fd );
#endif
}
}
0, 0, 0 );
}
- if( slapd_gentle_shutdown != 2 ) {
- close_listeners ( 0 );
- }
+ if( slapd_gentle_shutdown != 2 ) close_listeners ( 0 );
if( !slapd_gentle_shutdown ) {
slapd_abrupt_shutdown = 1;
/* The WinSock DLL is acceptable. Proceed. */
#elif defined( HAVE_WINSOCK )
WSADATA wsaData;
- if ( WSAStartup( 0x0101, &wsaData ) != 0 ) {
- return -1;
- }
+ if ( WSAStartup( 0x0101, &wsaData ) != 0 ) return -1;
#endif
+
return 0;
}
}
RETSIGTYPE
-slap_sig_shutdown( int sig ) {
+slap_sig_shutdown( int sig )
+{
#if 0
Debug(LDAP_DEBUG_TRACE, "slap_sig_shutdown: signal %d\n", sig, 0, 0);
#endif