[Date Prev][Date Next] [Chronological] [Thread] [Top]

Doing a non-blocking ldap_bind/ldap_simple_bind

Hi folks,
I am using OpenLDAP 2.2.20  and trying to make a non-blocking LDAP
connection to the server but havent had much luck. Can someone tell me what
I am doing wrong ?

Whenever, I try to connect to valid ip address & invalid port number,
ldap_bind/ldap_simple_bind( ) seem to block for timeout value. I was hoping
that ldap_bind/ldap_simple_bind( ) return immediately with the socket value
and then I can listen on the socket for any connection/bind errors.

Here is what I am doing:

    /* STEP Initialize LDAP data structures & get socket fd
    ld = ldap_init (inet_ntoa(srv_addr), hm_probe_info->dest_port);

    if (ld == NULL) {
    printf ("\n Ldap_init failed");
    return FALSE;

    network_timeout.tv_usec = 0;
    network_timeout.tv_sec = timeout_value;    //set it to 10sec

    if (ldap_set_option (ld, LDAP_OPT_NETWORK_TIMEOUT,
             (void *) &network_timeout) != LDAP_OPT_SUCCESS) {
    printf ("\n ldap_set_option for network timeout failed");
    ldap_unbind (ld);
    return FALSE;

    /* Set LDAP options version & network timeout
    version = LDAP_VERSION3;
    if (LDAP_OPT_SUCCESS != ldap_set_option (ld,
                         &version)) {
    printf ("\n%s - ldap_set_option for version failed");
    ldap_unbind (ld);
    return FALSE;

    /* Bind to the server
    msgid = ldap_simple_bind (ld, username, passwd);
    if (msgid == -1) {
    printf ("\n ldap_bind failed with error: %s", ldap_err2string (msgid));
    ldap_unbind (ld);
    return FALSE;

    /* Get the socket fd
    ret_val = ldap_get_option (ld, LDAP_OPT_DESC,

    if (ret_val == LDAP_SUCCESS) {
    printf ("\n ldap_get_option successful");
    return TRUE;
    } else {
    printf ("\n ldap_get_option unsuccessful");
    ldap_unbind (ld);
    return FALSE;