aboutsummaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-04-24 23:33:59 +0200
committerToni Uhlig <matzeton@googlemail.com>2018-04-24 23:33:59 +0200
commit6e7b5102c33a510f93b7b418d0bfc082ae2595f7 (patch)
tree86f08ae3138d6be89cad0a4cc05fd19ea78d2648 /src/server.c
parentb14059ea3a1f2e0a41d90ababf27473c026042d0 (diff)
POTD skeleton #27.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/server.c b/src/server.c
index 49837e6..073229c 100644
--- a/src/server.c
+++ b/src/server.c
@@ -99,8 +99,8 @@ int server_setup_epoll(server_ctx *ctx[], size_t siz)
E_GAIERR(s, "Convert socket address to string");
return -2;
}
- N("Redirector service listening on %s:%s",
- ctx[i]->host_buf, ctx[i]->service_buf);
+ N("Redirector service listening on %s:%s: %d",
+ ctx[i]->host_buf, ctx[i]->service_buf, ev.data.fd);
s = epoll_ctl(fd, EPOLL_CTL_ADD, ctx[i]->sock.fd, &ev);
if (s) {
@@ -124,8 +124,9 @@ int server_mainloop_epoll(int epoll_fd, server_ctx *ctx[], size_t siz)
assert(ctx);
assert(siz > 0 && siz < POTD_MAXFD);
- signal(SIGPIPE, SIG_IGN);
+ assert( signal(SIGPIPE, SIG_IGN) != SIG_ERR );
sigemptyset(&eset);
+
while (1) {
int n, i;
@@ -152,10 +153,8 @@ int server_mainloop_epoll(int epoll_fd, server_ctx *ctx[], size_t siz)
}
}
- free(events);
return 0;
error:
- free(events);
return 1;
}
@@ -168,11 +167,12 @@ static int server_accept_client(server_ctx *ctx[],
for (i = 0; i < siz; ++i) {
if (ctx[i]->sock.fd == event->data.fd) {
- args = (client_thread_args *) calloc(1, sizeof(client_thread_args));
+ args = (client_thread_args *) calloc(1, sizeof(*args));
+ assert(args);
if (socket_accept_in(&ctx[i]->sock, &args->client_psock)) {
E_STRERR("Could not accept client connection");
- return 0;
+ goto error;
}
args->server_ctx = ctx[i];
@@ -182,10 +182,10 @@ static int server_accept_client(server_ctx *ctx[],
E_GAIERR(s, "Convert socket address to string");
goto error;
}
- N("New connection from %s:%s to %s:%s: %d",
- args->host_buf, args->service_buf,
- ctx[i]->host_buf, ctx[i]->service_buf,
- args->client_psock.fd);
+ N2("New connection from %s:%s to %s:%s: %d",
+ args->host_buf, args->service_buf,
+ ctx[i]->host_buf, ctx[i]->service_buf,
+ args->client_psock.fd);
if (pthread_create(&args->self, NULL,
client_mainloop_epoll, args))