Commit eb16972d authored by Howard Chu's avatar Howard Chu
Browse files

Streamlined Winsock connection management

parent 53b87d1d
......@@ -254,57 +254,14 @@ static Connection* connection_get( ber_socket_t s )
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 */
......@@ -358,6 +315,7 @@ Connection * connection_init(
unsigned long id;
Connection *c;
int doinit = 0;
ber_socket_t sfd = SLAP_FD2SOCK(s);
assert( connections != NULL );
......@@ -376,7 +334,6 @@ Connection * connection_init(
}
assert( s >= 0 );
#ifndef HAVE_WINSOCK
assert( s < dtblsize );
c = &connections[s];
if( c->c_struct_state == SLAP_C_UNINITIALIZED ) {
......@@ -384,45 +341,6 @@ Connection * connection_init(
} 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;
......@@ -508,7 +426,7 @@ Connection * connection_init(
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;
......@@ -545,7 +463,7 @@ Connection * connection_init(
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
......@@ -557,7 +475,7 @@ Connection * connection_init(
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 );
......@@ -570,7 +488,7 @@ Connection * connection_init(
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
......@@ -926,11 +844,7 @@ Connection* connection_next( Connection *c, ber_socket_t *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 ) {
......@@ -1219,37 +1133,38 @@ operations_error:
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 );
......@@ -1277,7 +1192,7 @@ static int connection_read( ber_socket_t s, conn_readinfo *cri );
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;
/*
......
......@@ -2,6 +2,7 @@
/* 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
......@@ -85,13 +86,13 @@ static volatile int waking;
#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 */
......@@ -100,6 +101,15 @@ volatile sig_atomic_t slapd_shutdown = 0;
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
......@@ -108,28 +118,27 @@ static struct slap_daemon {
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;
......@@ -457,13 +466,119 @@ static struct 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
......@@ -500,25 +615,13 @@ static struct slap_daemon {
# 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)
......@@ -545,6 +648,7 @@ static struct slap_daemon {
*(nsp) = select( SLAP_EVENT_MAX, &readfds, \
nwriters > 0 ? &writefds : NULL, NULL, (tvp) ); \
} while (0)
# endif /* !HAVE_WINSOCK */
#endif /* ! epoll && ! /dev/poll */
#ifdef HAVE_SLP
......@@ -675,6 +779,42 @@ slapd_slp_dereg( void )
}
#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
*
......@@ -848,7 +988,10 @@ slapd_close( ber_socket_t s )
{
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
......@@ -1103,6 +1246,7 @@ slap_open_listener(
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)
/*
......@@ -1220,8 +1364,8 @@ slap_open_listener(
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",
......@@ -1229,17 +1373,16 @@ slap_open_listener(
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 ) {
......@@ -1250,7 +1393,7 @@ slap_open_listener(
#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();
......@@ -1270,7 +1413,7 @@ slap_open_listener(
#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();
......@@ -1288,7 +1431,7 @@ slap_open_listener(
#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 */
......@@ -1312,7 +1455,7 @@ slap_open_listener(
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 );
......@@ -1324,7 +1467,7 @@ slap_open_listener(
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;
}
......@@ -1498,8 +1641,8 @@ int
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
......@@ -1558,7 +1701,7 @@ slap_listener(
{
Sockaddr from;
ber_socket_t s;
ber_socket_t s, sfd;
ber_socklen_t len = sizeof(from);
Connection *c;
slap_ssf_t ssf = 0;
......@@ -1598,7 +1741,7 @@ slap_listener(
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.
......@@ -1631,24 +1774,23 @@ slap_listener(
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();