extra 'swamp' modes: -SS start searches and read responses; -SSS start all searches, then read all responses

This commit is contained in:
Pierangelo Masarati 2010-08-10 05:59:10 +00:00
parent 4fbbedcf29
commit 6ac38f9cc6

View file

@ -71,7 +71,7 @@ usage( char *name, char o )
"[-C] " "[-C] "
"[-F] " "[-F] "
"[-N] " "[-N] "
"[-S] " "[-S[S[S]]] "
"[-i <ignore>] " "[-i <ignore>] "
"[-l <loops>] " "[-l <loops>] "
"[-L <outerloops>] " "[-L <outerloops>] "
@ -83,7 +83,10 @@ usage( char *name, char o )
exit( EXIT_FAILURE ); exit( EXIT_FAILURE );
} }
/* Just send requests without reading responses */ /* -S: just send requests without reading responses
* -SS: send all requests asynchronous and immediately start reading responses
* -SSS: send all requests asynchronous; then read responses
*/
static int swamp; static int swamp;
int int
@ -389,7 +392,12 @@ do_search( char *uri, char *manager, struct berval *passwd,
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int version = LDAP_VERSION3; int version = LDAP_VERSION3;
char buf[ BUFSIZ ]; char buf[ BUFSIZ ];
int *msgids = NULL, active = 0;
/* make room for msgid */
if ( swamp > 1 ) {
msgids = (int *)calloc( sizeof(int), innerloop );
}
retry:; retry:;
if ( ld == NULL ) { if ( ld == NULL ) {
@ -440,51 +448,161 @@ retry:;
} }
} }
for ( ; i < innerloop; i++ ) { if ( swamp > 1 ) {
LDAPMessage *res = NULL; do {
LDAPMessage *res = NULL;
int j, msgid;
if (swamp) { if ( i < innerloop ) {
int msgid; rc = ldap_search_ext( ld, sbase, scope,
rc = ldap_search_ext( ld, sbase, scope, filter, NULL, noattrs, NULL, NULL,
filter, NULL, noattrs, NULL, NULL, NULL, LDAP_NO_LIMIT, &msgids[i] );
NULL, LDAP_NO_LIMIT, &msgid );
if ( rc == LDAP_SUCCESS ) continue;
else break;
}
rc = ldap_search_ext_s( ld, sbase, scope, active++;
filter, attrs, noattrs, NULL, NULL, #if 0
NULL, LDAP_NO_LIMIT, &res ); fprintf( stderr,
if ( res != NULL ) { ">>> PID=%ld - Search(%d, %d, %d, %d): "
ldap_msgfree( res ); "base=\"%s\" scope=%s filter=\"%s\"\n",
} (long) pid, innerloop, i, active, msgids[i],
sbase, ldap_pvt_scope2str( scope ), filter );
#endif
i++;
if ( rc ) { if ( rc ) {
int first = tester_ignore_err( rc ); int first = tester_ignore_err( rc );
/* if ignore.. */ /* if ignore.. */
if ( first ) { if ( first ) {
/* only log if first occurrence */ /* only log if first occurrence */
if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) { if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
tester_ldap_error( ld, "ldap_search_ext_s", NULL ); tester_ldap_error( ld, "ldap_search_ext", NULL );
}
continue;
}
/* busy needs special handling */
snprintf( buf, sizeof( buf ),
"base=\"%s\" filter=\"%s\"\n",
sbase, filter );
tester_ldap_error( ld, "ldap_search_ext", buf );
if ( rc == LDAP_BUSY && do_retry > 0 ) {
ldap_unbind_ext( ld, NULL, NULL );
ld = NULL;
do_retry--;
goto retry;
}
break;
}
if ( swamp > 2 ) {
continue;
} }
continue;
} }
/* busy needs special handling */ rc = ldap_result( ld, LDAP_RES_ANY, 0, NULL, &res );
snprintf( buf, sizeof( buf ), switch ( rc ) {
"base=\"%s\" filter=\"%s\"\n", case -1:
sbase, filter ); /* gone really bad */
tester_ldap_error( ld, "ldap_search_ext_s", buf ); goto cleanup;
if ( rc == LDAP_BUSY && do_retry > 0 ) {
ldap_unbind_ext( ld, NULL, NULL ); case 0:
ld = NULL; /* timeout (impossible) */
do_retry--; break;
goto retry;
case LDAP_RES_SEARCH_ENTRY:
case LDAP_RES_SEARCH_REFERENCE:
/* ignore */
break;
case LDAP_RES_SEARCH_RESULT:
/* just remove, no error checking (TODO?) */
msgid = ldap_msgid( res );
/* linear search, bah */
for ( j = 0; j < i; j++ ) {
if ( msgids[ j ] == msgid ) {
msgids[ j ] = -1;
active--;
#if 0
fprintf( stderr,
"<<< PID=%ld - SearchDone(%d, %d, %d, %d): "
"base=\"%s\" scope=%s filter=\"%s\"\n",
(long) pid, innerloop, j, active, msgid,
sbase, ldap_pvt_scope2str( scope ), filter );
#endif
break;
}
}
break;
default:
/* other messages unexpected */
fprintf( stderr,
"### PID=%ld - Search(%d): "
"base=\"%s\" scope=%s filter=\"%s\" "
"attrs=%s%s. unexpected response tag=%d\n",
(long) pid, innerloop,
sbase, ldap_pvt_scope2str( scope ), filter,
attrs[0], attrs[1] ? " (more...)" : "", rc );
break;
}
if ( res != NULL ) {
ldap_msgfree( res );
}
} while ( i < innerloop || active > 0 );
} else {
for ( ; i < innerloop; i++ ) {
LDAPMessage *res = NULL;
if (swamp) {
int msgid;
rc = ldap_search_ext( ld, sbase, scope,
filter, NULL, noattrs, NULL, NULL,
NULL, LDAP_NO_LIMIT, &msgid );
if ( rc == LDAP_SUCCESS ) continue;
else break;
}
rc = ldap_search_ext_s( ld, sbase, scope,
filter, attrs, noattrs, NULL, NULL,
NULL, LDAP_NO_LIMIT, &res );
if ( res != NULL ) {
ldap_msgfree( res );
}
if ( rc ) {
int first = tester_ignore_err( rc );
/* if ignore.. */
if ( first ) {
/* only log if first occurrence */
if ( ( force < 2 && first > 0 ) || abs(first) == 1 ) {
tester_ldap_error( ld, "ldap_search_ext_s", NULL );
}
continue;
}
/* busy needs special handling */
snprintf( buf, sizeof( buf ),
"base=\"%s\" filter=\"%s\"\n",
sbase, filter );
tester_ldap_error( ld, "ldap_search_ext_s", buf );
if ( rc == LDAP_BUSY && do_retry > 0 ) {
ldap_unbind_ext( ld, NULL, NULL );
ld = NULL;
do_retry--;
goto retry;
}
break;
} }
break;
} }
} }
cleanup:;
if ( msgids != NULL ) {
free( msgids );
}
if ( ldp != NULL ) { if ( ldp != NULL ) {
*ldp = ld; *ldp = ld;