aboutsummaryrefslogtreecommitdiff
path: root/src/server.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/src/server.c b/src/server.c
index e0b8738..6df7916 100644
--- a/src/server.c
+++ b/src/server.c
@@ -11,12 +11,12 @@
#include "utils.h"
#include "log.h"
-typedef struct client_thread_args {
+typedef struct client_thread {
pthread_t self;
psocket client_sock;
char host_buf[NI_MAXHOST], service_buf[NI_MAXSERV];
const server_ctx *server_ctx;
-} client_thread_args;
+} client_thread;
typedef struct server_event {
const server_ctx **srv_ctx;
@@ -25,14 +25,15 @@ typedef struct server_event {
typedef struct client_event {
const psocket *fwd_sock;
- const client_thread_args *client_args;
+ const client_thread *client_args;
} client_event;
static forward_state
-fwd_state_string(const forward_state c_state, const client_thread_args *args,
+fwd_state_string(const forward_state c_state, const client_thread *args,
const psocket *fwd);
static int
-server_mainloop(event_ctx *ev_ctx, const server_ctx *srv_ctx[], size_t siz);
+server_mainloop(event_ctx *ev_ctx, const server_ctx *srv_ctx[], size_t siz)
+ __attribute__((noreturn));
static int server_accept_client(event_ctx *ev_ctx, int fd, void *user_data);
static void *
client_mainloop(void *arg);
@@ -153,7 +154,7 @@ pid_t server_daemonize(event_ctx *ev_ctx, server_ctx *srv_ctx[], size_t siz)
}
static forward_state
-fwd_state_string(const forward_state c_state, const client_thread_args *args,
+fwd_state_string(const forward_state c_state, const client_thread *args,
const psocket *fwd)
{
switch (c_state) {
@@ -197,7 +198,7 @@ static int server_mainloop(event_ctx *ev_ctx, const server_ctx *srv_ctx[], size_
rc = event_loop(ev_ctx, server_accept_client, &ev_srv);
event_free(&ev_ctx);
- return rc;
+ exit(rc);
}
static int server_accept_client(event_ctx *ev_ctx, int fd, void *user_data)
@@ -205,7 +206,7 @@ static int server_accept_client(event_ctx *ev_ctx, int fd, void *user_data)
size_t i;
int s;
server_event *ev_srv = (server_event *) user_data;
- client_thread_args *args;
+ client_thread *args;
const server_ctx *srv_ctx;
(void) ev_ctx;
@@ -214,7 +215,7 @@ static int server_accept_client(event_ctx *ev_ctx, int fd, void *user_data)
for (i = 0; i < ev_srv->siz; ++i) {
srv_ctx = ev_srv->srv_ctx[i];
if (srv_ctx->sock.fd == fd) {
- args = (client_thread_args *) calloc(1, sizeof(*args));
+ args = (client_thread *) calloc(1, sizeof(*args));
assert(args);
if (socket_accept_in(&srv_ctx->sock,
@@ -260,19 +261,19 @@ error:
static void *
client_mainloop(void *arg)
{
- client_thread_args *args;
+ client_thread *args;
client_event ev_cli;
int s;
event_ctx *ev_ctx = NULL;
psocket fwd;
assert(arg);
- args = (client_thread_args *) arg;
+ args = (client_thread *) arg;
pthread_detach(args->self);
event_init(&ev_ctx);
if (event_setup(ev_ctx)) {
- E_STRERR("Client event descriptor creation for server fd %d",
+ E_STRERR("Client event context creation for server fd %d",
args->server_ctx->sock.fd);
goto finish;
}
@@ -289,7 +290,7 @@ client_mainloop(void *arg)
args->server_ctx->fwd_ctx->service_buf, fwd.fd);
if (event_add_sock(ev_ctx, &fwd)) {
- E_STRERR("Forward event descriptor add to %s:%s forward fd %d",
+ E_STRERR("Forward event context add to %s:%s forward fd %d",
args->server_ctx->fwd_ctx->host_buf,
args->server_ctx->fwd_ctx->service_buf, fwd.fd);
goto finish;
@@ -307,7 +308,7 @@ client_mainloop(void *arg)
goto finish;
}
if (event_add_sock(ev_ctx, &args->client_sock)) {
- E_STRERR("Forward event descriptor add to %s:%s forward fd %d",
+ E_STRERR("Forward event context add to %s:%s forward fd %d",
args->server_ctx->fwd_ctx->host_buf,
args->server_ctx->fwd_ctx->service_buf, fwd.fd);
goto finish;