Skip to content
Snippets Groups Projects
Commit 72758610 authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

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.
parent bd9323ef
No related branches found
No related tags found
No related merge requests found
......@@ -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 */
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment