Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
os-ip.c File Reference
#include "ldap-int.h"
#include <poll.h>

Go to the source code of this file.

Classes

struct  nsldapi_os_statusinfo
struct  nsldapi_cb_statusinfo
struct  nsldapi_iostatus_info
struct  nsldapi_compat_socket_info
union  nsldapi_iostatus_info.ios_status

Defines

#define NSLDAPI_INVALID_OS_SOCKET(s)   ((s) < 0 )
#define NSLDAPI_POLL_ARRAY_GROWTH   5 /* grow arrays 5 elements at a time */
#define NSLDAPI_CB_POLL_SD_CAST
#define NSLDAPI_CB_POLL_MATCH(sbp, pollfd)
#define NSLDAPI_IOSTATUS_TYPE_OSNATIVE   1 /* poll() or select() */
#define NSLDAPI_IOSTATUS_TYPE_CALLBACK   2 /* poll()-like */
#define NSLDAPI_POLL   poll
#define NSLDAPI_SELECT   select

Typedefs

typedef LBER_SOCKETNSLDAPI_SOCKET_FN )(LDAP *ld, int secure, int domain, int type, int protocol)
typedef intNSLDAPI_IOCTL_FN )(LBER_SOCKET s, int option, int *statusp)
typedef intNSLDAPI_CONNECT_WITH_TO_FN )(LBER_SOCKET s, struct sockaddr *name, int namelen, int msec_timeout)
typedef intNSLDAPI_CONNECT_FN )(LBER_SOCKET s, struct sockaddr *name, int namelen)
typedef intNSLDAPI_CLOSE_FN )(LBER_SOCKET s)
typedef struct
nsldapi_compat_socket_info 
NSLDAPICompatSocketInfo

Functions

static int nsldapi_add_to_os_pollfds (int fd, struct nsldapi_os_statusinfo *pip, short events)
static int nsldapi_clear_from_os_pollfds (int fd, struct nsldapi_os_statusinfo *pip, short events)
static int nsldapi_find_in_os_pollfds (int fd, struct nsldapi_os_statusinfo *pip, short revents)
static int nsldapi_iostatus_init_nolock (LDAP *ld)
static int nsldapi_add_to_cb_pollfds (Sockbuf *sb, struct nsldapi_cb_statusinfo *pip, short events)
static int nsldapi_clear_from_cb_pollfds (Sockbuf *sb, struct nsldapi_cb_statusinfo *pip, short events)
static int nsldapi_find_in_cb_pollfds (Sockbuf *sb, struct nsldapi_cb_statusinfo *pip, short revents)
static LBER_SOCKET nsldapi_os_socket (LDAP *ld, int secure, int domain, int type, int protocol)
static int nsldapi_os_ioctl (LBER_SOCKET s, int option, int *statusp)
static int nsldapi_os_connect_with_to (LBER_SOCKET s, struct sockaddr *name, int namelen, int msec_timeout)
static int nsldapi_try_each_host (LDAP *ld, const char *hostlist, int defport, int secure, NSLDAPI_SOCKET_FN *socketfn, NSLDAPI_IOCTL_FN *ioctlfn, NSLDAPI_CONNECT_WITH_TO_FN *connectwithtofn, NSLDAPI_CONNECT_FN *connectfn, NSLDAPI_CLOSE_FN *closefn)
static int nsldapi_os_closesocket (LBER_SOCKET s)
int nsldapi_connect_to_host (LDAP *ld, Sockbuf *sb, const char *hostlist, int defport, int secure, char **krbinstancep)
void nsldapi_close_connection (LDAP *ld, Sockbuf *sb)
int nsldapi_iostatus_interest_write (LDAP *ld, Sockbuf *sb)
int nsldapi_iostatus_interest_read (LDAP *ld, Sockbuf *sb)
int nsldapi_iostatus_interest_clear (LDAP *ld, Sockbuf *sb)
int nsldapi_iostatus_is_write_ready (LDAP *ld, Sockbuf *sb)
int nsldapi_iostatus_is_read_ready (LDAP *ld, Sockbuf *sb)
void nsldapi_iostatus_free (LDAP *ld)
static int nsldapi_tv2ms (struct timeval *tv)
int nsldapi_iostatus_poll (LDAP *ld, struct timeval *timeout)
int nsldapi_install_lber_extiofns (LDAP *ld, Sockbuf *sb)
static int LDAP_CALLBACK nsldapi_ext_compat_read (int s, void *buf, int len, struct lextiof_socket_private *arg)
static int LDAP_CALLBACK nsldapi_ext_compat_write (int s, const void *buf, int len, struct lextiof_socket_private *arg)
static int LDAP_CALLBACK nsldapi_ext_compat_poll (LDAP_X_PollFD fds[], int nfds, int timeout, struct lextiof_session_private *arg)
static LBER_SOCKET nsldapi_compat_socket (LDAP *ld, int secure, int domain, int type, int protocol)
static int LDAP_CALLBACK nsldapi_ext_compat_connect (const char *hostlist, int defport, int timeout, unsigned long options, struct lextiof_session_private *sessionarg, struct lextiof_socket_private **socketargp)
static int LDAP_CALLBACK nsldapi_ext_compat_close (int s, struct lextiof_socket_private *arg)
int nsldapi_install_compat_io_fns (LDAP *ld, struct ldap_io_fns *iofns)

Class Documentation

struct nsldapi_os_statusinfo

Definition at line 91 of file os-ip.c.

Collaboration diagram for nsldapi_os_statusinfo:
Class Members
struct pollfd * ossi_pollfds
int ossi_pollfds_size
struct nsldapi_cb_statusinfo

Definition at line 104 of file os-ip.c.

Collaboration diagram for nsldapi_cb_statusinfo:
Class Members
LDAP_X_PollFD * cbsi_pollfds
int cbsi_pollfds_size
struct nsldapi_iostatus_info

Definition at line 123 of file os-ip.c.

Collaboration diagram for nsldapi_iostatus_info:
Class Members
int ios_read_count
union nsldapi_iostatus_info ios_status
int ios_type
int ios_write_count
struct nsldapi_compat_socket_info

Definition at line 1551 of file os-ip.c.

Class Members
LDAP * csi_ld
LBER_SOCKET csi_socket
union nsldapi_iostatus_info.ios_status

Definition at line 129 of file os-ip.c.


Define Documentation

#define NSLDAPI_CB_POLL_MATCH (   sbp,
  pollfd 
)
Value:
((sbp)->sb_sd == NSLDAPI_CB_POLL_SD_CAST ((pollfd).lpoll_fd) && \
    (sbp)->sb_ext_io_fns.lbextiofn_socket_arg == (pollfd).lpoll_socketarg)

Definition at line 118 of file os-ip.c.

Definition at line 116 of file os-ip.c.

#define NSLDAPI_INVALID_OS_SOCKET (   s)    ((s) < 0 )

Definition at line 80 of file os-ip.c.

#define NSLDAPI_IOSTATUS_TYPE_CALLBACK   2 /* poll()-like */

Definition at line 126 of file os-ip.c.

#define NSLDAPI_IOSTATUS_TYPE_OSNATIVE   1 /* poll() or select() */

Definition at line 125 of file os-ip.c.

#define NSLDAPI_POLL   poll

Definition at line 172 of file os-ip.c.

#define NSLDAPI_POLL_ARRAY_GROWTH   5 /* grow arrays 5 elements at a time */

Definition at line 84 of file os-ip.c.

Definition at line 173 of file os-ip.c.


Typedef Documentation

Definition at line 193 of file os-ip.c.

Definition at line 191 of file os-ip.c.

typedef int( NSLDAPI_CONNECT_WITH_TO_FN)(LBER_SOCKET s, struct sockaddr *name, int namelen, int msec_timeout)

Definition at line 189 of file os-ip.c.

Definition at line 188 of file os-ip.c.

Definition at line 186 of file os-ip.c.


Function Documentation

static int nsldapi_add_to_cb_pollfds ( Sockbuf *  sb,
struct nsldapi_cb_statusinfo pip,
short  events 
) [static]

Definition at line 1396 of file os-ip.c.

{
       int    i, openslot;

       /* first we check to see if "sb" is already in our pollfds */
       openslot = -1;
       for ( i = 0; i < pip->cbsi_pollfds_size; ++i ) {
              if ( NSLDAPI_CB_POLL_MATCH( sb, pip->cbsi_pollfds[ i ] )) {
                     if (( pip->cbsi_pollfds[ i ].lpoll_events & events )
                         != events ) {
                            pip->cbsi_pollfds[ i ].lpoll_events |= events;
                            return( 1 );
                     } else {
                            return( 0 );
                     }
              }
              if ( pip->cbsi_pollfds[ i ].lpoll_fd == -1 && openslot == -1 ) {
                     openslot = i; /* remember for later */
              }
       }

       /*
        * "sb" is not currently being poll'd on -- add to array.
        * if we need to expand the pollfds array, we do it in increments of
        * NSLDAPI_POLL_ARRAY_GROWTH (#define near the top of this file).
        */
       if ( openslot == -1 ) {
              LDAP_X_PollFD *newpollfds;

              if ( pip->cbsi_pollfds_size == 0 ) {
                     newpollfds = (LDAP_X_PollFD *)NSLDAPI_MALLOC(
                         NSLDAPI_POLL_ARRAY_GROWTH
                         * sizeof( LDAP_X_PollFD ));
              } else {
                     newpollfds = (LDAP_X_PollFD *)NSLDAPI_REALLOC(
                         pip->cbsi_pollfds, (NSLDAPI_POLL_ARRAY_GROWTH
                         + pip->cbsi_pollfds_size)
                         * sizeof( LDAP_X_PollFD ));
              }
              if ( newpollfds == NULL ) { /* XXXmcs: no way to return err! */
                     return( 0 );
              }
              pip->cbsi_pollfds = newpollfds;
              openslot = pip->cbsi_pollfds_size;
              pip->cbsi_pollfds_size += NSLDAPI_POLL_ARRAY_GROWTH;
              for ( i = openslot + 1; i < pip->cbsi_pollfds_size; ++i ) {
                     pip->cbsi_pollfds[ i ].lpoll_fd = -1;
                     pip->cbsi_pollfds[ i ].lpoll_socketarg = NULL;
                     pip->cbsi_pollfds[ i ].lpoll_events =
                         pip->cbsi_pollfds[ i ].lpoll_revents = 0;
              }
       }
       pip->cbsi_pollfds[ openslot ].lpoll_fd = sb->sb_sd;
       pip->cbsi_pollfds[ openslot ].lpoll_socketarg =
           sb->sb_ext_io_fns.lbextiofn_socket_arg;
       pip->cbsi_pollfds[ openslot ].lpoll_events = events;
       pip->cbsi_pollfds[ openslot ].lpoll_revents = 0;
       return( 1 );
}

Here is the caller graph for this function:

static int nsldapi_add_to_os_pollfds ( int  fd,
struct nsldapi_os_statusinfo pip,
short  events 
) [static]

Definition at line 1279 of file os-ip.c.

{
       int    i, openslot;

       /* first we check to see if "fd" is already in our pollfds */
       openslot = -1;
       for ( i = 0; i < pip->ossi_pollfds_size; ++i ) {
              if ( pip->ossi_pollfds[ i ].fd == fd ) {
                     if (( pip->ossi_pollfds[ i ].events & events )
                         != events ) {
                            pip->ossi_pollfds[ i ].events |= events;
                            return( 1 );
                     } else {
                            return( 0 );
                     }
              }
              if ( pip->ossi_pollfds[ i ].fd == -1 && openslot == -1 ) {
                     openslot = i; /* remember for later */
              }
       }

       /*
        * "fd" is not currently being poll'd on -- add to array.
        * if we need to expand the pollfds array, we do it in increments of
        * NSLDAPI_POLL_ARRAY_GROWTH (#define near the top of this file).
        */
       if ( openslot == -1 ) {
              struct pollfd *newpollfds;

              if ( pip->ossi_pollfds_size == 0 ) {
                     newpollfds = (struct pollfd *)NSLDAPI_MALLOC(
                         NSLDAPI_POLL_ARRAY_GROWTH
                         * sizeof( struct pollfd ));
              } else {
                     newpollfds = (struct pollfd *)NSLDAPI_REALLOC(
                         pip->ossi_pollfds, (NSLDAPI_POLL_ARRAY_GROWTH
                         + pip->ossi_pollfds_size)
                         * sizeof( struct pollfd ));
              }
              if ( newpollfds == NULL ) { /* XXXmcs: no way to return err! */
                     return( 0 );
              }
              pip->ossi_pollfds = newpollfds;
              openslot = pip->ossi_pollfds_size;
              pip->ossi_pollfds_size += NSLDAPI_POLL_ARRAY_GROWTH;
              for ( i = openslot + 1; i < pip->ossi_pollfds_size; ++i ) {
                     pip->ossi_pollfds[ i ].fd = -1;
                     pip->ossi_pollfds[ i ].events =
                         pip->ossi_pollfds[ i ].revents = 0;
              }
       }
       pip->ossi_pollfds[ openslot ].fd = fd;
       pip->ossi_pollfds[ openslot ].events = events;
       pip->ossi_pollfds[ openslot ].revents = 0;
       return( 1 );
}

Here is the caller graph for this function:

static int nsldapi_clear_from_cb_pollfds ( Sockbuf *  sb,
struct nsldapi_cb_statusinfo pip,
short  events 
) [static]

Definition at line 1463 of file os-ip.c.

{
       int    i;

       for ( i = 0; i < pip->cbsi_pollfds_size; ++i ) {
              if ( NSLDAPI_CB_POLL_MATCH( sb, pip->cbsi_pollfds[ i ] )) {
                     if (( pip->cbsi_pollfds[ i ].lpoll_events
                         & events ) != 0 ) {
                            pip->cbsi_pollfds[ i ].lpoll_events &= ~events;
                            if ( pip->cbsi_pollfds[ i ].lpoll_events
                                == 0 ) {
                                   pip->cbsi_pollfds[i].lpoll_fd = -1;
                            }
                            return( 1 );  /* events overlap */
                     } else {
                            return( 0 );  /* events do not overlap */
                     }
              }
       }

       return( 0 );  /* "sb" was not found */
}

Here is the caller graph for this function:

static int nsldapi_clear_from_os_pollfds ( int  fd,
struct nsldapi_os_statusinfo pip,
short  events 
) [static]

Definition at line 1343 of file os-ip.c.

{
       int    i;

       for ( i = 0; i < pip->ossi_pollfds_size; ++i ) {
              if ( pip->ossi_pollfds[i].fd == fd ) {
                     if (( pip->ossi_pollfds[ i ].events & events ) != 0 ) {
                            pip->ossi_pollfds[ i ].events &= ~events;
                            if ( pip->ossi_pollfds[ i ].events == 0 ) {
                                   pip->ossi_pollfds[i].fd = -1;
                            }
                            return( 1 );  /* events overlap */
                     } else {
                            return( 0 );  /* events do not overlap */
                     }
              }
       }

       return( 0 );  /* "fd" was not found */
}

Here is the caller graph for this function:

void nsldapi_close_connection ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 752 of file os-ip.c.

{
       if ( ld->ld_extclose_fn == NULL ) {
#ifndef NSLDAPI_AVOID_OS_SOCKETS
              nsldapi_os_closesocket( sb->sb_sd );
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
       } else {
              ld->ld_extclose_fn( sb->sb_sd,
                         sb->sb_ext_io_fns.lbextiofn_socket_arg );
       }
}

Here is the call graph for this function:

static LBER_SOCKET nsldapi_compat_socket ( LDAP *  ld,
int  secure,
int  domain,
int  type,
int  protocol 
) [static]

Definition at line 1660 of file os-ip.c.

{
       int           s;

       s = ld->ld_io_fns_ptr->liof_socket( domain, type, protocol );

       if ( s >= 0 ) {
              char                        *errmsg = NULL;

#ifdef NSLDAPI_HAVE_POLL
              if ( ld->ld_io_fns_ptr->liof_select != NULL
                         && s >= FD_SETSIZE ) {
                     errmsg = "can't use socket >= FD_SETSIZE";
              }
#elif !defined(_WINDOWS) /* not on Windows and do not have poll() */
              if ( s >= FD_SETSIZE ) {
                     errmsg = "can't use socket >= FD_SETSIZE";
              }
#endif

              if ( NULL == errmsg && secure &&
                         ld->ld_io_fns_ptr->liof_ssl_enable( s ) < 0 ) {
                     errmsg = "failed to enable secure mode";
                  }

              if ( NULL != errmsg ) {
                     if ( NULL == ld->ld_io_fns_ptr->liof_close ) {
                            nsldapi_os_closesocket( s );
                     } else {
                            ld->ld_io_fns_ptr->liof_close( s );
                     }
                     LDAP_SET_LDERRNO( ld, LDAP_LOCAL_ERROR, NULL,
                                nsldapi_strdup( errmsg ));
                     return( -1 );
              }
       }

       return( s );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_connect_to_host ( LDAP *  ld,
Sockbuf *  sb,
const char *  hostlist,
int  defport,
int  secure,
char **  krbinstancep 
)

Definition at line 479 of file os-ip.c.

{
       int           s;

       LDAPDebug( LDAP_DEBUG_TRACE, "nsldapi_connect_to_host: %s, port: %d\n",
           NULL == hostlist ? "NULL" : hostlist, defport, 0 );

       /*
        * If an extended I/O connect callback has been defined, just use it.
        */
       if ( NULL != ld->ld_extconnect_fn ) {
              unsigned long connect_opts = 0;

              if ( ld->ld_options & LDAP_BITOPT_ASYNC) {
                     connect_opts |= LDAP_X_EXTIOF_OPT_NONBLOCKING;
              }
              if ( secure ) {
                     connect_opts |= LDAP_X_EXTIOF_OPT_SECURE;
              }
              s = ld->ld_extconnect_fn( hostlist, defport,
                  ld->ld_connect_timeout, connect_opts,
                  ld->ld_ext_session_arg,
                  &sb->sb_ext_io_fns.lbextiofn_socket_arg );

       } else {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return( -1 );
#else /* NSLDAPI_AVOID_OS_SOCKETS */
              s = nsldapi_try_each_host( ld, hostlist,
                     defport, secure, nsldapi_os_socket,
                     nsldapi_os_ioctl, nsldapi_os_connect_with_to,
                     NULL, nsldapi_os_closesocket );
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
       }

       if ( s < 0 ) {
              LDAP_SET_LDERRNO( ld, LDAP_CONNECT_ERROR, NULL, NULL );
              return( -1 );
       }

       sb->sb_sd = s;

       /*
        * Set krbinstancep (canonical name of host for use by Kerberos).
        */
#ifdef KERBEROS
       char   *p;

       if (( *krbinstancep = nsldapi_host_connected_to( sb )) != NULL
           && ( p = strchr( *krbinstancep, '.' )) != NULL ) {
              *p = '\0';
       }
#else /* KERBEROS */
       *krbinstancep = NULL;
#endif /* KERBEROS */

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int LDAP_CALLBACK nsldapi_ext_compat_close ( int  s,
struct lextiof_socket_private arg 
) [static]

Definition at line 1782 of file os-ip.c.

{
       NSLDAPICompatSocketInfo     *csip = (NSLDAPICompatSocketInfo *)arg;
       struct ldap_io_fns   *iofns = csip->csi_ld->ld_io_fns_ptr;
       int                  rc;

       rc = iofns->liof_close( csip->csi_socket );

       NSLDAPI_FREE( csip );

       return( rc );
}

Here is the caller graph for this function:

static int LDAP_CALLBACK nsldapi_ext_compat_connect ( const char *  hostlist,
int  defport,
int  timeout,
unsigned long  options,
struct lextiof_session_private sessionarg,
struct lextiof_socket_private **  socketargp 
) [static]

Definition at line 1707 of file os-ip.c.

{
       NSLDAPICompatSocketInfo            *defcsip;
       struct ldap_io_fns          *iofns;
       int                         s, secure;
       NSLDAPI_SOCKET_FN           *socketfn;
       NSLDAPI_IOCTL_FN            *ioctlfn;
       NSLDAPI_CONNECT_WITH_TO_FN  *connectwithtofn;
       NSLDAPI_CONNECT_FN          *connectfn;
       NSLDAPI_CLOSE_FN            *closefn;

       defcsip = (NSLDAPICompatSocketInfo *)sessionarg;
       iofns = defcsip->csi_ld->ld_io_fns_ptr;

       if ( 0 != ( options & LDAP_X_EXTIOF_OPT_SECURE )) {
              if ( NULL == iofns->liof_ssl_enable ) {
                     LDAP_SET_ERRNO( defcsip->csi_ld, EINVAL );
                     return( -1 );
              }
              secure = 1;
       } else {
              secure = 0;
       }

       socketfn = ( iofns->liof_socket == NULL ) ?
                  nsldapi_os_socket : nsldapi_compat_socket;
       ioctlfn = ( iofns->liof_ioctl == NULL ) ?
                  nsldapi_os_ioctl : (NSLDAPI_IOCTL_FN *)(iofns->liof_ioctl);
       if ( NULL == iofns->liof_connect ) {
              connectwithtofn = nsldapi_os_connect_with_to;
              connectfn = NULL;
       } else {
              connectwithtofn = NULL;
              connectfn = iofns->liof_connect;
       }
       closefn = ( iofns->liof_close == NULL ) ?
                  nsldapi_os_closesocket : iofns->liof_close;  

       s = nsldapi_try_each_host( defcsip->csi_ld, hostlist, defport,
                     secure, socketfn, ioctlfn, connectwithtofn,
                     connectfn, closefn );

       if ( s >= 0 ) {
              NSLDAPICompatSocketInfo            *csip;

              if (( csip = (NSLDAPICompatSocketInfo *)NSLDAPI_CALLOC( 1,
                  sizeof( NSLDAPICompatSocketInfo ))) == NULL ) {
                     (*closefn)( s );
                     LDAP_SET_LDERRNO( defcsip->csi_ld, LDAP_NO_MEMORY,
                            NULL, NULL );
                     return( -1 );
              }

              csip->csi_socket = s;
              csip->csi_ld = defcsip->csi_ld;
              *socketargp = (void *)csip;

              /*
               * We always return 1, which is a valid but not unique socket
               * (file descriptor) number.  The extended I/O functions only
               * require that the combination of the void *arg and the int
               * socket be unique.  Since we allocate the
               * NSLDAPICompatSocketInfo that we assign to arg, we meet
               * that requirement.
               */
              s = 1;
       }

       return( s );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int LDAP_CALLBACK nsldapi_ext_compat_poll ( LDAP_X_PollFD  fds[],
int  nfds,
int  timeout,
struct lextiof_session_private arg 
) [static]

Definition at line 1579 of file os-ip.c.

{
       NSLDAPICompatSocketInfo     *csip = (NSLDAPICompatSocketInfo *)arg;
       struct ldap_io_fns   *iofns = csip->csi_ld->ld_io_fns_ptr;
       fd_set               readfds, writefds;
       int                  i, rc, maxfd = 0;
       struct timeval              tv, *tvp;

       /*
        * Prepare fd_sets for select()
        */
       FD_ZERO( &readfds );
       FD_ZERO( &writefds );
       for ( i = 0; i < nfds; ++i ) {
              if ( fds[ i ].lpoll_fd < 0 ) {
                     continue;
              }

              if ( fds[ i ].lpoll_fd >= FD_SETSIZE ) {
                     LDAP_SET_ERRNO( csip->csi_ld, EINVAL );
                     return( -1 );
              }
              
              if ( 0 != ( fds[i].lpoll_events & LDAP_X_POLLIN )) {
                     FD_SET( fds[i].lpoll_fd, &readfds );
              }

              if ( 0 != ( fds[i].lpoll_events & LDAP_X_POLLOUT )) {
                     FD_SET( fds[i].lpoll_fd, &writefds );
              }

              fds[i].lpoll_revents = 0;   /* clear revents */

              if ( fds[i].lpoll_fd >= maxfd ) {
                     maxfd = fds[i].lpoll_fd;
              }
       }

       /*
        * select() using callback.
        */
       ++maxfd;
       if ( timeout == -1 ) {
              tvp = NULL;
       } else {
              tv.tv_sec = timeout / 1000;
              tv.tv_usec = 1000 * ( timeout - tv.tv_sec * 1000 );
              tvp = &tv;
       }
       rc = iofns->liof_select( maxfd, &readfds, &writefds, NULL, tvp );
       if ( rc <= 0 ) {     /* timeout or fatal error */
              return( rc );
       }

       /*
        * Use info. in fd_sets to populate poll() revents.
        */
       for ( i = 0; i < nfds; ++i ) {
              if ( fds[ i ].lpoll_fd < 0 ) {
                     continue;
              }

              if ( 0 != ( fds[i].lpoll_events & LDAP_X_POLLIN )
                  && FD_ISSET( fds[i].lpoll_fd, &readfds )) {
                     fds[i].lpoll_revents |= LDAP_X_POLLIN;
              }

              if ( 0 != ( fds[i].lpoll_events & LDAP_X_POLLOUT )
                  && FD_ISSET( fds[i].lpoll_fd, &writefds )) {
                     fds[i].lpoll_revents |= LDAP_X_POLLOUT;
              }

              /* XXXmcs: any other cases to deal with?  LDAP_X_POLLERR? */
       }

       return( rc );
}

Here is the caller graph for this function:

static int LDAP_CALLBACK nsldapi_ext_compat_read ( int  s,
void buf,
int  len,
struct lextiof_socket_private arg 
) [static]

Definition at line 1557 of file os-ip.c.

{
       NSLDAPICompatSocketInfo     *csip = (NSLDAPICompatSocketInfo *)arg;
       struct ldap_io_fns   *iofns = csip->csi_ld->ld_io_fns_ptr;

       return( iofns->liof_read( csip->csi_socket, buf, len ));
}

Here is the caller graph for this function:

static int LDAP_CALLBACK nsldapi_ext_compat_write ( int  s,
const void buf,
int  len,
struct lextiof_socket_private arg 
) [static]

Definition at line 1568 of file os-ip.c.

{
       NSLDAPICompatSocketInfo     *csip = (NSLDAPICompatSocketInfo *)arg;
       struct ldap_io_fns   *iofns = csip->csi_ld->ld_io_fns_ptr;

       return( iofns->liof_write( csip->csi_socket, buf, len ));
}

Here is the caller graph for this function:

static int nsldapi_find_in_cb_pollfds ( Sockbuf *  sb,
struct nsldapi_cb_statusinfo pip,
short  revents 
) [static]

Definition at line 1493 of file os-ip.c.

{
       int    i;

       for ( i = 0; i < pip->cbsi_pollfds_size; ++i ) {
              if ( NSLDAPI_CB_POLL_MATCH( sb, pip->cbsi_pollfds[ i ] )) {
                     if (( pip->cbsi_pollfds[ i ].lpoll_revents
                         & revents ) != 0 ) {
                            return( 1 );  /* revents overlap */
                     } else {
                            return( 0 );  /* revents do not overlap */
                     }
              }
       }

       return( 0 );  /* "sb" was not found */
}

Here is the caller graph for this function:

static int nsldapi_find_in_os_pollfds ( int  fd,
struct nsldapi_os_statusinfo pip,
short  revents 
) [static]

Definition at line 1371 of file os-ip.c.

{
       int    i;

       for ( i = 0; i < pip->ossi_pollfds_size; ++i ) {
              if ( pip->ossi_pollfds[i].fd == fd ) {
                     if (( pip->ossi_pollfds[ i ].revents & revents ) != 0 ) {
                            return( 1 );  /* revents overlap */
                     } else {
                            return( 0 );  /* revents do not overlap */
                     }
              }
       }

       return( 0 );  /* "fd" was not found */
}

Here is the caller graph for this function:

int nsldapi_install_compat_io_fns ( LDAP *  ld,
struct ldap_io_fns iofns 
)

Definition at line 1800 of file os-ip.c.

{
       NSLDAPICompatSocketInfo            *defcsip;

       if (( defcsip = (NSLDAPICompatSocketInfo *)NSLDAPI_CALLOC( 1,
           sizeof( NSLDAPICompatSocketInfo ))) == NULL ) {
              return( LDAP_NO_MEMORY );
       }

       defcsip->csi_socket = -1;
       defcsip->csi_ld = ld;

       if ( ld->ld_io_fns_ptr != NULL ) {
              (void)memset( (char *)ld->ld_io_fns_ptr, 0,
                  sizeof( struct ldap_io_fns ));
       } else if (( ld->ld_io_fns_ptr = (struct ldap_io_fns *)NSLDAPI_CALLOC(
           1, sizeof( struct ldap_io_fns ))) == NULL ) {
              NSLDAPI_FREE( defcsip );
              return( LDAP_NO_MEMORY );
       }

       /* struct copy */
       *(ld->ld_io_fns_ptr) = *iofns;

       ld->ld_extio_size = LBER_X_EXTIO_FNS_SIZE;
       ld->ld_ext_session_arg = defcsip;
       ld->ld_extread_fn = nsldapi_ext_compat_read;
       ld->ld_extwrite_fn = nsldapi_ext_compat_write;
       ld->ld_extpoll_fn = nsldapi_ext_compat_poll;
       ld->ld_extconnect_fn = nsldapi_ext_compat_connect;
       ld->ld_extclose_fn = nsldapi_ext_compat_close;

       return( nsldapi_install_lber_extiofns( ld, ld->ld_sbp ));
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_install_lber_extiofns ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 1517 of file os-ip.c.

{
       struct lber_x_ext_io_fns    lberiofns;

       if ( NULL != sb ) {
              lberiofns.lbextiofn_size = LBER_X_EXTIO_FNS_SIZE;
              lberiofns.lbextiofn_read = ld->ld_extread_fn;
              lberiofns.lbextiofn_write = ld->ld_extwrite_fn;
              lberiofns.lbextiofn_writev = ld->ld_extwritev_fn;
              lberiofns.lbextiofn_socket_arg = ld->ld_ext_session_arg;

              if ( ber_sockbuf_set_option( sb, LBER_SOCKBUF_OPT_EXT_IO_FNS,
                  &lberiofns ) != 0 ) {
                     return( LDAP_LOCAL_ERROR );
              }
       }

       return( LDAP_SUCCESS );
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsldapi_iostatus_free ( LDAP *  ld)

Definition at line 1119 of file os-ip.c.

{
       if ( ld == NULL ) {
              return;
       }

              
       /* clean up classic I/O compatibility glue */
       if ( ld->ld_io_fns_ptr != NULL ) {
              if ( ld->ld_ext_session_arg != NULL ) {
                     NSLDAPI_FREE( ld->ld_ext_session_arg );
              }
              NSLDAPI_FREE( ld->ld_io_fns_ptr );
       }

       /* clean up I/O status tracking info. */
       if ( ld->ld_iostatus != NULL ) {
              NSLDAPIIOStatus      *iosp = ld->ld_iostatus;

              if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_HAVE_POLL
                     if ( iosp->ios_status.ios_osinfo.ossi_pollfds
                         != NULL ) {
                            NSLDAPI_FREE(
                                iosp->ios_status.ios_osinfo.ossi_pollfds );
                     }
#endif /* NSLDAPI_HAVE_POLL */

              } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
                     if ( iosp->ios_status.ios_cbinfo.cbsi_pollfds
                         != NULL ) {
                            NSLDAPI_FREE(
                                iosp->ios_status.ios_cbinfo.cbsi_pollfds );
                     }
              } else {
                     LDAPDebug( LDAP_DEBUG_ANY,
                         "nsldapi_iostatus_free: unknown I/O type %d\n",
                          iosp->ios_type, 0, 0 );
              }

              NSLDAPI_FREE( iosp );
       }
}

Here is the caller graph for this function:

static int nsldapi_iostatus_init_nolock ( LDAP *  ld) [static]

Definition at line 1084 of file os-ip.c.

{
       NSLDAPIIOStatus      *iosp;

       if ( ld->ld_iostatus != NULL ) {
              return( 0 );
       }

       if (( iosp = (NSLDAPIIOStatus *)NSLDAPI_CALLOC( 1,
           sizeof( NSLDAPIIOStatus ))) == NULL ) {
              LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY, NULL, NULL );
              return( -1 );
       }

       if ( ld->ld_extpoll_fn == NULL ) {
              iosp->ios_type = NSLDAPI_IOSTATUS_TYPE_OSNATIVE;
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return( -1 );
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifndef NSLDAPI_HAVE_POLL
              FD_ZERO( &iosp->ios_status.ios_osinfo.ossi_readfds );
              FD_ZERO( &iosp->ios_status.ios_osinfo.ossi_writefds );
#endif /* !NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else {
              iosp->ios_type = NSLDAPI_IOSTATUS_TYPE_CALLBACK;
       }

       ld->ld_iostatus = iosp;
       return( 0 );
}

Here is the caller graph for this function:

int nsldapi_iostatus_interest_clear ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 914 of file os-ip.c.

{
       NSLDAPIIOStatus      *iosp;

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );

       if ( ld->ld_iostatus == NULL
           && nsldapi_iostatus_init_nolock( ld ) < 0 ) {
              LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
              return( -1 );
       }

       iosp = ld->ld_iostatus;

       if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return( -1 );
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef NSLDAPI_HAVE_POLL
              if ( nsldapi_clear_from_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, POLLOUT )) {
                     --iosp->ios_write_count;
              }
              if ( nsldapi_clear_from_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, POLLIN )) {
                     --iosp->ios_read_count;
              }
#else /* NSLDAPI_HAVE_POLL */
              if ( FD_ISSET( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo.ossi_writefds )) {
                     FD_CLR( sb->sb_sd,
                         &iosp->ios_status.ios_osinfo.ossi_writefds );
                     --iosp->ios_write_count;
              }
              if ( FD_ISSET( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo.ossi_readfds )) {
                     FD_CLR( sb->sb_sd,
                         &iosp->ios_status.ios_osinfo.ossi_readfds );
                     --iosp->ios_read_count;
              }
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              if ( nsldapi_clear_from_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, LDAP_X_POLLOUT )) {
                     --iosp->ios_write_count;
              }
              if ( nsldapi_clear_from_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, LDAP_X_POLLIN )) {
                     --iosp->ios_read_count;
              }
       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_interest_clear: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_iostatus_interest_read ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 859 of file os-ip.c.

{
       NSLDAPIIOStatus      *iosp;

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );

       if ( ld->ld_iostatus == NULL
           && nsldapi_iostatus_init_nolock( ld ) < 0 ) {
              LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
              return( -1 );
       }

       iosp = ld->ld_iostatus;

       if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return( -1 );
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef NSLDAPI_HAVE_POLL
              if ( nsldapi_add_to_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, POLLIN )) {
                     ++iosp->ios_read_count;
              }
#else /* NSLDAPI_HAVE_POLL */
              if ( !FD_ISSET( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo.ossi_readfds )) {
                     FD_SET( sb->sb_sd,
                         &iosp->ios_status.ios_osinfo.ossi_readfds );
                     ++iosp->ios_read_count;
              }
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              if ( nsldapi_add_to_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, LDAP_X_POLLIN )) {
                     ++iosp->ios_read_count;
              }
       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_interest_read: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_iostatus_interest_write ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 803 of file os-ip.c.

{
       NSLDAPIIOStatus      *iosp;

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );

       if ( ld->ld_iostatus == NULL
           && nsldapi_iostatus_init_nolock( ld ) < 0 ) {
              LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
              return( -1 );
       }

       iosp = ld->ld_iostatus;

       if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return( -1 );
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef NSLDAPI_HAVE_POLL
              if ( nsldapi_add_to_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, POLLOUT )) {
                     ++iosp->ios_write_count;
              }
#else /* NSLDAPI_HAVE_POLL */
              if ( !FD_ISSET( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo.ossi_writefds )) {
                     FD_SET( sb->sb_sd,
                         &iosp->ios_status.ios_osinfo.ossi_writefds );
                     ++iosp->ios_write_count;
              }
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              if ( nsldapi_add_to_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, LDAP_X_POLLOUT )) {
                     ++iosp->ios_write_count;
              }

       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_interest_write: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );

       return( 0 );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_iostatus_is_read_ready ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 1032 of file os-ip.c.

{
       int           rc;
       NSLDAPIIOStatus      *iosp;

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );
       iosp = ld->ld_iostatus;

       if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return 0;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef NSLDAPI_HAVE_POLL
              /*
               * if we are using poll() we do something a little tricky: if
               * any bits in the socket's returned events field other than
               * POLLOUT (ready for write) are set, we return true.  This
               * is done so we notice when a server closes a connection
               * or when another error occurs.  The actual error will be
               * noticed later when we call read() or recv().
               */
              rc = nsldapi_find_in_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, ~POLLOUT );

#else /* NSLDAPI_HAVE_POLL */
              rc = FD_ISSET( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo.ossi_use_readfds );
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              rc = nsldapi_find_in_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, ~LDAP_X_POLLOUT );

       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_is_read_ready: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
              rc = 0;
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
       return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_iostatus_is_write_ready ( LDAP *  ld,
Sockbuf *  sb 
)

Definition at line 982 of file os-ip.c.

{
       int           rc;
       NSLDAPIIOStatus      *iosp;

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );
       iosp = ld->ld_iostatus;

       if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifdef NSLDAPI_AVOID_OS_SOCKETS
              return 0;
#else  /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef NSLDAPI_HAVE_POLL
              /*
               * if we are using poll() we do something a little tricky: if
               * any bits in the socket's returned events field other than
               * POLLIN (ready for read) are set, we return true.  This
               * is done so we notice when a server closes a connection
               * or when another error occurs.  The actual error will be
               * noticed later when we call write() or send().
               */
              rc = nsldapi_find_in_os_pollfds( sb->sb_sd,
                  &iosp->ios_status.ios_osinfo, ~POLLIN );

#else /* NSLDAPI_HAVE_POLL */
              rc = FD_ISSET( sb->sb_sd,
                     &iosp->ios_status.ios_osinfo.ossi_use_writefds );
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              rc = nsldapi_find_in_cb_pollfds( sb,
                  &iosp->ios_status.ios_cbinfo, ~LDAP_X_POLLIN );

       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_is_write_ready: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
              rc = 0;
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
       return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

int nsldapi_iostatus_poll ( LDAP *  ld,
struct timeval timeout 
)

Definition at line 1207 of file os-ip.c.

{
       int                  rc;
       NSLDAPIIOStatus             *iosp;

       LDAPDebug( LDAP_DEBUG_TRACE, "nsldapi_iostatus_poll\n", 0, 0, 0 );

       LDAP_MUTEX_LOCK( ld, LDAP_IOSTATUS_LOCK );
       iosp = ld->ld_iostatus;

       if ( iosp == NULL ||
           ( iosp->ios_read_count <= 0 && iosp->ios_read_count <= 0 )) {
              rc = 0;              /* simulate a timeout */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_OSNATIVE ) {
#ifndef NSLDAPI_AVOID_OS_SOCKETS
#ifdef NSLDAPI_HAVE_POLL

              rc = NSLDAPI_POLL( iosp->ios_status.ios_osinfo.ossi_pollfds,
                  iosp->ios_status.ios_osinfo.ossi_pollfds_size,
                  nsldapi_tv2ms( timeout ));

#else /* NSLDAPI_HAVE_POLL */

              /* two (potentially large) struct copies */
              iosp->ios_status.ios_osinfo.ossi_use_readfds
                  = iosp->ios_status.ios_osinfo.ossi_readfds;
              iosp->ios_status.ios_osinfo.ossi_use_writefds
                  = iosp->ios_status.ios_osinfo.ossi_writefds;

#ifdef HPUX9
              rc = NSLDAPI_SELECT( nsldapi_get_select_table_size(),
                  (int *)&iosp->ios_status.ios_osinfo.ossi_use_readfds
                  (int *)&iosp->ios_status.ios_osinfo.ossi_use_writefds,
                  NULL, timeout );
#else
              rc = NSLDAPI_SELECT( nsldapi_get_select_table_size(),
                  &iosp->ios_status.ios_osinfo.ossi_use_readfds,
                  &iosp->ios_status.ios_osinfo.ossi_use_writefds,
                  NULL, timeout );
#endif /* else HPUX9 */
#endif /* else NSLDAPI_HAVE_POLL */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */

       } else if ( iosp->ios_type == NSLDAPI_IOSTATUS_TYPE_CALLBACK ) {
              /*
               * We always pass the session extended I/O argument to
               * the extended poll() callback.
               */
              rc = ld->ld_extpoll_fn( 
                  iosp->ios_status.ios_cbinfo.cbsi_pollfds,
                  iosp->ios_status.ios_cbinfo.cbsi_pollfds_size,
                  nsldapi_tv2ms( timeout ), ld->ld_ext_session_arg );

       } else {
              LDAPDebug( LDAP_DEBUG_ANY,
                  "nsldapi_iostatus_poll: unknown I/O type %d\n",
                   iosp->ios_type, 0, 0 );
              rc = 0;       /* simulate a timeout (what else to do?) */
       }

       LDAP_MUTEX_UNLOCK( ld, LDAP_IOSTATUS_LOCK );
       return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nsldapi_os_closesocket ( LBER_SOCKET  s) [static]

Definition at line 202 of file os-ip.c.

{
       int    rc;

#ifdef NSLDAPI_AVOID_OS_SOCKETS
       rc = -1;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
#ifdef _WINDOWS
       rc = closesocket( s );
#else /* _WINDOWS */
       rc = close( s );
#endif /* _WINDOWS */
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
       return( rc );
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nsldapi_os_connect_with_to ( LBER_SOCKET  s,
struct sockaddr name,
int  namelen,
int  msec_timeout 
) [static]

Definition at line 272 of file os-ip.c.

{
#ifdef NSLDAPI_AVOID_OS_SOCKETS
       return -1;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
       int           n, error;
       int           len;
#if defined(_WINDOWS) || defined(XP_OS2)
       int           nonblock = 1;
       int           block = 0;
#else
       int           flags;
#endif /* _WINDOWS */
#ifdef NSLDAPI_HAVE_POLL
       struct pollfd   pfd;
#else
       struct timeval       tval;
       fd_set        rset, wset;
#ifdef _WINDOWS
       fd_set        eset;
#endif
#endif /* NSLDAPI_HAVE_POLL */


       LDAPDebug( LDAP_DEBUG_TRACE, "nsldapi_connect_nonblock timeout: %d (msec)\n",
              msec, 0, 0);

#ifdef _WINDOWS
       ioctlsocket(sockfd, FIONBIO, &nonblock);
#elif defined(XP_OS2)
  ioctl( sockfd, FIONBIO, &nonblock, sizeof(nonblock) );
#else
       flags = fcntl(sockfd, F_GETFL, 0);
       fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
#endif /* _WINDOWS */

       error = 0;
       if ((n = connect(sockfd, saptr, salen)) < 0)
#ifdef _WINDOWS
              if ((n != SOCKET_ERROR) &&  (WSAGetLastError() != WSAEWOULDBLOCK)) {
#else
              if (errno != EINPROGRESS) {
#endif /* _WINDOWS */
#ifdef LDAP_DEBUG
                     if ( ldap_debug & LDAP_DEBUG_TRACE ) {
                            perror("connect");
                     }
#endif
                     return (-1);
              }

       /* success */
       if (n == 0)
              goto done;

#ifdef NSLDAPI_HAVE_POLL
       pfd.fd = sockfd;
       pfd.events = POLLOUT;
#else
       FD_ZERO(&rset);
       FD_SET(sockfd, &rset);
       wset = rset;

#ifdef _WINDOWS
       eset = rset;
#endif /* _WINDOWS */
#endif /* NSLDAPI_HAVE_POLL */

       if (msec < 0 && msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) {
              LDAPDebug( LDAP_DEBUG_TRACE, "Invalid timeout value detected.."
                     "resetting connect timeout to default value "
                     "(LDAP_X_IO_TIMEOUT_NO_TIMEOUT\n", 0, 0, 0);
              msec = LDAP_X_IO_TIMEOUT_NO_TIMEOUT;
#ifndef NSLDAPI_HAVE_POLL
       } else {
              if (msec != 0) {
                     tval.tv_sec = msec / 1000;
                     tval.tv_usec = 1000 * ( msec % 1000 );
              } else {
                     tval.tv_sec = 0;
              }
              tval.tv_usec = 0;
#endif /* NSLDAPI_HAVE_POLL */
       }

#ifdef NSLDAPI_HAVE_POLL
       if ((n = poll(&pfd, 1,
              (msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) ? msec : -1)) == 0) {
              errno = ETIMEDOUT;
              return (-1);
       }
       if (pfd.revents & POLLOUT) {
              len = sizeof(error);
              if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char *)&error, &len)
                     < 0)
                     return (-1);
#ifdef LDAP_DEBUG
       } else if ( ldap_debug & LDAP_DEBUG_TRACE ) {
              perror("poll error: sockfd not set");
#endif
       }

#else /* NSLDAPI_HAVE_POLL */
       /* if timeval structure == NULL, select will block indefinitely */
       /*                   != NULL, and value == 0, select will */
       /*                            not block */
       /* Windows is a bit quirky on how it behaves w.r.t nonblocking */
       /* connects.  If the connect fails, the exception fd, eset, is */
       /* set to show the failure.  The first argument in select is */
       /* ignored */

#ifdef _WINDOWS
       if ((n = select(sockfd +1, &rset, &wset, &eset,
              (msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) ? &tval : NULL)) == 0) {
              errno = WSAETIMEDOUT;
              return (-1);
       }
       /* if wset is set, the connect worked */
       if (FD_ISSET(sockfd, &wset) || FD_ISSET(sockfd, &rset)) {
              len = sizeof(error);
              if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char *)&error, &len)
                     < 0)
                     return (-1);
              goto done;
       }

       /* if eset is set, the connect failed */
       if (FD_ISSET(sockfd, &eset)) {
              return (-1);
       }

       /* failure on select call */
       if (n == SOCKET_ERROR) {
              perror("select error: SOCKET_ERROR returned");
              return (-1);         
       }
#else
       if ((n = select(sockfd +1, &rset, &wset, NULL,
              (msec != LDAP_X_IO_TIMEOUT_NO_TIMEOUT) ? &tval : NULL)) == 0) {
              errno = ETIMEDOUT;
              return (-1);
       }
       if (FD_ISSET(sockfd, &rset) || FD_ISSET(sockfd, &wset)) {
              len = sizeof(error);
              if (getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (char *)&error, &len)
                     < 0)
                     return (-1);
#ifdef LDAP_DEBUG
       } else if ( ldap_debug & LDAP_DEBUG_TRACE ) {
              perror("select error: sockfd not set");
#endif
       }
#endif /* _WINDOWS */
#endif /* NSLDAPI_HAVE_POLL */

done:
#ifdef _WINDOWS
       ioctlsocket(sockfd, FIONBIO, &block);
#elif defined(XP_OS2)
  ioctl( sockfd, FIONBIO, &nonblock, sizeof(block) );
#else
       fcntl(sockfd, F_SETFL, flags);
#endif /* _WINDOWS */

       if (error) {
              errno = error;
              return (-1);
       }

       return (0);
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nsldapi_os_ioctl ( LBER_SOCKET  s,
int  option,
int statusp 
) [static]

Definition at line 448 of file os-ip.c.

{
#ifdef NSLDAPI_AVOID_OS_SOCKETS
       return -1;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
       int           err;
#if defined(_WINDOWS) || defined(XP_OS2)
       u_long        iostatus;
#endif

       if ( FIONBIO != option ) {
              return( -1 );
       }

#ifdef _WINDOWS
       iostatus = *(u_long *)statusp;
       err = ioctlsocket( s, FIONBIO, &iostatus );
#else
#ifdef XP_OS2
       err = ioctl( s, FIONBIO, (caddr_t)&iostatus, sizeof(iostatus) );
#else
       err = ioctl( s, FIONBIO, (caddr_t)statusp );
#endif
#endif

       return( err );
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static LBER_SOCKET nsldapi_os_socket ( LDAP *  ld,
int  secure,
int  domain,
int  type,
int  protocol 
) [static]

Definition at line 220 of file os-ip.c.

{
#ifdef NSLDAPI_AVOID_OS_SOCKETS
       return -1;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
       int           s, invalid_socket;
       char          *errmsg = NULL;

       if ( secure ) {
              LDAP_SET_LDERRNO( ld, LDAP_LOCAL_ERROR, NULL,
                         nsldapi_strdup( "secure mode not supported" ));
              return( -1 );
       }

       s = socket( domain, type, protocol );

       /*
        * if the socket() call failed or it returned a socket larger
        * than we can deal with, return a "local error."
        */
       if ( NSLDAPI_INVALID_OS_SOCKET( s )) {
              errmsg = "unable to create a socket";
              invalid_socket = 1;
       } else {      /* valid socket -- check for overflow */
              invalid_socket = 0;
#if !defined(NSLDAPI_HAVE_POLL) && !defined(_WINDOWS)
              /* not on Windows and do not have poll() */
              if ( s >= FD_SETSIZE ) {
                     errmsg = "can't use socket >= FD_SETSIZE";
              }
#endif
       }

       if ( errmsg != NULL ) {     /* local socket error */
              if ( !invalid_socket ) {
                     nsldapi_os_closesocket( s );
              }
              errmsg = nsldapi_strdup( errmsg );
              LDAP_SET_LDERRNO( ld, LDAP_LOCAL_ERROR, NULL, errmsg );
              return( -1 );
       }

       return( s );
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nsldapi_try_each_host ( LDAP *  ld,
const char *  hostlist,
int  defport,
int  secure,
NSLDAPI_SOCKET_FN socketfn,
NSLDAPI_IOCTL_FN ioctlfn,
NSLDAPI_CONNECT_WITH_TO_FN connectwithtofn,
NSLDAPI_CONNECT_FN connectfn,
NSLDAPI_CLOSE_FN closefn 
) [static]

Definition at line 549 of file os-ip.c.

{
#ifdef NSLDAPI_AVOID_OS_SOCKETS
       return -1;
#else /* NSLDAPI_AVOID_OS_SOCKETS */
       int                  rc, i, s, err, connected, use_hp;
       int                  parse_err, port;
       struct sockaddr_in   sin;
       nsldapi_in_addr_t    address;
       char                 **addrlist, *ldhpbuf, *ldhpbuf_allocd;
       char                 *host;
       LDAPHostEnt          ldhent, *ldhp;
       struct hostent              *hp;
       struct ldap_x_hostlist_status      *status;
#ifdef GETHOSTBYNAME_BUF_T
       GETHOSTBYNAME_BUF_T  hbuf;
       struct hostent              hent;
#endif /* GETHOSTBYNAME_BUF_T */

       connected = 0;
       parse_err = ldap_x_hostlist_first( hostlist, defport, &host, &port,
            &status );
       while ( !connected && LDAP_SUCCESS == parse_err && host != NULL ) {
              ldhpbuf_allocd = NULL;
              ldhp = NULL;
              hp = NULL;
              s = 0;
              use_hp = 0;
              addrlist = NULL;


              if (( address = inet_addr( host )) == -1 ) {
                     if ( ld->ld_dns_gethostbyname_fn == NULL ) {
                            if (( hp = GETHOSTBYNAME( host, &hent, hbuf,
                                sizeof(hbuf), &err )) != NULL ) {
                                   addrlist = hp->h_addr_list;
                            }
                     } else {
                            /*
                             * DNS callback installed... use it.
                             */
#ifdef GETHOSTBYNAME_buf_t
                            /* avoid allocation by using hbuf if large enough */
                            if ( sizeof( hbuf ) < ld->ld_dns_bufsize ) {
                                   ldhpbuf = ldhpbuf_allocd
                                       = NSLDAPI_MALLOC( ld->ld_dns_bufsize );
                            } else {
                                   ldhpbuf = (char *)hbuf;
                            }
#else /* GETHOSTBYNAME_buf_t */
                            ldhpbuf = ldhpbuf_allocd = NSLDAPI_MALLOC(
                                ld->ld_dns_bufsize );
#endif /* else GETHOSTBYNAME_buf_t */

                            if ( ldhpbuf == NULL ) {
                                   LDAP_SET_LDERRNO( ld, LDAP_NO_MEMORY,
                                       NULL, NULL );
                                   ldap_memfree( host );
                                   ldap_x_hostlist_statusfree( status );
                                   return( -1 );
                            }

                            if (( ldhp = ld->ld_dns_gethostbyname_fn( host,
                                &ldhent, ldhpbuf, ld->ld_dns_bufsize, &err,
                                ld->ld_dns_extradata )) != NULL ) {
                                   addrlist = ldhp->ldaphe_addr_list;
                            }
                     }

                     if ( addrlist == NULL ) {
                            LDAP_SET_LDERRNO( ld, LDAP_CONNECT_ERROR, NULL, NULL );
                            LDAP_SET_ERRNO( ld, EHOSTUNREACH );  /* close enough */
                            if ( ldhpbuf_allocd != NULL ) {
                                   NSLDAPI_FREE( ldhpbuf_allocd );
                            }
                            ldap_memfree( host );
                            ldap_x_hostlist_statusfree( status );
                            return( -1 );
                     }
                     use_hp = 1;
              }

              rc = -1;
              for ( i = 0; !use_hp || ( addrlist[ i ] != 0 ); i++ ) {
                     if ( -1 == ( s = (*socketfn)( ld, secure, AF_INET,
                                   SOCK_STREAM, 0 ))) {
                            if ( ldhpbuf_allocd != NULL ) {
                                   NSLDAPI_FREE( ldhpbuf_allocd );
                            }
                            ldap_memfree( host );
                            ldap_x_hostlist_statusfree( status );
                            return( -1 );
                     }

                     if ( ld->ld_options & LDAP_BITOPT_ASYNC ) {
                            int    iostatus = 1;

                            err = (*ioctlfn)( s, FIONBIO, &iostatus );
                            if ( err == -1 ) {
                                   LDAPDebug( LDAP_DEBUG_ANY,
                                       "FIONBIO ioctl failed on %d\n",
                                       s, 0, 0 );
                            }
                     }

                     (void)memset( (char *)&sin, 0, sizeof( struct sockaddr_in ));
                     sin.sin_family = AF_INET;
                     sin.sin_port = htons( (unsigned short)port );

                     SAFEMEMCPY( (char *) &sin.sin_addr.s_addr,
                         ( use_hp ? (char *) addrlist[ i ] :
                         (char *) &address ), sizeof( sin.sin_addr.s_addr) );

                     {
#ifdef LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
/*
 * Block all of the signals that might interrupt connect() since there
 * is an OS bug that causes connect() to fail if it is restarted.  Look in
 * ns/netsite/ldap/include/portable.h for the definition of
 * LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
 */
                            sigset_t      ints_off, oldset;

                            sigemptyset( &ints_off );
                            sigaddset( &ints_off, SIGALRM );
                            sigaddset( &ints_off, SIGIO );
                            sigaddset( &ints_off, SIGCLD );

                            sigprocmask( SIG_BLOCK, &ints_off, &oldset );
#endif /* LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED */

                            if ( NULL != connectwithtofn  ) {  
                                   err = (*connectwithtofn)(s,
                                          (struct sockaddr *)&sin,
                                          sizeof(struct sockaddr_in),
                                          ld->ld_connect_timeout);
                            } else {
                                   err = (*connectfn)(s,
                                          (struct sockaddr *)&sin,
                                          sizeof(struct sockaddr_in));
                            }
#ifdef LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED
/*
 * restore original signal mask
 */
                            sigprocmask( SIG_SETMASK, &oldset, 0 );
#endif /* LDAP_CONNECT_MUST_NOT_BE_INTERRUPTED */

                     }
                     if ( err >= 0 ) {
                            connected = 1;
                            rc = 0;
                            break;
                     } else {
                            if ( ld->ld_options & LDAP_BITOPT_ASYNC) {
#ifdef _WINDOWS
                                   if (err == -1 && WSAGetLastError() == WSAEWOULDBLOCK)
                                          LDAP_SET_ERRNO( ld, EWOULDBLOCK );
#endif /* _WINDOWS */
                                   err = LDAP_GET_ERRNO( ld );
                                   if ( NSLDAPI_ERRNO_IO_INPROGRESS( err )) {
                                          LDAPDebug( LDAP_DEBUG_TRACE, "connect would block...\n",
                                                    0, 0, 0 );
                                          rc = -2;
                                          break;
                                   }
                            }

#ifdef LDAP_DEBUG
                            if ( ldap_debug & LDAP_DEBUG_TRACE ) {
                                   perror( (char *)inet_ntoa( sin.sin_addr ));
                            }
#endif
                            (*closefn)( s );
                            if ( !use_hp ) {
                                   break;
                            }
                     }
              }

              ldap_memfree( host );
              parse_err = ldap_x_hostlist_next( &host, &port, status );
       }

       if ( ldhpbuf_allocd != NULL ) {
              NSLDAPI_FREE( ldhpbuf_allocd );
       }
       ldap_memfree( host );
       ldap_x_hostlist_statusfree( status );

       if ( connected ) {
              LDAPDebug( LDAP_DEBUG_TRACE, "sd %d connected to: %s\n",
                  s, inet_ntoa( sin.sin_addr ), 0 );
       }

       return( rc == 0 ? s : -1 );
#endif /* NSLDAPI_AVOID_OS_SOCKETS */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int nsldapi_tv2ms ( struct timeval tv) [static]

Definition at line 1196 of file os-ip.c.

{
       if ( tv == NULL ) {
              return( -1 ); /* infinite timout for poll() */
       }

       return( tv->tv_sec * 1000 + tv->tv_usec / 1000 );
}

Here is the caller graph for this function: