* Start daemon, multiple client connects, requests, disconnects
*/
-#define TEST5_MAX_CLIENTS 10
+#define TEST5_VALID_CLIENTS 10
+#define TEST5_MAX_CLIENTS 100
struct test5_pkt {
uint32_t len;
state->done = true;
}
-static int test5_client(const char *sockpath, int id)
+static int test5_client(const char *sockpath, int id, pid_t pid_server,
+ pid_t *client_pid)
{
pid_t pid;
int fd[2];
close(fd[0]);
state.fd = -1;
- sleep(10);
+ while (kill(pid_server, 0) == 0 || errno != ESRCH) {
+ sleep(1);
+ }
exit(0);
}
close(fd[0]);
+ *client_pid = pid;
return ret;
}
struct test5_server_state *state =
(struct test5_server_state *)private_data;
- if (state->num_clients == TEST5_MAX_CLIENTS) {
+ if (state->num_clients == TEST5_VALID_CLIENTS) {
return false;
}
state->num_clients += 1;
- assert(state->num_clients <= TEST5_MAX_CLIENTS);
+ assert(state->num_clients <= TEST5_VALID_CLIENTS);
return true;
}
pid_t pid_server, pid;
int fd[2], ret, i;
ssize_t n;
+ pid_t client_pid[TEST5_MAX_CLIENTS];
pid = getpid();
close(fd[0]);
- for (i=0; i<100; i++) {
- ret = test5_client(sockpath, i);
- if (i < TEST5_MAX_CLIENTS) {
+ for (i=0; i<TEST5_MAX_CLIENTS; i++) {
+ ret = test5_client(sockpath, i, pid_server, &client_pid[i]);
+ if (i < TEST5_VALID_CLIENTS) {
assert(ret == i+1);
} else {
assert(ret == 0);
}
}
- for (i=0; i<100; i++) {
+ for (i=TEST5_MAX_CLIENTS-1; i>=0; i--) {
+ kill(client_pid[i], SIGKILL);
+
pid = wait(&ret);
assert(pid != -1);
}