diff options
author | Aki <please@ignore.pl> | 2020-05-06 10:34:20 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-05-06 10:34:20 +0200 |
commit | 0b256dd68b7ed1e1e0875050204a3620c164d30f (patch) | |
tree | 3107413d531893b097b6f0f1e6daf9845648a7ac | |
parent | c683087e78d8338a3a118178200a3137b666331e (diff) | |
download | plop-0b256dd68b7ed1e1e0875050204a3620c164d30f.zip plop-0b256dd68b7ed1e1e0875050204a3620c164d30f.tar.gz plop-0b256dd68b7ed1e1e0875050204a3620c164d30f.tar.bz2 |
Fixed style inconsistencies and cleared up selected parts of code
-rw-r--r-- | http.h | 1 | ||||
-rw-r--r-- | plop.c | 19 |
2 files changed, 13 insertions, 7 deletions
@@ -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); @@ -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); } } |