Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / test / t_conn_pool.c @ master

History | View | Annotate | Download (1.49 KB)

1
/* vim: set ai sw=4 sts=4 ts=4 :*/
2

    
3
#include <gdp/gdp.h>
4
#include <gdp/gdp_priv.h>
5
#include <ep/ep_app.h>
6
#include <ep/ep_dbg.h>
7
#include <ep/ep_thr.h>
8

    
9
#include <getopt.h>
10
#include <sysexits.h>
11

    
12

    
13
#define MAXTHREADS                20
14

    
15
int                        NLookups = 4;
16

    
17
void *
18
test_thread(void *tdata)
19
{
20
        int tno = (int) tdata;
21
        int i;
22
        char nbuf[200];
23
        EP_STAT estat;
24

    
25
        for (i = 0; i < NLookups; i++)
26
        {
27
                gdp_name_t gname;
28

    
29
                snprintf(nbuf, sizeof nbuf, "test.%x%02x", tno, i);
30
                estat = gdp_name_resolve(nbuf, gname);
31
                char ebuf[100];
32
                printf("test %x%02x  %s\n", tno, i,
33
                                ep_stat_tostr(estat, ebuf, sizeof ebuf));
34
        }
35
        return NULL;
36
}
37

    
38
void
39
usage(void)
40
{
41
        fprintf(stderr,
42
                        "Usage: %s [-D dbgspec] [-n nlookups] [-t nthreads]\n",
43
                        ep_app_getprogname());
44
        exit(EX_USAGE);
45
}
46

    
47
int
48
main(int argc, char **argv)
49
{
50
        int tno;
51
        int nThreads = 4;
52
        int opt;
53
        bool show_usage = false;
54
        EP_THR thr_id[MAXTHREADS];
55

    
56
        gdp_init_phase_0(NULL, 0);
57
        _gdp_name_init(NULL);
58

    
59
        while ((opt = getopt(argc, argv, "D:n:t:")) > 0)
60
        {
61
                switch (opt)
62
                {
63
                        case 'D':
64
                                ep_dbg_set(optarg);
65
                                break;
66

    
67
                        case 'n':
68
                                NLookups = atoi(optarg);
69
                                break;
70

    
71
                        case 't':
72
                                nThreads = atoi(optarg);
73
                                if (nThreads > MAXTHREADS)
74
                                        nThreads = MAXTHREADS;
75
                                break;
76

    
77
                        default:
78
                                show_usage = true;
79
                                break;
80
                }
81
        }
82
        argc -= optind;
83
        argv += optind;
84

    
85
        if (show_usage)
86
                usage();
87

    
88
        for (tno = 0; tno < nThreads; tno++)
89
                ep_thr_spawn(&thr_id[tno], test_thread, (void *) tno);
90
        for (tno = 0; tno < nThreads; tno++)
91
                pthread_join(thr_id[tno], NULL);
92
        return 0;
93
}