diff options
-rw-r--r-- | main.c | 27 |
1 files changed, 19 insertions, 8 deletions
@@ -1,4 +1,4 @@ -#include <string.h> +#include <stdio.h> #include <sys/epoll.h> #include <lauxlib.h> @@ -7,6 +7,16 @@ #include "plop.h" +/// Prints program usage to standard error. +/// \param name Name of the executable from argv +static void usage(char * name) +{ + // TODO: Extend command line interface with e.g. getopt. + dprintf(2, + "Usage: %s <port> <handler>\n", + name); +} + /// Standard entry point for the program. /// \param argc Argument count /// \param argv Argument array @@ -18,19 +28,20 @@ int main(int argc, char ** argv) if (3 != argc) { - return 1; // TODO: Document error codes/print usage information + usage(argv[0]); + return 1; // TODO: Handle errors properly in main(). } if (LUA_OK != load_handler(L, argv[2])) { - return 2; // TODO: Document error codes/print usage information + return 2; } const int efd = epoll_create1(0); if (-1 == efd) { - return 3; // TODO: Handle errors properly + return 3; } struct epoll_event e; @@ -40,7 +51,7 @@ int main(int argc, char ** argv) if (-1 == epoll_ctl(efd, EPOLL_CTL_ADD, server, &e)) { - return 4; // TODO: Handle errors properly + return 4; } static const int MAX_EVENTS = 20; @@ -52,7 +63,7 @@ int main(int argc, char ** argv) if (-1 == evc) { - return 5; // TODO: Handle errors properly + return 5; } for (int i = 0; i < evc; ++i) @@ -61,14 +72,14 @@ int main(int argc, char ** argv) { if (-1 == handle_server(L, efd, server)) { - return 6; // TODO: Handle errors properly + return 6; } } else { if (-1 == handle_client(L, &events[i])) { - return 7; // TODO: Handle errors properly + return 7; } } } |