2 Startup, and shutdown the memcached servers.
5 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
12 #include <libmemcached/memcached.h>
16 void server_startup(server_startup_st
*construct
)
20 if ((construct
->server_list
= getenv("MEMCACHED_SERVERS")))
22 printf("servers %s\n", construct
->server_list
);
23 construct
->servers
= memcached_servers_parse(construct
->server_list
);
24 construct
->server_list
= NULL
;
30 char server_string_buffer
[8096];
32 end_ptr
= server_string_buffer
;
34 for (x
= 0; x
< construct
->count
; x
++)
36 char buffer
[1024]; /* Nothing special for number */
42 sprintf(buffer
, "memcached -d -P /tmp/%umemc.pid -t 1 -U %u -m 128", x
, x
+ TEST_PORT_BASE
);
44 sprintf(buffer
, "memcached -d -P /tmp/%umemc.pid -t 1 -U %u", x
, x
+ TEST_PORT_BASE
);
49 sprintf(buffer
, "memcached -d -P /tmp/%umemc.pid -t 1 -p %u -m 128", x
, x
+ TEST_PORT_BASE
);
51 sprintf(buffer
, "memcached -d -P /tmp/%umemc.pid -t 1 -p %u", x
, x
+ TEST_PORT_BASE
);
54 status
= system(buffer
);
55 count
= sprintf(end_ptr
, "localhost:%u,", x
+ TEST_PORT_BASE
);
60 construct
->server_list
= strdup(server_string_buffer
);
62 printf("servers %s\n", construct
->server_list
);
63 construct
->servers
= memcached_servers_parse(construct
->server_list
);
66 assert(construct
->servers
);
70 for (x
= 0; x
< memcached_server_list_count(construct
->servers
); x
++)
72 printf("\t%s : %u\n", construct
->servers
[x
].hostname
, construct
->servers
[x
].port
);
73 assert(construct
->servers
[x
].fd
== -1);
74 assert(construct
->servers
[x
].cursor_active
== 0);
80 void server_shutdown(server_startup_st
*construct
)
84 if (construct
->server_list
)
86 for (x
= 0; x
< construct
->count
; x
++)
88 char buffer
[1024]; /* Nothing special for number */
89 sprintf(buffer
, "cat /tmp/%umemc.pid | xargs kill", x
);
92 sprintf(buffer
, "/tmp/%umemc.pid", x
);
96 free(construct
->server_list
);