]> git.sur5r.net Git - openldap/commitdiff
allow to pass timeout arg (tnx to Luca)
authorPierangelo Masarati <ando@openldap.org>
Fri, 19 Aug 2005 07:27:32 +0000 (07:27 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 19 Aug 2005 07:27:32 +0000 (07:27 +0000)
tests/progs/slapd-addel.c
tests/progs/slapd-modify.c
tests/progs/slapd-modrdn.c
tests/progs/slapd-read.c
tests/progs/slapd-search.c
tests/progs/slapd-tester.c

index 6b8caacc0633293494a111f4bcaf02a67e9baba7..082a7aa3d530e4ab770ca9d34304971ba74aeef4 100644 (file)
@@ -41,12 +41,20 @@ get_add_entry( char *filename, LDAPMod ***mods );
 
 static void
 do_addel( char *uri, char *host, int port, char *manager, char *passwd,
-       char *dn, LDAPMod **attrs, int maxloop, int maxretries );
+       char *dn, LDAPMod **attrs, int maxloop, int maxretries, int delay );
 
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -f <addfile> [-l <loops>]\n",
+        fprintf( stderr,
+               "usage: %s "
+               "-H <uri> | ([-h <host>] -p <port>) "
+               "-D <manager> "
+               "-w <passwd> "
+               "-f <addfile> "
+               "[-l <loops>] "
+               "[-r <maxretries>] "
+               "[-t <delay>]\n",
                        name );
        exit( EXIT_FAILURE );
 }
@@ -64,9 +72,10 @@ main( int argc, char **argv )
        char            *entry = NULL;
        int             loops = LOOPS;
        int             retries = RETRIES;
+       int             delay = 0;
        LDAPMod         **attrs = NULL;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:r:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:f:l:r:t:" )) != EOF ) {
                switch( i ) {
                case 'H':               /* the server's URI */
                        uri = strdup( optarg );
@@ -96,10 +105,14 @@ main( int argc, char **argv )
                        loops = atoi( optarg );
                        break;
 
-               case 'r':
+               case 'r':               /* number of retries */
                        retries = atoi( optarg );
                        break;
 
+               case 't':               /* delay in seconds */
+                       delay = atoi( optarg );
+                       break;
+
                default:
                        usage( argv[0] );
                        break;
@@ -128,7 +141,7 @@ main( int argc, char **argv )
        }
 
        do_addel( uri, host, port, manager, passwd, entry, attrs,
-                       loops, retries );
+                       loops, retries, delay );
 
        exit( EXIT_SUCCESS );
 }
@@ -258,7 +271,8 @@ do_addel(
        char *entry,
        LDAPMod **attrs,
        int maxloop,
-       int maxretries
+       int maxretries,
+       int delay
 )
 {
        LDAP    *ld = NULL;
@@ -294,9 +308,11 @@ retry:;
                switch ( rc ) {
                case LDAP_BUSY:
                case LDAP_UNAVAILABLE:
-                       if ( do_retry == 1 ) {
-                               do_retry = 0;
-                               sleep( 1 );
+                       if ( do_retry > 0 ) {
+                               do_retry--;
+                               if ( delay != 0 ) {
+                                   sleep( delay );
+                               }
                                goto retry;
                        }
                /* fallthru */
index b639df553908dd065281e8020b2e37334780b25a..c0484dbc5cfa7d6611ff3971a5bbfe17a176b435 100644 (file)
 static void
 do_modify( char *uri, char *host, int port, char *manager, char *passwd,
                char *entry, char *attr, char *value, int maxloop,
-               int maxretries );
+               int maxretries, int delay );
 
 
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -e <entry> [-l <loops>]\n",
+        fprintf( stderr,
+               "usage: %s "
+               "-H <uri> | ([-h <host>] -p <port>) "
+               "-D <manager> "
+               "-w <passwd> "
+               "-e <entry> "
+               "[-l <loops>] "
+               "[-r <maxretries>] "
+               "[-t <delay>]\n",
                        name );
        exit( EXIT_FAILURE );
 }
@@ -60,8 +68,9 @@ main( int argc, char **argv )
        char            *value = NULL;
        int             loops = LOOPS;
        int             retries = RETRIES;
+       int             delay = 0;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:r:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:a:l:r:t:" )) != EOF ) {
                switch( i ) {
                case 'H':               /* the server uri */
                        uri = strdup( optarg );
@@ -95,10 +104,14 @@ main( int argc, char **argv )
                        loops = atoi( optarg );
                        break;
 
-               case 'r':
+               case 'r':               /* number of retries */
                        retries = atoi( optarg );
                        break;
 
+               case 't':               /* delay in seconds */
+                       delay = atoi( optarg );
+                       break;
+
                default:
                        usage( argv[0] );
                        break;
@@ -131,7 +144,7 @@ main( int argc, char **argv )
                value++;
 
        do_modify( uri, host, port, manager, passwd, entry, ava, value,
-                       loops, retries );
+                       loops, retries, delay );
        exit( EXIT_SUCCESS );
 }
 
@@ -139,7 +152,7 @@ main( int argc, char **argv )
 static void
 do_modify( char *uri, char *host, int port, char *manager,
        char *passwd, char *entry, char* attr, char* value,
-       int maxloop, int maxretries )
+       int maxloop, int maxretries, int delay )
 {
        LDAP    *ld = NULL;
        int     i = 0, do_retry = maxretries;
@@ -188,9 +201,11 @@ retry:;
                switch ( rc ) {
                case LDAP_BUSY:
                case LDAP_UNAVAILABLE:
-                       if ( do_retry == 1 ) {
-                               do_retry = 0;
-                               sleep( 1 );
+                       if ( do_retry > 0 ) {
+                               do_retry--;
+                               if ( delay > 0 ) {
+                                   sleep( delay );
+                               }
                                goto retry;
                        }
                /* fallthru */
index 2e95ddfa038e126f7ee1319f9d897d02f069da08..06b513044269dbbc68033bde43a79533149ab6bf 100644 (file)
 
 static void
 do_modrdn( char *uri, char *host, int port, char *manager, char *passwd,
-               char *entry, int maxloop, int maxretries );
+               char *entry, int maxloop, int maxretries, int delay );
 
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-h <host>] -p port -D <managerDN> -w <passwd> -e <entry> [-l <loops>]\n",
+        fprintf( stderr,
+               "usage: %s "
+               "-H <uri> | ([-h <host>] -p <port>) "
+               "-D <manager> "
+               "-w <passwd> "
+               "-e <entry> "
+               "[-l <loops>] "
+               "[-r <maxretries>] "
+               "[-t <delay>]\n",
                        name );
        exit( EXIT_FAILURE );
 }
@@ -60,8 +68,9 @@ main( int argc, char **argv )
        char            *entry = NULL;
        int             loops = LOOPS;
        int             retries = RETRIES;
+       int             delay = 0;
 
-       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:r:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:D:w:e:l:r:t:" )) != EOF ) {
                switch( i ) {
                case 'H':               /* the server uri */
                        uri = strdup( optarg );
@@ -95,6 +104,10 @@ main( int argc, char **argv )
                        retries = atoi( optarg );
                        break;
 
+               case 't':               /* delay in seconds */
+                       delay = atoi( optarg );
+                       break;
+
                default:
                        usage( argv[0] );
                        break;
@@ -112,14 +125,14 @@ main( int argc, char **argv )
 
        }
 
-       do_modrdn( uri, host, port, manager, passwd, entry, loops, retries );
+       do_modrdn( uri, host, port, manager, passwd, entry, loops, retries, delay );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
 do_modrdn( char *uri, char *host, int port, char *manager,
-       char *passwd, char *entry, int maxloop, int maxretries )
+       char *passwd, char *entry, int maxloop, int maxretries, int delay )
 {
        LDAP    *ld = NULL;
        int     i = 0, do_retry = maxretries;
@@ -180,9 +193,11 @@ retry:;
                switch ( rc ) {
                case LDAP_BUSY:
                case LDAP_UNAVAILABLE:
-                       if ( do_retry == 1 ) {
-                               do_retry = 0;
-                               sleep( 1 );
+                       if ( do_retry > 0 ) {
+                               do_retry--;
+                               if ( delay > 0) {
+                                   sleep( delay );
+                               }
                                goto retry;
                        }
                /* fallthru */
index e2c07686794808b4508b2580f3c2349e9e03d1e4..c5cb56ce33bd87d9ece5e3acdaa198eeb4a141f2 100644 (file)
 
 static void
 do_read( char *uri, char *host, int port, char *entry, int maxloop,
-               int maxretries );
+               int maxretries, int delay );
 
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
+        fprintf( stderr,
+               "usage: %s "
+               "-H <uri> | ([-h <host>] -p <port>) "
+               "-e <entry> "
+               "[-l <loops>] "
+               "[-r <maxretries>] "
+               "[-t <delay>]\n",
                        name );
        exit( EXIT_FAILURE );
 }
@@ -58,8 +64,9 @@ main( int argc, char **argv )
        char            *entry = NULL;
        int             loops = LOOPS;
        int             retries = RETRIES;
+       int             delay = 0;
 
-       while ( (i = getopt( argc, argv, "H:h:p:e:l:r:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "H:h:p:e:l:r:t:" )) != EOF ) {
                switch( i ) {
                case 'H':               /* the server uri */
                        uri = strdup( optarg );
@@ -85,6 +92,10 @@ main( int argc, char **argv )
                        retries = atoi( optarg );
                        break;
 
+               case 't':               /* delay in seconds */
+                       delay = atoi( optarg );
+                       break;
+
                default:
                        usage( argv[0] );
                        break;
@@ -100,14 +111,14 @@ main( int argc, char **argv )
                exit( EXIT_FAILURE );
        }
 
-       do_read( uri, host, port, entry, ( 20 * loops ), retries );
+       do_read( uri, host, port, entry, ( 20 * loops ), retries, delay );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
 do_read( char *uri, char *host, int port, char *entry, int maxloop,
-               int maxretries )
+               int maxretries, int delay )
 {
        LDAP    *ld = NULL;
        int     i = 0, do_retry = maxretries;
@@ -143,9 +154,11 @@ retry:;
                switch ( rc ) {
                case LDAP_BUSY:
                case LDAP_UNAVAILABLE:
-                       if ( do_retry == 1 ) {
-                               do_retry = 0;
-                               sleep( 1 );
+                       if ( do_retry > 0 ) {
+                               do_retry--;
+                               if ( delay > 0 ) {
+                                   sleep( delay );
+                               }
                                goto retry;
                        }
                /* fallthru */
index 71588310565c47fd78f7d627fbb05aba0a1022de..9d9afe1e4fd39b144c1484fd72eca9066edbc585 100644 (file)
 
 static void
 do_search( char *uri, char *host, int port, char *manager, char *passwd,
-               char *sbase, char *filter, int maxloop, int maxretries );
+               char *sbase, char *filter, int maxloop, int maxretries, int delay );
 
 static void
 usage( char *name )
 {
-       fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
+        fprintf( stderr,
+               "usage: %s "
+               "-H <uri> | ([-h <host>] -p <port>) "
+               "-D <manager> "
+               "-w <passwd> "
+               "-b <searchbase> "
+               "-f <searchfilter> "
+               "[-l <loops>] "
+               "[-r <maxretries>] "
+               "[-t <delay>]\n",
                        name );
        exit( EXIT_FAILURE );
 }
@@ -61,8 +70,9 @@ main( int argc, char **argv )
        char            *filter  = NULL;
        int             loops = LOOPS;
        int             retries = RETRIES;
+       int             delay = 0;
 
-       while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "b:D:f:H:h:l:p:w:r:t:" )) != EOF ) {
                switch( i ) {
                case 'H':               /* the server uri */
                        uri = strdup( optarg );
@@ -100,6 +110,10 @@ main( int argc, char **argv )
                        retries = atoi( optarg );
                        break;
 
+               case 't':               /* delay in seconds */
+                       delay = atoi( optarg );
+                       break;
+
                default:
                        usage( argv[0] );
                        break;
@@ -118,14 +132,14 @@ main( int argc, char **argv )
        }
 
        do_search( uri, host, port, manager, passwd, sbase, filter,
-                       ( 10 * loops ), retries );
+                       ( 10 * loops ), retries, delay );
        exit( EXIT_SUCCESS );
 }
 
 
 static void
 do_search( char *uri, char *host, int port, char *manager, char *passwd,
-               char *sbase, char *filter, int maxloop, int maxretries )
+               char *sbase, char *filter, int maxloop, int maxretries, int delay )
 {
        LDAP    *ld = NULL;
        int     i = 0, do_retry = maxretries;
@@ -163,7 +177,9 @@ retry:;
                case LDAP_UNAVAILABLE:
                        if ( do_retry > 0 ) {
                                do_retry--;
-                               sleep( 1 );
+                               if ( delay != 0 ) {
+                                   sleep( delay );
+                               }
                                goto retry;
                        }
                /* fallthru */
@@ -196,5 +212,3 @@ retry:;
 
        ldap_unbind( ld );
 }
-
-
index 4121b4d17454a45d3be0998025618622eda084f1..c8d4d57f25cd0efc1568c1f0fa523d5f15f4f268 100644 (file)
@@ -80,7 +80,8 @@ usage( char *name )
                "[-j <maxchild>] "
                "[-l <loops>] "
                "-P <progdir> "
-               "[-r <maxretries>]\n",
+               "[-r <maxretries>]"
+               "[-t <delay>]\n",
                name );
        exit( EXIT_FAILURE );
 }
@@ -98,6 +99,7 @@ main( int argc, char **argv )
        char            *progdir = NULL;
        char            *loops = LOOPS;
        char            *retries = RETRIES;
+       char            *delay = "0";
        DIR                     *datadir;
        struct dirent   *file;
        char            *sfile = NULL;
@@ -132,7 +134,7 @@ main( int argc, char **argv )
        char            *moddn[MAXREQS];
        int             modnum = 0;
 
-       while ( (i = getopt( argc, argv, "D:d:H:h:j:l:P:p:r:w:" )) != EOF ) {
+       while ( (i = getopt( argc, argv, "D:d:H:h:j:l:P:p:r:t:w:" )) != EOF ) {
                switch( i ) {
                case 'D':               /* slapd manager */
                        manager = ArgDup( optarg );
@@ -166,10 +168,14 @@ main( int argc, char **argv )
                        port = strdup( optarg );
                        break;
 
-               case 'r':
+               case 'r':               /* the number of retries in case of error */
                        retries = strdup( optarg );
                        break;
 
+               case 't':               /* the delay in seconds between each retry */
+                       delay = strdup( optarg );
+                       break;
+
                case 'w':               /* the managers passwd */
                        passwd = ArgDup( optarg );
                        break;
@@ -264,6 +270,8 @@ main( int argc, char **argv )
        sargs[sanum++] = loops;
        sargs[sanum++] = "-r";
        sargs[sanum++] = retries;
+       sargs[sanum++] = "-t";
+       sargs[sanum++] = delay;
        sargs[sanum++] = "-b";
        sargs[sanum++] = NULL;          /* will hold the search base */
        sargs[sanum++] = "-f";
@@ -291,6 +299,8 @@ main( int argc, char **argv )
        rargs[ranum++] = loops;
        rargs[ranum++] = "-r";
        rargs[ranum++] = retries;
+       rargs[ranum++] = "-t";
+       rargs[ranum++] = delay;
        rargs[ranum++] = "-e";
        rargs[ranum++] = NULL;          /* will hold the read entry */
        rargs[ranum++] = NULL;
@@ -320,6 +330,8 @@ main( int argc, char **argv )
        margs[manum++] = loops;
        margs[manum++] = "-r";
        margs[manum++] = retries;
+       margs[manum++] = "-t";
+       margs[manum++] = delay;
        margs[manum++] = "-e";
        margs[manum++] = NULL;          /* will hold the modrdn entry */
        margs[manum++] = NULL;
@@ -349,6 +361,8 @@ main( int argc, char **argv )
        modargs[modanum++] = loops;
        modargs[modanum++] = "-r";
        modargs[modanum++] = retries;
+       modargs[modanum++] = "-t";
+       modargs[modanum++] = delay;
        modargs[modanum++] = "-e";
        modargs[modanum++] = NULL;              /* will hold the modify entry */
        modargs[modanum++] = "-a";;
@@ -380,6 +394,8 @@ main( int argc, char **argv )
        aargs[aanum++] = loops;
        aargs[aanum++] = "-r";
        aargs[aanum++] = retries;
+       aargs[aanum++] = "-t";
+       aargs[aanum++] = delay;
        aargs[aanum++] = "-f";
        aargs[aanum++] = NULL;          /* will hold the add data file */
        aargs[aanum++] = NULL;