summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2020-08-16 02:16:47 +0200
committerAki <please@ignore.pl>2020-08-16 02:16:47 +0200
commit0c5f075ed0aa99b5adc537a3173e0bd11e198efd (patch)
treebf10a356163348ef7d73009d71cfcadb21df5b54
parent67671f75955eaeb5f44bcd8717417f7ba7007c4b (diff)
downloadplop-0c5f075ed0aa99b5adc537a3173e0bd11e198efd.zip
plop-0c5f075ed0aa99b5adc537a3173e0bd11e198efd.tar.gz
plop-0c5f075ed0aa99b5adc537a3173e0bd11e198efd.tar.bz2
Cleaned up main and added simple usage message
-rw-r--r--main.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/main.c b/main.c
index ebe6bfe..4b5cb59 100644
--- a/main.c
+++ b/main.c
@@ -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;
}
}
}