]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/os-ip.c
ITS#6689
[openldap] / libraries / libldap / os-ip.c
index 4092b742facd7a275b85e2edb8035a9a33a30735..424ef02e669af66483dbc639d73c76364848214a 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2010 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,
@@ -207,7 +258,7 @@ ldap_pvt_is_socket_ready(LDAP *ld, int s)
                == AC_SOCKET_ERROR )
        {
                /* XXX: needs to be replace with ber_stream_read() */
-               int rc = read(s, &ch, 1);
+               (void)read(s, &ch, 1);
                TRACE;
                return -1;
        }
@@ -533,9 +584,9 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
 
 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
        memset( &hints, '\0', sizeof(hints) );
-#ifdef USE_AI_ATTRCONFIG /* FIXME: configure test needed */
-       /* Use AI_ATTRCONFIG only on systems where its known to be needed. */
-       hints.ai_flags = AI_ATTRCONFIG;
+#ifdef USE_AI_ADDRCONFIG /* FIXME: configure test needed */
+       /* Use AI_ADDRCONFIG only on systems where its known to be needed. */
+       hints.ai_flags = AI_ADDRCONFIG;
 #endif
        hints.ai_family = ldap_int_inet4or6;
        hints.ai_socktype = socktype;
@@ -769,7 +820,7 @@ ldap_host_connected_to( Sockbuf *sb, const char *host )
                char *herr;
 #ifdef NI_MAXHOST
                char hbuf[NI_MAXHOST];
-#elif defined( MAXHOSTNAMELEN
+#elif defined( MAXHOSTNAMELEN )
                char hbuf[MAXHOSTNAMELEN];
 #else
                char hbuf[256];
@@ -957,6 +1008,9 @@ ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
 
        sip = (struct selectinfo *)ld->ld_selectinfo;
 
+       if (ber_sockbuf_ctrl( sb, LBER_SB_OPT_DATA_READY, NULL ))
+               return 1;
+
        ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
 
 #ifdef HAVE_POLL