diff options
author | Brian Cully <bjc@kublai.com> | 2008-04-14 21:52:55 -0400 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-04-14 21:52:55 -0400 |
commit | 6ba98a9f9f48e13738d9736cba9c45b5e94f42f2 (patch) | |
tree | 86d7c281bcdbf67eb53cee064aa905e740ec5ccf /tests/.svn/text-base/randnast.c.svn-base | |
download | nastd-6ba98a9f9f48e13738d9736cba9c45b5e94f42f2.tar.gz nastd-6ba98a9f9f48e13738d9736cba9c45b5e94f42f2.zip |
Initial import
Diffstat (limited to 'tests/.svn/text-base/randnast.c.svn-base')
-rw-r--r-- | tests/.svn/text-base/randnast.c.svn-base | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/.svn/text-base/randnast.c.svn-base b/tests/.svn/text-base/randnast.c.svn-base new file mode 100644 index 0000000..dd39fc6 --- /dev/null +++ b/tests/.svn/text-base/randnast.c.svn-base @@ -0,0 +1,69 @@ +#include <nastd.h> + +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +#include <time.h> +#include <unistd.h> + +char letters[] = "abcdefghijklmnopqrstuvwxyz0123456789-_."; + +int +main(int argc, char *argv[]) +{ + nasth *nasthole; + struct timeval before, after; + nast_options opts; + int i, rc; + + nasthole = nast_sphincter_new(NULL); + if (nasthole == NULL) { + fprintf(stderr, "ERROR: Couldn't connect to nasthole.\n"); + return 2; + } + + srand(time(NULL)); + + for (;;) { + /* Get the default options. */ + rc = nast_options_get(nasthole, &opts); + if (rc == -1) { + fprintf(stderr, "ERROR: Couldn't get options: %s.\n", + nast_errmsg(nasthole)); + nast_sphincter_close(nasthole); + return 2; + } + + for (i = 0; i < 10; i++) { + char uname[32]; + int i, maxlen; + + maxlen = rand() % sizeof(uname); + for (i = 0; i < maxlen-1; i++) + uname[i] = letters[rand() % sizeof(letters)]; + uname[maxlen] = '\0'; + + gettimeofday(&before, NULL); + rc = nast_get(nasthole, uname); + gettimeofday(&after, NULL); + if (rc == -1) { + fprintf(stderr, + "ERROR: Couldn't perform query: %s.\n", + nast_errmsg(nasthole)); + nast_sphincter_close(nasthole); + return 2; + } + + after.tv_sec -= before.tv_sec; + after.tv_usec -= before.tv_usec; + if (after.tv_usec < 0) { + after.tv_sec--; + after.tv_usec += 1000000; + } + fprintf(stderr, "Request time: %2ld.%06ld seconds.\n", + after.tv_sec, after.tv_usec); + } + } + nast_sphincter_close(nasthole); + return 0; +} |