1
0
forked from aniani/gmnisrv

Log response body size in bytes

This commit is contained in:
Drew DeVault 2020-09-26 14:41:17 -04:00
parent dfab99ace5
commit 9bed26b8d9
2 changed files with 5 additions and 1 deletions

View File

@ -32,6 +32,7 @@ struct gmnisrv_client {
enum gemini_status status; enum gemini_status status;
char *meta; char *meta;
int bodyfd; int bodyfd;
size_t bbytes;
struct gmnisrv_host *host; struct gmnisrv_host *host;
char *path; char *path;

View File

@ -152,6 +152,7 @@ accept_client(struct gmnisrv_server *server, int fd)
client->pollfd = pollfd; client->pollfd = pollfd;
client->addrlen = addrlen; client->addrlen = addrlen;
client->server = server; client->server = server;
client->bodyfd = -1;
clock_gettime(CLOCK_MONOTONIC, &client->ctime); clock_gettime(CLOCK_MONOTONIC, &client->ctime);
memcpy(&client->addr, &addr, sizeof(addr)); 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); clock_gettime(CLOCK_MONOTONIC, &now);
timespec_diff(&client->ctime, &now, &diff); timespec_diff(&client->ctime, &now, &diff);
int ms = diff.tv_sec * 1000 + (int)(diff.tv_nsec / 1.0e6); 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->host ? client->host->hostname : "(none)",
client->path ? client->path : "(none)", client->path ? client->path : "(none)",
(int)client->status, client->meta); (int)client->status, client->meta);
@ -446,6 +448,7 @@ client_writable(struct gmnisrv_server *server, struct gmnisrv_client *client)
disconnect_client(server, client); disconnect_client(server, client);
return; return;
} }
client->bbytes += n;
client->bufln = n; client->bufln = n;
client->bufix = 0; client->bufix = 0;
} }