From f0bd9b3a5b51e40fbcd894c1ef75075b440226b4 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Fri, 9 Jul 2004 17:50:22 +0000 Subject: [PATCH] Mark areas needed poll(2) support with HAVE_POLL. --- libraries/libldap/init.c | 6 ++-- libraries/libldap/ldap-int.h | 5 +++- libraries/libldap/os-ip.c | 40 +++++++++++++++++++------- libraries/libldap/os-local.c | 55 ++++++++++++++++++------------------ libraries/libldap/request.c | 3 +- 5 files changed, 66 insertions(+), 43 deletions(-) diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c index f20223294a..03e55c85cf 100644 --- a/libraries/libldap/init.c +++ b/libraries/libldap/init.c @@ -534,8 +534,10 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl ) || defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL) ldap_int_hostname = ldap_pvt_get_fqdn( ldap_int_hostname ); #endif - if ( ldap_int_tblsize == 0 ) - ldap_int_ip_init(); + +#ifndef HAVE_POLL + if ( ldap_int_tblsize == 0 ) ldap_int_ip_init(); +#endif ldap_int_initialize_global_options(gopts, NULL); diff --git a/libraries/libldap/ldap-int.h b/libraries/libldap/ldap-int.h index 7d0c6fdb19..73b0aa999d 100644 --- a/libraries/libldap/ldap-int.h +++ b/libraries/libldap/ldap-int.h @@ -448,7 +448,11 @@ LDAP_F (int) ldap_int_open_connection( LDAP *ld, /* * in os-ip.c */ +#ifndef HAVE_POLL LDAP_V (int) ldap_int_tblsize; +LDAP_F (void) ldap_int_ip_init( void ); +#endif + LDAP_F (int) ldap_int_timeval_dup( struct timeval **dest, const struct timeval *tm ); LDAP_F (int) ldap_connect_to_host( LDAP *ld, Sockbuf *sb, @@ -461,7 +465,6 @@ LDAP_F (char *) ldap_host_connected_to( Sockbuf *sb, const char *host ); #endif -LDAP_F (void) ldap_int_ip_init( void ); LDAP_F (int) ldap_int_select( LDAP *ld, struct timeval *timeout ); LDAP_F (void *) ldap_new_select_info( void ); LDAP_F (void) ldap_free_select_info( void *sip ); diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index 1b3b515810..7399fe5bd2 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -39,8 +39,6 @@ #include "ldap-int.h" -int ldap_int_tblsize = 0; - #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP ) # ifdef LDAP_PF_INET6 int ldap_int_inet4or6 = AF_UNSPEC; @@ -212,10 +210,12 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, { int rc; struct timeval tv, *opt_tv=NULL; +#ifndef HAVE_POLL fd_set wfds, *z=NULL; #ifdef HAVE_WINSOCK fd_set efds; #endif +#endif #ifdef LDAP_CONNECTIONLESS /* We could do a connect() but that would interfere with @@ -258,6 +258,9 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, if ( async ) return ( -2 ); #endif +#ifdef HAVE_POLL + assert(0); +#else FD_ZERO(&wfds); FD_SET(s, &wfds ); @@ -305,6 +308,8 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, return ( -1 ); return ( 0 ); } +#endif + osip_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0); ldap_pvt_set_errno( ETIMEDOUT ); return ( -1 ); @@ -607,14 +612,18 @@ ldap_host_connected_to( Sockbuf *sb, const char *host ) #endif -/* for UNIX */ +#ifdef HAVE_POLL +/* for UNIX poll(2) */ + /* ??? */ +#else +/* for UNIX select(2) */ struct selectinfo { fd_set si_readfds; fd_set si_writefds; fd_set si_use_readfds; fd_set si_use_writefds; }; - +#endif void ldap_mark_select_write( LDAP *ld, Sockbuf *sb ) @@ -708,10 +717,14 @@ ldap_free_select_info( void *sip ) } +#ifndef HAVE_POLL +int ldap_int_tblsize = 0; + void ldap_int_ip_init( void ) { int tblsize; + #if defined( HAVE_SYSCONF ) tblsize = sysconf( _SC_OPEN_MAX ); #elif defined( HAVE_GETDTABLESIZE ) @@ -721,11 +734,12 @@ ldap_int_ip_init( void ) #endif /* !USE_SYSCONF */ #ifdef FD_SETSIZE - if( tblsize > FD_SETSIZE ) - tblsize = FD_SETSIZE; + if( tblsize > FD_SETSIZE ) tblsize = FD_SETSIZE; #endif /* FD_SETSIZE*/ + ldap_int_tblsize = tblsize; } +#endif int @@ -739,14 +753,20 @@ ldap_int_select( LDAP *ld, struct timeval *timeout ) Debug( LDAP_DEBUG_TRACE, "ldap_int_select\n", 0, 0, 0 ); #endif - if ( ldap_int_tblsize == 0 ) - ldap_int_ip_init(); +#ifndef HAVE_POLL + if ( ldap_int_tblsize == 0 ) ldap_int_ip_init(); +#endif sip = (struct selectinfo *)ld->ld_selectinfo; sip->si_use_readfds = sip->si_readfds; sip->si_use_writefds = sip->si_writefds; +#ifdef HAVE_POLL + assert(0); + return -1; +#else return( select( ldap_int_tblsize, - &sip->si_use_readfds, &sip->si_use_writefds, - NULL, timeout )); + &sip->si_use_readfds, &sip->si_use_writefds, + NULL, timeout )); +#endif } diff --git a/libraries/libldap/os-local.c b/libraries/libldap/os-local.c index 6cbc8a10c2..43d55f513d 100644 --- a/libraries/libldap/os-local.c +++ b/libraries/libldap/os-local.c @@ -51,8 +51,6 @@ #include "ldap-int.h" #include "ldap_defaults.h" -/* int ldap_int_tblsize = 0; */ - #ifdef LDAP_DEBUG #define oslocal_debug(ld,fmt,arg1,arg2,arg3) \ @@ -169,7 +167,6 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) { int rc; struct timeval tv, *opt_tv=NULL; - fd_set wfds, *z=NULL; if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) { tv.tv_usec = opt_tv->tv_usec; @@ -177,17 +174,15 @@ ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async) } oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n", - s, opt_tv ? tv.tv_sec : -1L, async); + s, opt_tv ? tv.tv_sec : -1L, async); - if ( ldap_pvt_ndelay_on(ld, s) == -1 ) - return ( -1 ); + if ( ldap_pvt_ndelay_on(ld, s) == -1 ) return -1; if ( connect(s, (struct sockaddr *) sa, sizeof(struct sockaddr_un)) != AC_SOCKET_ERROR ) { - if ( ldap_pvt_ndelay_off(ld, s) == -1 ) { - return ( -1 ); - } + if ( ldap_pvt_ndelay_off(ld, s) == -1 ) return -1; + #ifdef DO_SENDMSG /* Send a dummy message with access rights. Remote side will * obtain our uid/gid by fstat'ing this descriptor. @@ -211,38 +206,42 @@ sendcred: } } #endif - return ( 0 ); + return 0; } - if ( errno != EINPROGRESS && errno != EWOULDBLOCK ) { - return ( -1 ); - } + if ( errno != EINPROGRESS && errno != EWOULDBLOCK ) return -1; #ifdef notyet - if ( async ) return ( -2 ); + if ( async ) return -2; #endif - FD_ZERO(&wfds); - FD_SET(s, &wfds ); +#ifdef HAVE_POLL + assert(0); +#else + { + fd_set wfds, *z=NULL; + FD_ZERO(&wfds); + FD_SET(s, &wfds ); - do { - rc = select(ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL); - } while( rc == AC_SOCKET_ERROR && errno == EINTR && - LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART )); + do { + rc = select( ldap_int_tblsize, z, &wfds, z, opt_tv ? &tv : NULL ); + } while( rc == AC_SOCKET_ERROR && errno == EINTR && + LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART )); - if( rc == AC_SOCKET_ERROR ) return rc; + if( rc == AC_SOCKET_ERROR ) return rc; - if ( FD_ISSET(s, &wfds) ) { - if ( ldap_pvt_is_socket_ready(ld, s) == -1 ) - return ( -1 ); - if ( ldap_pvt_ndelay_off(ld, s) == -1 ) - return ( -1 ); + if ( FD_ISSET(s, &wfds) ) { + if ( ldap_pvt_is_socket_ready(ld, s) == -1 ) return -1; + if ( ldap_pvt_ndelay_off(ld, s) == -1 ) return -1; #ifdef DO_SENDMSG - goto sendcred; + goto sendcred; #else - return ( 0 ); + return ( 0 ); #endif + } } +#endif + oslocal_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0); ldap_pvt_set_errno( ETIMEDOUT ); return ( -1 ); diff --git a/libraries/libldap/request.c b/libraries/libldap/request.c index 237a6eefff..1187e28fae 100644 --- a/libraries/libldap/request.c +++ b/libraries/libldap/request.c @@ -158,8 +158,7 @@ ldap_send_initial_request( int ldap_int_flush_request( LDAP *ld, - LDAPRequest *lr -) + LDAPRequest *lr ) { LDAPConn *lc = lr->lr_conn; -- 2.39.5