diff options
-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); } } |