From 9bed26b8d91ff4f688c200ff8183e3134edf1d55 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 26 Sep 2020 14:41:17 -0400 Subject: [PATCH] Log response body size in bytes --- include/server.h | 1 + src/server.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/server.h b/include/server.h index 0317de9..ef5781a 100644 --- a/include/server.h +++ b/include/server.h @@ -32,6 +32,7 @@ struct gmnisrv_client { enum gemini_status status; char *meta; int bodyfd; + size_t bbytes; struct gmnisrv_host *host; char *path; diff --git a/src/server.c b/src/server.c index 7e28280..8ddc422 100644 --- a/src/server.c +++ b/src/server.c @@ -152,6 +152,7 @@ accept_client(struct gmnisrv_server *server, int fd) client->pollfd = pollfd; client->addrlen = addrlen; client->server = server; + client->bodyfd = -1; clock_gettime(CLOCK_MONOTONIC, &client->ctime); memcpy(&client->addr, &addr, sizeof(addr)); @@ -181,7 +182,8 @@ disconnect_client(struct gmnisrv_server *server, struct gmnisrv_client *client) clock_gettime(CLOCK_MONOTONIC, &now); timespec_diff(&client->ctime, &now, &diff); int ms = diff.tv_sec * 1000 + (int)(diff.tv_nsec / 1.0e6); - client_log(&client->addr, "%dms %s %s %02d %s", ms, + client_log(&client->addr, "%3dms %5d %s %s %02d %s", + ms, client->bbytes, client->host ? client->host->hostname : "(none)", client->path ? client->path : "(none)", (int)client->status, client->meta); @@ -446,6 +448,7 @@ client_writable(struct gmnisrv_server *server, struct gmnisrv_client *client) disconnect_client(server, client); return; } + client->bbytes += n; client->bufln = n; client->bufix = 0; }