From 0b256dd68b7ed1e1e0875050204a3620c164d30f Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 May 2020 10:34:20 +0200 Subject: Fixed style inconsistencies and cleared up selected parts of code --- http.h | 1 - plop.c | 19 +++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/http.h b/http.h index fd75db9..14a4769 100644 --- a/http.h +++ b/http.h @@ -12,7 +12,6 @@ enum status STATUS_VERSION_NOT_SUPPORTED = 505, }; -extern const char * method_str[]; extern const char * status_str[]; int respond_only_status(int, enum status); diff --git a/plop.c b/plop.c index 8d21362..fb62b01 100644 --- a/plop.c +++ b/plop.c @@ -116,7 +116,9 @@ int handle_client(struct pollfd * pfd, char ** data, const int shift_by) int handle_server(struct pollfd * fdv, int fdc, const int size) { if (0 == fdv[0].revents) + { return fdc; + } while (size > fdc + 1 && -1 != (fdv[fdc].fd = accept(fdv[0].fd, NULL, NULL))) { @@ -143,18 +145,23 @@ int main(int argc, char ** argv) if (2 != argc) { - return 4; + return 1; // TODO: Document error codes/print usage information } - char * data[200] = {0}; - struct pollfd fdv[200]; + static const int max_clients = 200; + + int fdc = 0; + char * data[max_clients]; + struct pollfd fdv[max_clients]; + + memset(data, 0, sizeof(data)); memset(fdv, 0, sizeof(fdv)); fdv[0].fd = make_server(NULL, argv[1]); fdv[0].events = POLLIN; - int fdc = 1; + fdc++; - while (-1 != fdc && -1 != poll(fdv, fdc, -1)) + while (0 < fdc && -1 != poll(fdv, fdc, -1)) { int shift_by = 0; @@ -163,6 +170,6 @@ int main(int argc, char ** argv) shift_by = handle_client(&fdv[i], &data[i], shift_by); } - fdc = handle_server(fdv, fdc - shift_by, 200); + fdc = handle_server(fdv, fdc - shift_by, max_clients); } } -- cgit v1.1