From ac8b5468aadcb26e9729c0c90e682e904774c7d3 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Tue, 31 Aug 1999 16:47:42 +0000 Subject: [PATCH] Clean up soctpair for NT. Add USE_PAIR to allow pair(2) use. --- build/build.dsp | 4 +++ include/ac/socket.h | 10 ++++++ libraries/liblutil/liblutil.dsp | 4 +++ libraries/liblutil/sockpair.c | 11 ++++--- servers/slapd/daemon.c | 57 +++++++++------------------------ 5 files changed, 40 insertions(+), 46 deletions(-) diff --git a/build/build.dsp b/build/build.dsp index 9663b97c0c..6626fcdbbf 100644 --- a/build/build.dsp +++ b/build/build.dsp @@ -120,5 +120,9 @@ CFG=build - Win32 Single Debug !ENDIF +# Begin Source File + +SOURCE=..\libraries\liblutil\sockpair.c +# End Source File # End Target # End Project diff --git a/include/ac/socket.h b/include/ac/socket.h index d63935a80c..154d6f5ebb 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -88,6 +88,8 @@ #define sock_errno() WSAGetLastError() #define sock_errstr(e) WSAGetErrorString(e) +extern char* WSAGetErrorString LDAP_P((int)); + #elif MACOS # define tcp_close( s ) tcpclose( s ) # define tcp_read( s, buf, len ) tcpread( s, buf, len ) @@ -112,6 +114,11 @@ # define tcp_close( s ) close( s ) # define tcp_read( s, buf, len) read( s, buf, len ) # define tcp_write( s, buf, len) write( s, buf, len ) + +#ifdef HAVE_PAIR +#define USE_PAIR HAVE_PAIR +#endif + #endif /* MACOS */ #ifndef ioctl_t @@ -121,6 +128,9 @@ #ifndef AC_SOCKET_INVALID # define AC_SOCKET_INVALID (-1) #endif +#ifndef AC_SOCKET_ERROR +# define AC_SOCKET_ERROR (-1) +#endif #if !defined( HAVE_INET_ATON ) && !defined( inet_aton ) #define inet_aton ldap_pvt_inet_aton diff --git a/libraries/liblutil/liblutil.dsp b/libraries/liblutil/liblutil.dsp index 539fc479c0..54800a3eca 100644 --- a/libraries/liblutil/liblutil.dsp +++ b/libraries/liblutil/liblutil.dsp @@ -255,6 +255,10 @@ InputPath=.\slapdmsg.mc # End Source File # Begin Source File +SOURCE=.\sockpair.c +# End Source File +# Begin Source File + SOURCE=.\utils.c # End Source File # End Target diff --git a/libraries/liblutil/sockpair.c b/libraries/liblutil/sockpair.c index f45bdd753c..5c33eb26d7 100644 --- a/libraries/liblutil/sockpair.c +++ b/libraries/liblutil/sockpair.c @@ -25,7 +25,7 @@ int lutil_pair( LBER_SOCKET_T sds[2] ) LBER_SOCKET_T sd; sd = socket( AF_INET, SOCK_DGRAM, 0 ); - if (sd < 0) + if ( sd == AC_SOCKET_INVALID ) return sd; (void) memset( (void*) &si, 0, len ); @@ -33,17 +33,20 @@ int lutil_pair( LBER_SOCKET_T sds[2] ) si.sin_port = 0; si.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); - if ( rc = bind( sd, (struct sockaddr *)&si, len ) ) { + rc = bind( sd, (struct sockaddr *)&si, len ); + if ( rc == AC_SOCKET_ERROR ) { tcp_close(sd); return rc; } - if ( rc = getsockname( sd, (struct sockaddr *)&si, &len ) ) { + rc = getsockname( sd, (struct sockaddr *)&si, &len ); + if ( rc == AC_SOCKET_ERROR ) { tcp_close(sd); return rc; } - if ( rc = connect( sd, (struct sockaddr *)&si, len ) ) { + rc = connect( sd, (struct sockaddr *)&si, len ); + if ( rc == AC_SOCKET_ERROR ) { tcp_close(sd); return rc; } diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index f3edbc4f1b..3b78fd24b9 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -17,6 +17,7 @@ #include "ldap_pvt.h" #include "ldap_defaults.h" +#include "lutil.h" #include "slap.h" #ifdef HAVE_TCPD @@ -263,9 +264,9 @@ open_listener( #ifdef SO_REUSEADDR /* enable address reuse */ tmp = 1; - if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR, - (char *) &tmp, sizeof(tmp) ) == -1 ) - { + rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_REUSEADDR, + (char *) &tmp, sizeof(tmp) ); + if ( rc == AC_SOCKET_ERROR ) { int err = sock_errno(); Debug( LDAP_DEBUG_ANY, "slapd(%ld): setsockopt(SO_REUSEADDR) failed errno=%d (%s)\n", @@ -275,9 +276,9 @@ open_listener( #ifdef SO_KEEPALIVE /* enable keep alives */ tmp = 1; - if ( setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE, - (char *) &tmp, sizeof(tmp) ) == -1 ) - { + rc = setsockopt( l.sl_sd, SOL_SOCKET, SO_KEEPALIVE, + (char *) &tmp, sizeof(tmp) ); + if ( rc == AC_SOCKET_ERROR ) { int err = sock_errno(); Debug( LDAP_DEBUG_ANY, "slapd(%ld): setsockopt(SO_KEEPALIVE) failed errno=%d (%s)\n", @@ -287,9 +288,9 @@ open_listener( #ifdef TCP_NODELAY /* enable no delay */ tmp = 1; - if ( setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY, - (char *)&tmp, sizeof(tmp) ) ) - { + rc = setsockopt( l.sl_sd, IPPROTO_TCP, TCP_NODELAY, + (char *)&tmp, sizeof(tmp) ); + if ( rc == AC_SOCKET_ERROR ) { int err = sock_errno(); Debug( LDAP_DEBUG_ANY, "slapd(%ld): setsockopt(TCP_NODELAY) failed errno=%d (%s)\n", @@ -297,7 +298,8 @@ open_listener( } #endif - if ( bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ) == -1 ) { + rc = bind( l.sl_sd, (struct sockaddr *) &l.sl_addr, sizeof(l.sl_addr) ); + if ( rc == AC_SOCKET_ERROR ) { int err = sock_errno(); Debug( LDAP_DEBUG_ANY, "daemon: bind(%ld) failed errno=%d (%s)\n", (long) l.sl_sd, err, sock_errstr(err) ); @@ -359,8 +361,7 @@ int slapd_daemon_init(char *urls, int port, int tls_port ) * loop will be select'ing on this socket, and will wake up when * this byte arrives. */ - if( (rc = lutil_pair( wake_sds )) < 0 ) - { + if( (rc = lutil_pair( wake_sds )) < 0 ) { Debug( LDAP_DEBUG_ANY, "daemon: lutil_pair() failed rc=%d\n", rc, 0, 0 ); return rc; @@ -961,38 +962,10 @@ int sockdestroy(void) return 0; } -void hit_socket(void) -{ - ber_socket_t s; - int on = 1; - extern struct sockaddr_in bind_addr; - - /* throw something at the socket to terminate the select() in the daemon thread. */ - if (( s = socket( AF_INET, SOCK_STREAM, 0 )) == AC_SOCKET_INVALID ) - Debug( LDAP_DEBUG_ANY, - "slap_set_shutdown: socket failed\n\tWSAGetLastError=%d (%s)\n", - WSAGetLastError(), WSAGetLastErrorString(), 0 ); - - if ( ioctlsocket( s, FIONBIO, &on ) == -1 ) - Debug( LDAP_DEBUG_ANY, - "slap_set_shutdown:FIONBIO ioctl on %d faled\n\tWSAGetLastError=%d (%s)\n", - s, WSAGetLastError(), WSAGetLastError() ); - - bind_addr.sin_addr.s_addr = htonl( INADDR_LOOPBACK ); - - if ( connect( s, (struct sockaddr *)&bind_addr, sizeof( struct sockaddr_in )) == SOCKET_ERROR ) { - Debug( LDAP_DEBUG_ANY, - "hit_socket: error on connect: %d\n", - WSAGetLastError(), 0, 0 ); - /* we can probably expect some error to occur here, mostly WSAEWOULDBLOCK */ - } - - tcp_close(s); -} - #elif HAVE_WINSOCK static int sockinit(void) -{ WSADATA wsaData; +{ + WSADATA wsaData; if ( WSAStartup( 0x0101, &wsaData ) != 0 ) { return -1; } -- 2.39.5