From ff23537bcb84998aa03156c89ee597ca02e86866 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 29 Mar 1999 05:15:59 +0000 Subject: [PATCH] Rework ac/socket.h for HAVE_WINSOCK: tcp_close -> closesocket ioctl -> ioctlsocket Modify codes to use tcp_close() instead of close() for sockets. Modify ioctl codes to be compatible with WINSOCK. --- clients/gopher/go500.c | 4 ++-- clients/gopher/go500gw.c | 6 +++--- include/ac/socket.h | 30 ++++++++++++++---------------- libraries/liblber/sockbuf.c | 5 +++-- libraries/libldap/cldap.c | 4 ++-- servers/ldapd/main.c | 10 +++++----- servers/slapd/daemon.c | 10 +++++----- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/clients/gopher/go500.c b/clients/gopher/go500.c index 1be51161c0..5eca20ad11 100644 --- a/clients/gopher/go500.c +++ b/clients/gopher/go500.c @@ -254,7 +254,7 @@ main( int argc, char **argv ) switch( pid = fork() ) { case 0: /* child */ - close( s ); + tcp_close( s ); do_queries( ns ); break; @@ -263,7 +263,7 @@ main( int argc, char **argv ) break; default: /* parent */ - close( ns ); + tcp_close( ns ); if ( debug ) fprintf( stderr, "forked child %d\n", pid ); break; diff --git a/clients/gopher/go500gw.c b/clients/gopher/go500gw.c index b0c1a65d5b..e03bd4b4f8 100644 --- a/clients/gopher/go500gw.c +++ b/clients/gopher/go500gw.c @@ -243,7 +243,7 @@ main (int argc, char **argv ) do_queries( 0 ); - close( 0 ); + tcp_close( 0 ); exit( 0 ); } @@ -280,7 +280,7 @@ main (int argc, char **argv ) switch( pid = fork() ) { case 0: /* child */ - close( s ); + tcp_close( s ); do_queries( ns ); break; @@ -289,7 +289,7 @@ main (int argc, char **argv ) break; default: /* parent */ - close( ns ); + tcp_close( ns ); if ( debug ) fprintf( stderr, "forked child %d\n", pid ); break; diff --git a/include/ac/socket.h b/include/ac/socket.h index 415f5a265f..466cccd442 100644 --- a/include/ac/socket.h +++ b/include/ac/socket.h @@ -63,22 +63,20 @@ #define MAXHOSTNAMELEN 64 #endif -#ifdef MACOS -#define tcp_close( s ) tcpclose( s ) -#else /* MACOS */ -#ifdef DOS -#ifdef PCNFS -#define tcp_close( s ) close( s ) -#endif /* PCNFS */ -#ifdef NCSA -#define tcp_close( s ) netclose( s ); netshut() -#endif /* NCSA */ -#ifdef WINSOCK -#define tcp_close( s ) closesocket( s ); -#endif /* WINSOCK */ -#else /* DOS */ -#define tcp_close( s ) close( s ) -#endif /* DOS */ +#ifdef HAVE_WINSOCK +# define tcp_close( s ) closesocket( s ); +# define ioctl( s, c, a ) ioctlsocket( (s), (c), (a) ) +#elif MACOS +# define tcp_close( s ) tcpclose( s ) +#elif DOS +# ifdef PCNFS +# define tcp_close( s ) close( s ) +# endif /* PCNFS */ +# ifdef NCSA +# define tcp_close( s ) do { netclose( s ); netshut() } while(0) +# endif /* NCSA */ +#else +# define tcp_close( s ) close( s ) #endif /* MACOS */ #if !defined(__alpha) || defined(VMS) diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c index d07926e08e..1b4adad44d 100644 --- a/libraries/liblber/sockbuf.c +++ b/libraries/liblber/sockbuf.c @@ -579,8 +579,9 @@ int lber_pvt_sb_set_nonblock( Sockbuf *sb, int nb ) } #ifdef FIONBIO if (lber_pvt_sb_in_use(sb)) { - int status = (nb!=0); - if (ioctl( lber_pvt_sb_get_desc(sb), FIONBIO, (caddr_t)&status ) == -1 ) { + /* WINSOCK requires the status to be a long */ + u_long status = (nb!=0); + if (ioctl( lber_pvt_sb_get_desc(sb), FIONBIO, &status ) == -1 ) { return -1; } } diff --git a/libraries/libldap/cldap.c b/libraries/libldap/cldap.c index 55f1be4fb9..126e1695b4 100644 --- a/libraries/libldap/cldap.c +++ b/libraries/libldap/cldap.c @@ -81,11 +81,11 @@ cldap_open( char *host, int port ) sock.sin_family = AF_INET; sock.sin_port = 0; if ( bind(s, (struct sockaddr *) &sock, sizeof(sock)) < 0) { - close( s ); + tcp_close( s ); return( NULL ); } if (( ld = ldap_init( host, port )) == NULL ) { - close( s ); + tcp_close( s ); return( NULL ); } diff --git a/servers/ldapd/main.c b/servers/ldapd/main.c index 5e91ec6ea3..3f0e3d3580 100644 --- a/servers/ldapd/main.c +++ b/servers/ldapd/main.c @@ -418,7 +418,7 @@ main( int argc, char **argv ) inet_ntoa( from.sin_addr ) ); } - close(ns); + tcp_close(ns); continue; } #endif /* TCP_WRAPPERS */ @@ -436,7 +436,7 @@ main( int argc, char **argv ) #ifdef VMS /* This is for debug on terminal on VMS */ - close( tcps ); + tcp_close( tcps ); #ifdef LDAP_PROCTITLE setproctitle( hp == NULL ? inet_ntoa( from.sin_addr ) : hp->h_name ); @@ -450,7 +450,7 @@ main( int argc, char **argv ) switch( pid = fork() ) { case 0: /* child */ - close( tcps ); + tcp_close( tcps ); #ifdef LDAP_PROCTITLE sprintf( title, "%s (%d)\n", hp == NULL ? inet_ntoa( from.sin_addr ) : hp->h_name, @@ -467,14 +467,14 @@ main( int argc, char **argv ) #ifdef LDAP_DEBUG if ( ldap_debug ) perror( "fork" ); #endif - close( ns ); + tcp_close( ns ); syslog( LOG_ERR, "fork failed %m" ); /* let things cool off */ sleep( 15 ); break; default: /* parent */ - close( ns ); + tcp_close( ns ); Debug( LDAP_DEBUG_TRACE, "forked child %d\n", pid, 0, 0 ); break; diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index 58954d3026..0f3c859860 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -149,7 +149,7 @@ static void slapd_close(int s) { slapd_remove(s); Debug( LDAP_DEBUG_CONNS, "daemon: closing %d\n", s, 0, 0 ); - close(s); + tcp_close(s); } static void * @@ -357,7 +357,7 @@ slapd_daemon_task( Debug( LDAP_DEBUG_ANY, "daemon: %d beyond descriptor table size %d\n", s, dtblsize, 0 ); - close(s); + tcp_close(s); continue; } #endif @@ -409,7 +409,7 @@ slapd_daemon_task( client_addr == NULL ? "unknown" : client_addr, 0, 0 ); - close(s); + tcp_close(s); continue; } #endif /* HAVE_TCPD */ @@ -420,7 +420,7 @@ slapd_daemon_task( s, client_name == NULL ? "unknown" : client_name, client_addr == NULL ? "unknown" : client_addr); - close(s); + tcp_close(s); continue; } @@ -510,7 +510,7 @@ slapd_daemon_task( } if( tcps >= 0 ) { - close( tcps ); + tcp_close( tcps ); } ldap_pvt_thread_mutex_lock( &active_threads_mutex ); -- 2.39.5