2 Startup, and shutdown the memcached servers.
5 #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10
15 #include <libmemcached/memcached.h>
19 void server_startup(server_startup_st
*construct
)
23 if ((construct
->server_list
= getenv("MEMCACHED_SERVERS")))
25 printf("servers %s\n", construct
->server_list
);
26 construct
->servers
= memcached_servers_parse(construct
->server_list
);
27 construct
->server_list
= NULL
;
33 char server_string_buffer
[8096];
35 end_ptr
= server_string_buffer
;
37 for (x
= 0; x
< construct
->count
; x
++)
39 char buffer
[1024]; /* Nothing special for number */
43 sprintf(buffer
, "/tmp/%umemc.pid", x
);
44 if (access(buffer
, F_OK
) == 0)
46 FILE *fp
= fopen(buffer
, "r");
51 if (fgets(buffer
, sizeof(buffer
), fp
) != NULL
)
53 pid_t pid
= (pid_t
)atol(buffer
);
64 sprintf(buffer
, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128",
65 MEMCACHED_BINARY
, x
, x
+ TEST_PORT_BASE
, x
+ TEST_PORT_BASE
);
69 sprintf(buffer
, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u",
70 MEMCACHED_BINARY
, x
, x
+ TEST_PORT_BASE
, x
+ TEST_PORT_BASE
);
72 fprintf(stderr
, "STARTING SERVER: %s\n", buffer
);
73 status
= system(buffer
);
74 count
= sprintf(end_ptr
, "localhost:%u,", x
+ TEST_PORT_BASE
);
79 construct
->server_list
= strdup(server_string_buffer
);
81 printf("servers %s\n", construct
->server_list
);
82 construct
->servers
= memcached_servers_parse(construct
->server_list
);
85 assert(construct
->servers
);
87 srandom((unsigned int)time(NULL
));
89 for (x
= 0; x
< memcached_server_list_count(construct
->servers
); x
++)
91 printf("\t%s : %u\n", construct
->servers
[x
].hostname
, construct
->servers
[x
].port
);
92 assert(construct
->servers
[x
].fd
== -1);
93 assert(construct
->servers
[x
].cursor_active
== 0);
99 void server_shutdown(server_startup_st
*construct
)
103 if (construct
->server_list
)
105 for (x
= 0; x
< construct
->count
; x
++)
107 char buffer
[1024]; /* Nothing special for number */
108 sprintf(buffer
, "cat /tmp/%umemc.pid | xargs kill", x
);
109 /* We have to check the return value of this or the compiler will yell */
110 int sys_ret
= system(buffer
);
111 assert(sys_ret
!= -1);
112 sprintf(buffer
, "/tmp/%umemc.pid", x
);
116 free(construct
->server_list
);