Re: Facing issues with LDAP_X_OPT_CONNECT_TIMEOUT option.

Anton Bobrov <[email protected]>
Newsgroups gmane.comp.mozilla.devel.directory
Organization Sun Microsystems, Inc.
Message-ID <[email protected]>
LDAP_X_OPT_CONNECT_TIMEOUT is applicable only when a new connection
being established. in your case that happens when you execute bind
operation. now i dunno why your LDAP server is changing its IP addr
dynamically and how it does the cleanup but normally you should get
LDAP_SERVER_DOWN from ldap_search_s() if that happens clean. there
were several fixes made to "connection down" handling in libldap
since 5.08 version so you might wanna upgrade to the latest version
and see if LDAP_SERVER_DOWN gets returned straight away or not.

Binod Kumar wrote:
> Hello,
> 
>         "LDAP_X_OPT_CONNECT_TIMEOUT" documentation says that it allows  to 
> control the TCP/IP timeout. But in my sample program this option is not 
> working as expected. I have set the TCP/IP timeout value as 60000 
> millisecond. If IP address of LDAP server gets changed after the successfull 
> bind operation, ldap_search_s() API is returning after 15 minutes of TCP/IP 
> timeout period on linux platforms even if i have set the 
> LDAP_X_OPT_CONNECT_TIMEOUT value with 60000 millisecond..
> Following is the code
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <time.h>
> #include <ldap.h>
> int main( int argc, char **argv )
> {
>      LDAP *ld;
>      LDAPMessage *result, *e;
>      BerElement *ber;
>      char *a, *dn;
>      char **vals;
>      int rc,i;
>      /* get a handle to an LDAP connection */
>     if ( (ld = ldap_init( "10.88.176.137", 389 )) == NULL )
>    {
>        perror( "ldap_init" );
>        return( 1 );
>     }
>     int    timeout = 60000;
>     if ( ldap_set_option( ld, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout ) != 
> LDAP_SUCCESS )
>     {
>                 rc = ldap_get_lderrno( ld, NULL, NULL);
>                 fprintf( stderr, "ldap_set_option: %s\n", ldap_err2string( 
> rc ) );
>                 ldap_unbind( ld );
>                 return (rc);
>     }
>     /* authenticate to the directory as nobody */
>    if ( ldap_simple_bind_s( ld,"cn=directory manager", "password" ) != 
> LDAP_SUCCESS )
>    {
>               ldap_perror( ld, "ldap_simple_bind_s" );
>               return( 1 );
>    }
>   while(1)
>   {
>           /* search for all entries with surname of Jensen */
>           if ( ldap_search_s( ld, "o=airius.com", 0,"objectclass=*", NULL, 
> 0, &result ) != LDAP_SUCCESS )
>           {
>                 ldap_perror( ld, "ldap_search_s" );
>                 return( 1 );
>           }
>           /* for each entry print out name + all attrs and values */
>           for ( e = ldap_first_entry( ld, result ); e != NULL;e = 
> ldap_next_entry( ld, e ) )
>          {
>                 if ( (dn = ldap_get_dn( ld, e )) != NULL )
>                 {
>                   printf( "dn: %s\n", dn );
>                   ldap_memfree( dn );
>                 }
>                 for ( a = ldap_first_attribute( ld, e, &ber );a != NULL; a = 
> ldap_next_attribute( ld, e, ber ) )
>                  {
>                       if ((vals = ldap_get_values( ld, e, a)) != NULL )
>                      {
>                             for ( i = 0; vals[i] != NULL; i++ )
>                              {
>                                   printf( "%s: %s\n", a, vals[i] );
>                              }
>                             ldap_value_free( vals );
>                       }
>                       ldap_memfree( a );
>                 }
>                 if ( ber != NULL )
>                  {
>                       ldap_ber_free( ber, 0 );
>                  }
>                 printf( "\n" );
>       }//end of outer for loop
>     }//end of while loop
>   ldap_msgfree( result );
>   ldap_unbind( ld );
>   return( 0 );
> }
> 
> I have used LDAP SDK version  5.08. I am using Linux operating system. 
> Please let me know if something is wrong with this program or there is some 
> issue with LDAP_X_OPT_CONNECT_TIMEOUT option.
> Looking forward for help and suggestion in this regard.
> 
> Thanks & Regards
> Binod Kumar 
> 
> 
> _______________________________________________
> dev-tech-ldap mailing list
> [email protected]
> https://lists.mozilla.org/listinfo/dev-tech-ldap
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.