From 7275861039abe6f1284923eea43aa5b6ec196d3f Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 4 Aug 1999 18:29:59 +0000 Subject: [PATCH] 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. --- libraries/liblber/lber-int.h | 2 ++ libraries/liblber/sockbuf.c | 35 ++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 13 deletions(-) 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 -- 2.39.5