if(s == AC_SOCKET_INVALID) return NULL;
-#ifndef HAVE_WINSOCK
assert( s < dtblsize );
c = &connections[s];
-#else
- c = NULL;
- {
- ldap_pvt_thread_mutex_lock( &connections_mutex );
- for(i=0; i<dtblsize; i++) {
- if( connections[i].c_struct_state == SLAP_C_PENDING )
- continue;
-
- if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
- assert( connections[i].c_conn_state == SLAP_C_INVALID );
- assert( connections[i].c_sb == 0 );
- break;
- }
-
- if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
- assert( connections[i].c_conn_state == SLAP_C_INVALID );
- assert( connections[i].c_sd == AC_SOCKET_INVALID );
- continue;
- }
-
- /* state can actually change from used -> unused by resched,
- * so don't assert details here.
- */
-
- if( connections[i].c_sd == s ) {
- c = &connections[i];
- break;
- }
- }
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
- }
-#endif
-
if( c != NULL ) {
ldap_pvt_thread_mutex_lock( &c->c_mutex );
assert( c->c_struct_state != SLAP_C_UNINITIALIZED );
-#ifdef HAVE_WINSOCK
- /* Avoid race condition after releasing
- * connections_mutex
- */
- if ( c->c_sd != s ) {
- ldap_pvt_thread_mutex_unlock( &c->c_mutex );
- return NULL;
- }
-#endif
if( c->c_struct_state != SLAP_C_USED ) {
/* connection must have been closed due to resched */
unsigned long id;
Connection *c;
int doinit = 0;
+ ber_socket_t sfd = SLAP_FD2SOCK(s);
assert( connections != NULL );
}
assert( s >= 0 );
-#ifndef HAVE_WINSOCK
assert( s < dtblsize );
c = &connections[s];
if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
} else {
assert( c->c_struct_state == SLAP_C_UNUSED );
}
-#else
- {
- ber_socket_t i;
- c = NULL;
-
- ldap_pvt_thread_mutex_lock( &connections_mutex );
- for( i=0; i < dtblsize; i++) {
- if ( connections[i].c_struct_state == SLAP_C_PENDING )
- continue;
-
- if( connections[i].c_struct_state == SLAP_C_UNINITIALIZED ) {
- assert( connections[i].c_sb == 0 );
- c = &connections[i];
- c->c_struct_state = SLAP_C_PENDING;
- doinit = 1;
- break;
- }
-
- if( connections[i].c_struct_state == SLAP_C_UNUSED ) {
- c = &connections[i];
- c->c_struct_state = SLAP_C_PENDING;
- break;
- }
-
- if( connections[i].c_conn_state == SLAP_C_CLIENT ) continue;
-
- assert( connections[i].c_struct_state == SLAP_C_USED );
- assert( connections[i].c_conn_state != SLAP_C_INVALID );
- }
- ldap_pvt_thread_mutex_unlock( &connections_mutex );
-
- if( c == NULL ) {
- Debug( LDAP_DEBUG_ANY,
- "connection_init(%d): connection table full "
- "(%d/%d)\n", s, i, dtblsize);
- return NULL;
- }
- }
-#endif
if( doinit ) {
c->c_send_ldap_result = slap_send_ldap_result;
c->c_conn_state = SLAP_C_CLIENT;
c->c_struct_state = SLAP_C_USED;
c->c_close_reason = "?"; /* should never be needed */
- ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &s );
+ ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_SET_FD, &sfd );
ldap_pvt_thread_mutex_unlock( &c->c_mutex );
return c;
LBER_SBIOD_LEVEL_PROVIDER, (void*)"udp_" );
#endif
ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_udp,
- LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
+ LBER_SBIOD_LEVEL_PROVIDER, (void *)&sfd );
ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_readahead,
LBER_SBIOD_LEVEL_PROVIDER, NULL );
} else
LBER_SBIOD_LEVEL_PROVIDER, (void*)"ipc_" );
#endif
ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_fd,
- LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
+ LBER_SBIOD_LEVEL_PROVIDER, (void *)&sfd );
#ifdef LDAP_PF_LOCAL_SENDMSG
if ( !BER_BVISEMPTY( peerbv ))
ber_sockbuf_ctrl( c->c_sb, LBER_SB_OPT_UNGET_BUF, peerbv );
LBER_SBIOD_LEVEL_PROVIDER, (void*)"tcp_" );
#endif
ber_sockbuf_add_io( c->c_sb, &ber_sockbuf_io_tcp,
- LBER_SBIOD_LEVEL_PROVIDER, (void *)&s );
+ LBER_SBIOD_LEVEL_PROVIDER, (void *)&sfd );
}
#ifdef LDAP_DEBUG
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 ) {
static const Listener dummy_list = { BER_BVC(""), BER_BVC("") };
-int connection_client_setup(
+Connection *connection_client_setup(
ber_socket_t s,
ldap_pvt_thread_start_t *func,
void *arg )
{
Connection *c;
+ ber_socket_t sfd = SLAP_SOCKNEW( s );
- c = connection_init( s, (Listener *)&dummy_list, "", "",
+ c = connection_init( sfd, (Listener *)&dummy_list, "", "",
CONN_IS_CLIENT, 0, NULL
LDAP_PF_LOCAL_SENDMSG_ARG(NULL));
- if ( !c ) return -1;
+ if ( c ) {
+ c->c_clientfunc = func;
+ c->c_clientarg = arg;
- c->c_clientfunc = func;
- c->c_clientarg = arg;
-
- slapd_add_internal( s, 0 );
- slapd_set_read( s, 1 );
- return 0;
+ slapd_add_internal( sfd, 0 );
+ slapd_set_read( sfd, 1 );
+ }
+ return c;
}
void connection_client_enable(
- ber_socket_t s )
+ Connection *c )
{
- slapd_set_read( s, 1 );
+ slapd_set_read( c->c_sd, 1 );
}
void connection_client_stop(
- ber_socket_t s )
+ Connection *c )
{
- Connection *c;
Sockbuf *sb;
+ ber_socket_t s = c->c_sd;
/* get (locked) connection */
c = connection_get( s );
static void* connection_read_thread( void* ctx, void* argv )
{
int rc ;
- conn_readinfo cri = { NULL, NULL, NULL, 0 };
+ conn_readinfo cri = { NULL, NULL, NULL, NULL, 0 };
ber_socket_t s = (long)argv;
/*
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
* Copyright 1998-2007 The OpenLDAP Foundation.
+ * Portions Copyright 2007 by Howard Chu, Symas Corporation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#ifdef NO_THREADS
#define WAKE_LISTENER(w) do { \
if ((w) && ++waking < 5) { \
- tcp_write( wake_sds[1], "0", 1 ); \
+ tcp_write( SLAP_FD2SOCK(wake_sds[1]), "0", 1 ); \
} \
} while (0)
#else /* ! NO_THREADS */
#define WAKE_LISTENER(w) do { \
if (w) { \
- tcp_write( wake_sds[1], "0", 1 ); \
+ tcp_write( SLAP_FD2SOCK(wake_sds[1]), "0", 1 ); \
} \
} while (0)
#endif /* ! NO_THREADS */
volatile sig_atomic_t slapd_gentle_shutdown = 0;
volatile sig_atomic_t slapd_abrupt_shutdown = 0;
+#ifdef HAVE_WINSOCK
+ldap_pvt_thread_mutex_t slapd_ws_mutex;
+SOCKET *slapd_ws_sockets;
+#define SD_READ 1
+#define SD_WRITE 2
+#define SD_ACTIVE 4
+#define SD_LISTENER 8
+#endif
+
static struct slap_daemon {
ldap_pvt_thread_mutex_t sd_mutex;
#ifdef HAVE_TCPD
ber_socket_t sd_nactives;
int sd_nwriters;
+ int sd_nfds;
#if defined(HAVE_EPOLL)
struct epoll_event *sd_epolls;
int *sd_index;
int sd_epfd;
- int sd_nfds;
#elif defined(SLAP_X_DEVPOLL) && defined(HAVE_DEVPOLL)
/* eXperimental */
struct pollfd *sd_pollfd;
int *sd_index;
Listener **sd_l;
int sd_dpfd;
- int sd_nfds;
#else /* ! epoll && ! /dev/poll */
-#ifndef HAVE_WINSOCK
- /* In winsock, accept() returns values higher than dtblsize
- so don't bother with this optimization */
- int sd_nfds;
-#endif /* ! HAVE_WINSOCK */
+#ifdef HAVE_WINSOCK
+ char *sd_flags;
+ char *sd_rflags;
+#else /* ! HAVE_WINSOCK */
fd_set sd_actives;
fd_set sd_readers;
fd_set sd_writers;
+#endif /* ! HAVE_WINSOCK */
#endif /* ! epoll && ! /dev/poll */
} slap_daemon;
} while (0)
#else /* ! epoll && ! /dev/poll */
+# ifdef HAVE_WINSOCK
+# define SLAP_EVENT_FNAME "WSselect"
+/* Winsock provides a "select" function but its fd_sets are
+ * actually arrays of sockets. Since these sockets are handles
+ * and not a contiguous range of small integers, we manage our
+ * own "fd" table of socket handles and use their indices as
+ * descriptors.
+ *
+ * All of our listener/connection structures use fds; the actual
+ * I/O functions use sockets. The SLAP_FD2SOCK macro in proto-slap.h
+ * handles the mapping.
+ *
+ * Despite the mapping overhead, this is about 45% more efficient
+ * than just using Winsock's select and FD_ISSET directly.
+ *
+ * Unfortunately Winsock's select implementation doesn't scale well
+ * as the number of connections increases. This probably needs to be
+ * rewritten to use the Winsock overlapped/asynchronous I/O functions.
+ */
+# define SLAP_EVENTS_ARE_INDEXED 1
+# define SLAP_EVENT_DECL fd_set readfds, writefds
+# define SLAP_EVENT_INIT do { \
+ int i; \
+ FD_ZERO( &readfds ); \
+ FD_ZERO( &writefds ); \
+ memset( slap_daemon.sd_rflags, 0, slap_daemon.sd_nfds ); \
+ for ( i=0; i<slap_daemon.sd_nfds; i++ ) { \
+ if ( slap_daemon.sd_flags[i] & SD_READ ) \
+ FD_SET( slapd_ws_sockets[i], &readfds );\
+ if ( slap_daemon.sd_flags[i] & SD_WRITE ) \
+ FD_SET( slapd_ws_sockets[i], &writefds ); \
+ } } while ( 0 )
+
+# define SLAP_EVENT_MAX slap_daemon.sd_nfds
+
+# define SLAP_EVENT_WAIT(tvp, nsp) do { \
+ int i; \
+ *(nsp) = select( SLAP_EVENT_MAX, &readfds, \
+ nwriters > 0 ? &writefds : NULL, NULL, (tvp) ); \
+ for ( i=0; i<readfds.fd_count; i++) { \
+ int fd = slapd_sock2fd(readfds.fd_array[i]); \
+ if ( fd >= 0 ) { \
+ slap_daemon.sd_rflags[fd] = SD_READ; \
+ if ( fd >= *(nsp)) *(nsp) = fd+1; \
+ } \
+ } \
+ for ( i=0; i<writefds.fd_count; i++) { \
+ int fd = slapd_sock2fd(writefds.fd_array[i]); \
+ if ( fd >= 0 ) { \
+ slap_daemon.sd_rflags[fd] = SD_WRITE; \
+ if ( fd >= *(nsp)) *(nsp) = fd+1; \
+ } \
+ } \
+} while (0)
+
+# define SLAP_EVENT_IS_READ(fd) (slap_daemon.sd_rflags[fd] & SD_READ)
+# define SLAP_EVENT_IS_WRITE(fd) (slap_daemon.sd_rflags[fd] & SD_WRITE)
+
+# define SLAP_EVENT_CLR_READ(fd) slap_daemon.sd_rflags[fd] &= ~SD_READ;
+# define SLAP_EVENT_CLR_WRITE(fd) slap_daemon.sd_rflags[fd] &= ~SD_WRITE;
+
+# define SLAP_SOCK_INIT do { \
+ ldap_pvt_thread_mutex_init( &slapd_ws_mutex ); \
+ slapd_ws_sockets = ch_malloc( dtblsize * ( sizeof(SOCKET) + 2)); \
+ slap_daemon.sd_flags = (char *)(slapd_ws_sockets + dtblsize); \
+ slap_daemon.sd_rflags = slap_daemon.sd_flags + dtblsize; \
+ memset( slapd_ws_sockets, -1, dtblsize * sizeof(SOCKET) ); \
+ slapd_ws_sockets[0] = wake_sds[0]; \
+ slapd_ws_sockets[1] = wake_sds[1]; \
+ wake_sds[0] = 0; \
+ wake_sds[1] = 1; \
+ slap_daemon.sd_nfds = 2; \
+ } while ( 0 )
+
+# define SLAP_SOCK_DESTROY do { \
+ ch_free( slapd_ws_sockets ); slapd_ws_sockets = NULL; \
+ slap_daemon.sd_flags = NULL; \
+ slap_daemon.sd_rflags = NULL; \
+ ldap_pvt_thread_mutex_destroy( &slapd_ws_mutex ); \
+ } while ( 0 )
+
+# define SLAP_SOCK_IS_ACTIVE(fd) ( slap_daemon.sd_flags[fd] & SD_ACTIVE )
+# define SLAP_SOCK_IS_READ(fd) ( slap_daemon.sd_flags[fd] & SD_READ )
+# define SLAP_SOCK_IS_WRITE(fd) ( slap_daemon.sd_flags[fd] & SD_WRITE )
+# define SLAP_SOCK_NOT_ACTIVE(fd) (!slap_daemon.sd_flags[fd])
+
+# define SLAP_SOCK_SET_READ(fd) ( slap_daemon.sd_flags[fd] |= SD_READ )
+# define SLAP_SOCK_SET_WRITE(fd) ( slap_daemon.sd_flags[fd] |= SD_WRITE )
+
+# define SLAP_SELECT_ADDTEST(s) do { \
+ if ((s) >= slap_daemon.sd_nfds) slap_daemon.sd_nfds = (s)+1; \
+} while (0)
+
+# define SLAP_SOCK_CLR_READ(fd) ( slap_daemon.sd_flags[fd] &= ~SD_READ )
+# define SLAP_SOCK_CLR_WRITE(fd) ( slap_daemon.sd_flags[fd] &= ~SD_WRITE )
+
+# define SLAP_SOCK_ADD(s, l) do { \
+ SLAP_SELECT_ADDTEST((s)); \
+ slap_daemon.sd_flags[s] = SD_ACTIVE|SD_READ; \
+} while ( 0 )
+
+# define SLAP_SOCK_DEL(s) do { \
+ slap_daemon.sd_flags[s] = 0; \
+ slapd_sockdel( s ); \
+} while ( 0 )
+
+# else /* !HAVE_WINSOCK */
/**************************************
* Use select system call - select(2) *
**************************************/
# define SLAP_EVENT_FNAME "select"
/* select */
-
# define SLAP_EVENTS_ARE_INDEXED 1
# define SLAP_EVENT_DECL fd_set readfds, writefds
# define SLAP_SOCK_NOT_ACTIVE(fd) (!SLAP_SOCK_IS_ACTIVE(fd) && \
!SLAP_SOCK_IS_READ(fd) && !SLAP_SOCK_IS_WRITE(fd))
-# ifdef HAVE_WINSOCK
-# define SLAP_SOCK_SET_READ(fd) do { \
- if (!SLAP_SOCK_IS_READ(fd)) { FD_SET((fd), &slap_daemon.sd_readers); } \
-} while (0)
-# define SLAP_SOCK_SET_WRITE(fd) do { \
- if (!SLAP_SOCK_IS_WRITE(fd)) { FD_SET((fd), &slap_daemon.sd_writers); } \
-} while (0)
-
-# define SLAP_SELECT_ADDTEST(s)
-# define SLAP_EVENT_MAX dtblsize
-# else /* ! HAVE_WINSOCK */
-# define SLAP_SOCK_SET_READ(fd) FD_SET((fd), &slap_daemon.sd_readers)
-# define SLAP_SOCK_SET_WRITE(fd) FD_SET((fd), &slap_daemon.sd_writers)
+# define SLAP_SOCK_SET_READ(fd) FD_SET((fd), &slap_daemon.sd_readers)
+# define SLAP_SOCK_SET_WRITE(fd) FD_SET((fd), &slap_daemon.sd_writers)
-# define SLAP_EVENT_MAX slap_daemon.sd_nfds
-# define SLAP_SELECT_ADDTEST(s) do { \
+# define SLAP_EVENT_MAX slap_daemon.sd_nfds
+# define SLAP_SELECT_ADDTEST(s) do { \
if ((s) >= slap_daemon.sd_nfds) slap_daemon.sd_nfds = (s)+1; \
} while (0)
-# endif /* ! HAVE_WINSOCK */
# define SLAP_SOCK_CLR_READ(fd) FD_CLR((fd), &slap_daemon.sd_readers)
# define SLAP_SOCK_CLR_WRITE(fd) FD_CLR((fd), &slap_daemon.sd_writers)
*(nsp) = select( SLAP_EVENT_MAX, &readfds, \
nwriters > 0 ? &writefds : NULL, NULL, (tvp) ); \
} while (0)
+# endif /* !HAVE_WINSOCK */
#endif /* ! epoll && ! /dev/poll */
#ifdef HAVE_SLP
}
#endif /* HAVE_SLP */
+#ifdef HAVE_WINSOCK
+/* Manage the descriptor to socket table */
+ber_socket_t
+slapd_socknew( ber_socket_t s )
+{
+ ber_socket_t i;
+ ldap_pvt_thread_mutex_lock( &slapd_ws_mutex );
+ for ( i = 0; i < dtblsize && slapd_ws_sockets[i] != INVALID_SOCKET; i++ );
+ if ( i == dtblsize ) {
+ WSASetLastError( WSAEMFILE );
+ } else {
+ slapd_ws_sockets[i] = s;
+ }
+ ldap_pvt_thread_mutex_unlock( &slapd_ws_mutex );
+ return i;
+}
+
+void
+slapd_sockdel( ber_socket_t s )
+{
+ ldap_pvt_thread_mutex_lock( &slapd_ws_mutex );
+ slapd_ws_sockets[s] = INVALID_SOCKET;
+ ldap_pvt_thread_mutex_unlock( &slapd_ws_mutex );
+}
+
+ber_socket_t
+slapd_sock2fd( ber_socket_t s )
+{
+ ber_socket_t i;
+ for ( i=0; i<dtblsize && slapd_ws_sockets[i] != s; i++);
+ if ( i == dtblsize )
+ i = -1;
+ return i;
+}
+#endif
+
/*
* Add a descriptor to daemon control
*
{
Debug( LDAP_DEBUG_CONNS, "daemon: closing %ld\n",
(long) s, 0, 0 );
- tcp_close(s);
+ tcp_close( SLAP_FD2SOCK(s) );
+#ifdef HAVE_WINSOCK
+ slapd_sockdel( s );
+#endif
}
static void
int err, addrlen = 0;
struct sockaddr **sal, **psal;
int socktype = SOCK_STREAM; /* default to COTS */
+ ber_socket_t s;
#if defined(LDAP_PF_LOCAL) || defined(SLAP_X_LISTENER_MOD)
/*
if( l.sl_is_udp ) socktype = SOCK_DGRAM;
#endif /* LDAP_CONNECTIONLESS */
- l.sl_sd = socket( (*sal)->sa_family, socktype, 0);
- if ( l.sl_sd == AC_SOCKET_INVALID ) {
+ s = socket( (*sal)->sa_family, socktype, 0);
+ if ( s == AC_SOCKET_INVALID ) {
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"daemon: %s socket() failed errno=%d (%s)\n",
sal++;
continue;
}
+ l.sl_sd = SLAP_SOCKNEW( s );
-#ifndef HAVE_WINSOCK
if ( l.sl_sd >= dtblsize ) {
Debug( LDAP_DEBUG_ANY,
"daemon: listener descriptor %ld is too great %ld\n",
(long) l.sl_sd, (long) dtblsize, 0 );
- tcp_close( l.sl_sd );
+ tcp_close( s );
sal++;
continue;
}
-#endif /* ! HAVE_WINSOCK */
#ifdef LDAP_PF_LOCAL
if ( (*sal)->sa_family == AF_LOCAL ) {
#ifdef SO_REUSEADDR
/* enable address reuse */
tmp = 1;
- rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR,
+ rc = setsockopt( s, SOL_SOCKET, SO_REUSEADDR,
(char *) &tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
#ifdef IPV6_V6ONLY
/* Try to use IPv6 sockets for IPv6 only */
tmp = 1;
- rc = setsockopt( l.sl_sd, IPPROTO_IPV6, IPV6_V6ONLY,
+ rc = setsockopt( s , IPPROTO_IPV6, IPV6_V6ONLY,
(char *) &tmp, sizeof(tmp) );
if ( rc == AC_SOCKET_ERROR ) {
int err = sock_errno();
#ifdef LOCAL_CREDS
{
int one = 1;
- setsockopt( l.sl_sd, 0, LOCAL_CREDS, &one, sizeof( one ) );
+ setsockopt( s, 0, LOCAL_CREDS, &one, sizeof( one ) );
}
#endif /* LOCAL_CREDS */
old_umask = umask( 0 );
}
#endif /* LDAP_PF_LOCAL */
- rc = bind( l.sl_sd, *sal, addrlen );
+ rc = bind( s, *sal, addrlen );
#ifdef LDAP_PF_LOCAL
if ( (*sal)->sa_family == AF_LOCAL ) {
umask( old_umask );
Debug( LDAP_DEBUG_ANY,
"daemon: bind(%ld) failed errno=%d (%s)\n",
(long)l.sl_sd, err, sock_errstr( err ) );
- tcp_close( l.sl_sd );
+ tcp_close( s );
sal++;
continue;
}
slapd_daemon_destroy( void )
{
connections_destroy();
- tcp_close( wake_sds[1] );
- tcp_close( wake_sds[0] );
+ tcp_close( SLAP_FD2SOCK(wake_sds[1]) );
+ tcp_close( SLAP_FD2SOCK(wake_sds[0]) );
sockdestroy();
#ifdef HAVE_SLP
{
Sockaddr from;
- ber_socket_t s;
+ ber_socket_t s, sfd;
ber_socklen_t len = sizeof(from);
Connection *c;
slap_ssf_t ssf = 0;
from.sa_un_addr.sun_path[0] = '\0';
# endif /* LDAP_PF_LOCAL */
- s = accept( sl->sl_sd, (struct sockaddr *) &from, &len );
+ s = accept( SLAP_FD2SOCK( sl->sl_sd ), (struct sockaddr *) &from, &len );
/* Resume the listener FD to allow concurrent-processing of
* additional incoming connections.
ldap_pvt_thread_yield();
return 0;
}
+ sfd = SLAP_SOCKNEW( s );
-#ifndef HAVE_WINSOCK
/* make sure descriptor number isn't too great */
- if ( s >= dtblsize ) {
+ if ( sfd >= dtblsize ) {
Debug( LDAP_DEBUG_ANY,
"daemon: %ld beyond descriptor table size %ld\n",
- (long) s, (long) dtblsize, 0 );
+ (long) sfd, (long) dtblsize, 0 );
- slapd_close(s);
+ tcp_close(s);
ldap_pvt_thread_yield();
return 0;
}
-#endif /* ! HAVE_WINSOCK */
#ifdef LDAP_DEBUG
ldap_pvt_thread_mutex_lock( &slap_daemon.sd_mutex );
/* newly accepted stream should not be in any of the FD SETS */
- assert( SLAP_SOCK_NOT_ACTIVE( s ));
+ assert( SLAP_SOCK_NOT_ACTIVE( sfd ));
ldap_pvt_thread_mutex_unlock( &slap_daemon.sd_mutex );
#endif /* LDAP_DEBUG */
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(SO_KEEPALIVE) failed "
- "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
+ "errno=%d (%s)\n", (long) sfd, err, sock_errstr(err) );
}
#endif /* SO_KEEPALIVE */
#ifdef TCP_NODELAY
int err = sock_errno();
Debug( LDAP_DEBUG_ANY,
"slapd(%ld): setsockopt(TCP_NODELAY) failed "
- "errno=%d (%s)\n", (long) s, err, sock_errstr(err) );
+ "errno=%d (%s)\n", (long) sfd, err, sock_errstr(err) );
}
#endif /* TCP_NODELAY */
}
Debug( LDAP_DEBUG_CONNS,
"daemon: listen=%ld, new connection on %ld\n",
- (long) sl->sl_sd, (long) s, 0 );
+ (long) sl->sl_sd, (long) sfd, 0 );
cflag = 0;
switch ( from.sa_addr.sa_family ) {
break;
default:
- slapd_close(s);
+ slapd_close(sfd);
return 0;
}
/* DENY ACCESS */
Statslog( LDAP_DEBUG_STATS,
"fd=%ld DENIED from %s (%s)\n",
- (long) s,
+ (long) sfd,
dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
peeraddr != NULL ? peeraddr : SLAP_STRING_UNKNOWN,
0, 0 );
- slapd_close(s);
+ slapd_close(sfd);
return 0;
}
}
#ifdef HAVE_TLS
if ( sl->sl_is_tls ) cflag |= CONN_IS_TLS;
#endif
- c = connection_init(s, sl,
+ c = connection_init(sfd, sl,
dnsname != NULL ? dnsname : SLAP_STRING_UNKNOWN,
peername, cflag, ssf,
authid.bv_val ? &authid : NULL
if( !c ) {
Debug( LDAP_DEBUG_ANY,
"daemon: connection_init(%ld, %s, %s) failed.\n",
- (long) s, peername, sl->sl_name.bv_val );
- slapd_close(s);
+ (long) sfd, peername, sl->sl_name.bv_val );
+ slapd_close(sfd);
return 0;
}
Statslog( LDAP_DEBUG_STATS,
"conn=%ld fd=%ld ACCEPT from %s (%s)\n",
- c->c_connid, (long) s, peername, sl->sl_name.bv_val,
+ c->c_connid, (long) sfd, peername, sl->sl_name.bv_val,
0 );
return 0;
continue;
#endif /* LDAP_CONNECTIONLESS */
- if ( listen( slap_listeners[l]->sl_sd, SLAPD_LISTEN_BACKLOG ) == -1 ) {
+ if ( listen( SLAP_FD2SOCK( slap_listeners[l]->sl_sd ), SLAPD_LISTEN_BACKLOG ) == -1 ) {
int err = sock_errno();
#ifdef LDAP_PF_INET6
}
/* make the listening socket non-blocking */
- if ( ber_pvt_socket_set_nonblock( slap_listeners[l]->sl_sd, 1 ) < 0 ) {
+ if ( ber_pvt_socket_set_nonblock( SLAP_FD2SOCK( slap_listeners[l]->sl_sd ), 1 ) < 0 ) {
Debug( LDAP_DEBUG_ANY, "slapd_daemon_task: "
"set nonblocking on a listening socket failed\n",
0, 0, 0 );
char c[BUFSIZ];
SLAP_EVENT_CLR_READ( wake_sds[0] );
waking = 0;
- tcp_read( wake_sds[0], c, sizeof(c) );
+ tcp_read( SLAP_FD2SOCK(wake_sds[0]), c, sizeof(c) );
Debug( LDAP_DEBUG_CONNS, "daemon: waked\n", 0, 0, 0 );
continue;
}
}
Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
-#ifdef HAVE_WINSOCK
- nrfds = readfds.fd_count;
- nwfds = writefds.fd_count;
- for ( i = 0; i < readfds.fd_count; i++ ) {
- Debug( LDAP_DEBUG_CONNS, " %d%s",
- readfds.fd_array[i], "r", 0 );
- }
- for ( i = 0; i < writefds.fd_count; i++ ) {
- Debug( LDAP_DEBUG_CONNS, " %d%s",
- writefds.fd_array[i], "w", 0 );
- }
-
-#else /* ! HAVE_WINSOCK */
nrfds = 0;
nwfds = 0;
for ( i = 0; i < nfds; i++ ) {
}
if ( ns <= 0 ) break;
}
-#endif /* ! HAVE_WINSOCK */
Debug( LDAP_DEBUG_CONNS, "\n", 0, 0, 0 );
/* loop through the writers */
for ( i = 0; nwfds > 0; i++ ) {
ber_socket_t wd;
-#ifdef HAVE_WINSOCK
- wd = writefds.fd_array[i];
-#else /* ! HAVE_WINSOCK */
if ( ! SLAP_EVENT_IS_WRITE( i ) ) continue;
wd = i;
-#endif /* ! HAVE_WINSOCK */
SLAP_EVENT_CLR_WRITE( wd );
nwfds--;
for ( i = 0; nrfds > 0; i++ ) {
ber_socket_t rd;
-#ifdef HAVE_WINSOCK
- rd = readfds.fd_array[i];
-#else /* ! HAVE_WINSOCK */
if ( ! SLAP_EVENT_IS_READ( i ) ) continue;
rd = i;
-#endif /* ! HAVE_WINSOCK */
SLAP_EVENT_CLR_READ( rd );
nrfds--;
Debug( LDAP_DEBUG_CONNS, "daemon: activity on:", 0, 0, 0 );
for ( i = 0; i < ns; i++ ) {
- int r, w;
+ int r, w, fd;
/* Don't log listener events */
if ( SLAP_EVENT_IS_LISTENER( i )
continue;
}
+ fd = SLAP_EVENT_FD( i );
/* Don't log internal wake events */
- if ( SLAP_EVENT_FD( i ) == wake_sds[0] ) continue;
+ if ( fd == wake_sds[0] ) continue;
r = SLAP_EVENT_IS_READ( i );
w = SLAP_EVENT_IS_WRITE( i );
if ( r || w ) {
- Debug( LDAP_DEBUG_CONNS, " %d%s%s", SLAP_EVENT_FD(i),
+ Debug( LDAP_DEBUG_CONNS, " %d%s%s", fd,
r ? "r" : "", w ? "w" : "" );
}
}
if ( fd == wake_sds[0] ) {
char c[BUFSIZ];
waking = 0;
- tcp_read( wake_sds[0], c, sizeof(c) );
+ tcp_read( SLAP_FD2SOCK(wake_sds[0]), c, sizeof(c) );
break;
}