From: Kurt Zeilenga Date: Wed, 4 Aug 1999 18:29:59 +0000 (+0000) Subject: Provide set_nonblock code which acts upon ber_socket_t and use this X-Git-Tag: TWEB_OL_BASE~289 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7275861039abe6f1284923eea43aa5b6ec196d3f;p=openldap Provide set_nonblock code which acts upon ber_socket_t and use this as in sockbuf_set_nonblock code. Allows -llber and -lldap to share a common implementation. --- diff --git a/libraries/liblber/lber-int.h b/libraries/liblber/lber-int.h index ff5a1577eb..b65553571d 100644 --- a/libraries/liblber/lber-int.h +++ b/libraries/liblber/lber-int.h @@ -270,5 +270,7 @@ ber_pvt_sb_udp_set_dst LDAP_P((Sockbuf *sb, void *addr )); LDAP_F( void * ) ber_pvt_sb_udp_get_src LDAP_P((Sockbuf *sb )); +LDAP_F( int ) +ber_pvt_socket_set_nonblock LDAP_P(( ber_socket_t sd, int nb )); #endif /* _LBER_INT_H */ diff --git a/libraries/liblber/sockbuf.c b/libraries/liblber/sockbuf.c index b81235b946..52b3204081 100644 --- a/libraries/liblber/sockbuf.c +++ b/libraries/liblber/sockbuf.c @@ -644,6 +644,23 @@ int ber_pvt_sb_set_readahead( Sockbuf *sb, int rh ) return 0; } +int ber_pvt_socket_set_nonblock( ber_socket_t sd, int nb ) +{ +#if HAVE_FCNTL + int flags = fcntl(ber_pvt_sb_get_desc(sb), F_GETFL); + if( nb ) { + flags |= O_NONBLOCK; + } else { + flags &= ~O_NONBLOCK; + } + return fcntl( ber_pvt_sb_get_desc(sb), F_SETFL, flags ); + +#elif defined( FIONBIO ) + ioctl_t status = nb ? 1 : 0; + return ioctl( sd, FIONBIO, &status ); +#endif +} + #define USE_NONBLOCK #ifdef USE_NONBLOCK int ber_pvt_sb_set_nonblock( Sockbuf *sb, int nb ) @@ -662,19 +679,11 @@ int ber_pvt_sb_set_nonblock( Sockbuf *sb, int nb ) sb->sb_read_ahead = 0; #endif } - if (ber_pvt_sb_in_use(sb)) { -#if HAVE_FCNTL - int flags = fcntl(ber_pvt_sb_get_desc(sb), F_GETFL); - flags |= O_NONBLOCK; - return fcntl(ber_pvt_sb_get_desc(sb), F_SETFL, flags); - -#elif defined( FIONBIO ) - /* WINSOCK requires the status to be a long */ - ioctl_t status = (nb!=0); - return ioctl( ber_pvt_sb_get_desc(sb), FIONBIO, &status ); -#endif /* FIONBIO */ - } - return 0; + if (ber_pvt_sb_in_use(sb)) { + return ber_pvt_socket_set_nonblock( + ber_pvt_sb_get_desc(sb), nb ); + } + return 0; } #endif