case ATTR_OPT_TV: {
struct timeval tv;
char *next;
- tv.tv_sec = -1;
tv.tv_usec = 0;
tv.tv_sec = strtol( opt, &next, 10 );
if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
gopts->ldo_timelimit = LDAP_NO_LIMIT;
gopts->ldo_sizelimit = LDAP_NO_LIMIT;
- gopts->ldo_tm_api = (struct timeval *)NULL;
- gopts->ldo_tm_net = (struct timeval *)NULL;
+ gopts->ldo_tm_api.tv_sec = -1;
+ gopts->ldo_tm_net.tv_sec = -1;
/* ldo_defludp will be freed by the termination handler
*/
#endif
/* per API call timeout */
- struct timeval *ldo_tm_api;
- struct timeval *ldo_tm_net;
+ struct timeval ldo_tm_api;
+ struct timeval ldo_tm_net;
ber_int_t ldo_version;
ber_int_t ldo_deref;
/* but not pointers to malloc'ed items */
ld->ld_options.ldo_sctrls = NULL;
ld->ld_options.ldo_cctrls = NULL;
- ld->ld_options.ldo_tm_api = NULL;
- ld->ld_options.ldo_tm_net = NULL;
ld->ld_options.ldo_defludp = NULL;
#ifdef HAVE_CYRUS_SASL
ld->ld_options.ldo_tls_ctx = NULL;
#endif
- if ( gopts->ldo_tm_api &&
- ldap_int_timeval_dup( &ld->ld_options.ldo_tm_api, gopts->ldo_tm_api ))
- goto nomem;
-
- if ( gopts->ldo_tm_net &&
- ldap_int_timeval_dup( &ld->ld_options.ldo_tm_net, gopts->ldo_tm_net ))
- goto nomem;
-
if ( gopts->ldo_defludp ) {
ld->ld_options.ldo_defludp = ldap_url_duplist(gopts->ldo_defludp);
nomem:
ldap_free_select_info( ld->ld_selectinfo );
ldap_free_urllist( ld->ld_options.ldo_defludp );
- LDAP_FREE( ld->ld_options.ldo_tm_net );
- LDAP_FREE( ld->ld_options.ldo_tm_api );
#ifdef HAVE_CYRUS_SASL
LDAP_FREE( ld->ld_options.ldo_def_sasl_authzid );
LDAP_FREE( ld->ld_options.ldo_def_sasl_authcid );
return LDAP_OPT_SUCCESS;
case LDAP_OPT_TIMEOUT:
- /* the caller has to free outvalue ! */
- if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_api ) != 0 ) {
- return LDAP_OPT_ERROR;
- }
+ *(struct timeval *) outvalue = lo->ldo_tm_api;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_NETWORK_TIMEOUT:
- /* the caller has to free outvalue ! */
- if ( ldap_int_timeval_dup( outvalue, lo->ldo_tm_net ) != 0 ) {
- return LDAP_OPT_ERROR;
- }
+ *(struct timeval *) outvalue = lo->ldo_tm_net;
return LDAP_OPT_SUCCESS;
case LDAP_OPT_DEREF:
const struct timeval *tv =
(const struct timeval *) invalue;
- if ( lo->ldo_tm_api != NULL ) {
- LDAP_FREE( lo->ldo_tm_api );
- lo->ldo_tm_api = NULL;
- }
-
- if ( ldap_int_timeval_dup( &lo->ldo_tm_api, tv ) != 0 ) {
- return LDAP_OPT_ERROR;
- }
+ lo->ldo_tm_api = *tv;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_NETWORK_TIMEOUT: {
const struct timeval *tv =
(const struct timeval *) invalue;
- if ( lo->ldo_tm_net != NULL ) {
- LDAP_FREE( lo->ldo_tm_net );
- lo->ldo_tm_net = NULL;
- }
-
- if ( ldap_int_timeval_dup( &lo->ldo_tm_net, tv ) != 0 ) {
- return LDAP_OPT_ERROR;
- }
+ lo->ldo_tm_net = *tv;
} return LDAP_OPT_SUCCESS;
case LDAP_OPT_HOST_NAME: {
int async)
{
int rc, err;
- struct timeval tv = { 0 },
- *opt_tv = NULL;
+ struct timeval tv, *opt_tv = NULL;
#ifdef LDAP_CONNECTIONLESS
/* We could do a connect() but that would interfere with
return ( 0 );
}
#endif
- opt_tv = ld->ld_options.ldo_tm_net;
- if ( opt_tv != NULL ) {
- tv = *opt_tv;
+ if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
+ tv = ld->ld_options.ldo_tm_net;
+ opt_tv = &tv;
}
osip_debug(ld, "ldap_pvt_connect: fd: %d tm: %ld async: %d\n",
ldap_pvt_connect(LDAP *ld, ber_socket_t s, struct sockaddr_un *sa, int async)
{
int rc;
- struct timeval tv = { 0 },
- *opt_tv = NULL;
+ struct timeval tv, *opt_tv = NULL;
- opt_tv = ld->ld_options.ldo_tm_net;
- if ( opt_tv != NULL ) {
- tv = *opt_tv;
+ if ( ld->ld_options.ldo_tm_net.tv_sec >= 0 ) {
+ tv = ld->ld_options.ldo_tm_net;
+ opt_tv = &tv;
}
oslocal_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n",
lc->lconn_status = LDAP_CONNST_CONNECTED;
break;
- case -2: {
+ case -2:
/* async only occurs if a network timeout is set */
- struct timeval *tvp = ld->ld_options.ldo_tm_net;
- assert( tvp != NULL );
- /* honor network timeout */
- if ( time( NULL ) - lc->lconn_created <= tvp->tv_sec )
- {
- /* caller will have to call again */
- ld->ld_errno = LDAP_X_CONNECTING;
- }
- } /* fallthru */
+ /* honor network timeout */
+ if ( time( NULL ) - lc->lconn_created <= ld->ld_options.ldo_tm_net.tv_sec )
+ {
+ /* caller will have to call again */
+ ld->ld_errno = LDAP_X_CONNECTING;
+ }
+ /* fallthru */
default:
/* error */
LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex );
#endif
- if ( timeout == NULL ) {
- timeout = ld->ld_options.ldo_tm_api;
+ if ( timeout == NULL && ld->ld_options.ldo_tm_api.tv_sec >= 0 ) {
+ tv = ld->ld_options.ldo_tm_api;
+ timeout = &tv;
}
#ifdef LDAP_DEBUG
}
#endif
- if ( ld->ld_options.ldo_tm_api != NULL ) {
- LDAP_FREE( ld->ld_options.ldo_tm_api );
- ld->ld_options.ldo_tm_api = NULL;
- }
-
- if ( ld->ld_options.ldo_tm_net != NULL ) {
- LDAP_FREE( ld->ld_options.ldo_tm_net );
- ld->ld_options.ldo_tm_net = NULL;
- }
-
#ifdef HAVE_CYRUS_SASL
if ( ld->ld_options.ldo_def_sasl_mech != NULL ) {
LDAP_FREE( ld->ld_options.ldo_def_sasl_mech );