]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/os-ip.c
Merge remote branch 'origin/mdb.master'
[openldap] / libraries / libldap / os-ip.c
index a3a3306f93144293f3d91adc0ea8fd45e323ee18..dd270374fd44b6f8369f6ad0cd7d7d0090e30497 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * 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;
                }