X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fos-ip.c;h=dd270374fd44b6f8369f6ad0cd7d7d0090e30497;hb=52a0d000311d7eda3eb830c7bff75286fe7661fc;hp=a3a3306f93144293f3d91adc0ea8fd45e323ee18;hpb=040f945d3697b4860e3fbde491adf9a51aac65b1;p=openldap diff --git a/libraries/libldap/os-ip.c b/libraries/libldap/os-ip.c index a3a3306f93..dd270374fd 100644 --- a/libraries/libldap/os-ip.c +++ b/libraries/libldap/os-ip.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2009 The OpenLDAP Foundation. + * Copyright 1998-2011 The OpenLDAP Foundation. * Portions Copyright 1999 Lars Uffmann. * All rights reserved. * @@ -142,6 +142,57 @@ ldap_int_prepare_socket(LDAP *ld, int s, int proto ) "setsockopt(%d, SO_KEEPALIVE) failed (ignored).\n", s, 0, 0 ); } + if ( ld->ld_options.ldo_keepalive_idle > 0 ) + { +#ifdef TCP_KEEPIDLE + if ( setsockopt( s, IPPROTO_TCP, TCP_KEEPIDLE, + (void*) &ld->ld_options.ldo_keepalive_idle, + sizeof(ld->ld_options.ldo_keepalive_idle) ) == AC_SOCKET_ERROR ) + { + osip_debug( ld, "ldap_prepare_socket: " + "setsockopt(%d, TCP_KEEPIDLE) failed (ignored).\n", + s, 0, 0 ); + } +#else + osip_debug( ld, "ldap_prepare_socket: " + "sockopt TCP_KEEPIDLE not supported on this system.\n", + 0, 0, 0 ); +#endif /* TCP_KEEPIDLE */ + } + if ( ld->ld_options.ldo_keepalive_probes > 0 ) + { +#ifdef TCP_KEEPCNT + if ( setsockopt( s, IPPROTO_TCP, TCP_KEEPCNT, + (void*) &ld->ld_options.ldo_keepalive_probes, + sizeof(ld->ld_options.ldo_keepalive_probes) ) == AC_SOCKET_ERROR ) + { + osip_debug( ld, "ldap_prepare_socket: " + "setsockopt(%d, TCP_KEEPCNT) failed (ignored).\n", + s, 0, 0 ); + } +#else + osip_debug( ld, "ldap_prepare_socket: " + "sockopt TCP_KEEPCNT not supported on this system.\n", + 0, 0, 0 ); +#endif /* TCP_KEEPCNT */ + } + if ( ld->ld_options.ldo_keepalive_interval > 0 ) + { +#ifdef TCP_KEEPINTVL + if ( setsockopt( s, IPPROTO_TCP, TCP_KEEPINTVL, + (void*) &ld->ld_options.ldo_keepalive_interval, + sizeof(ld->ld_options.ldo_keepalive_interval) ) == AC_SOCKET_ERROR ) + { + osip_debug( ld, "ldap_prepare_socket: " + "setsockopt(%d, TCP_KEEPINTVL) failed (ignored).\n", + s, 0, 0 ); + } +#else + osip_debug( ld, "ldap_prepare_socket: " + "sockopt TCP_KEEPINTVL not supported on this system.\n", + 0, 0, 0 ); +#endif /* TCP_KEEPINTVL */ + } #endif /* SO_KEEPALIVE */ #ifdef TCP_NODELAY if ( setsockopt( s, IPPROTO_TCP, TCP_NODELAY, @@ -541,16 +592,12 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, hints.ai_socktype = socktype; snprintf(serv, sizeof serv, "%d", port ); -#ifdef LDAP_R_COMPILE /* most getaddrinfo(3) use non-threadsafe resolver libraries */ - ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_LOCK(&ldap_int_resolv_mutex); err = getaddrinfo( host, serv, &hints, &res ); -#ifdef LDAP_R_COMPILE - ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex); -#endif + LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex); if ( err != 0 ) { osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n", @@ -676,9 +723,9 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb, async); if ( (rc == 0) || (rc == -2) ) { - i = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&sin ); - if ( i ) - rc = i; + int err = ldap_int_connect_cbs( ld, sb, &s, srv, (struct sockaddr *)&sin ); + if ( err ) + rc = err; else break; }