diff options
author | Aki <please@ignore.pl> | 2020-07-07 17:47:21 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2020-07-07 17:47:21 +0200 |
commit | f6aa26cb6489338c66c07cea14f2892eec88cb01 (patch) | |
tree | adc2b975bc3c0399a69850c113a5b37dc6f6357d /main.c | |
parent | ebf5def64dbb2474e9105a4fbdd9b875c023d3e5 (diff) | |
download | plop-f6aa26cb6489338c66c07cea14f2892eec88cb01.zip plop-f6aa26cb6489338c66c07cea14f2892eec88cb01.tar.gz plop-f6aa26cb6489338c66c07cea14f2892eec88cb01.tar.bz2 |
Preparations to completely separate execution-related from plop itself
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -0,0 +1,58 @@ +#include <poll.h> +#include <string.h> + +#include <lauxlib.h> +#include <lua.h> +#include <lualib.h> + +#include "plop.h" + +/// Standard entry point for the program. +/// \param argc Argument count +/// \param argv Argument array +/// \return Error code +int main(int argc, char ** argv) +{ + lua_State * L = luaL_newstate(); + luaL_openlibs(L); + + if (3 != argc) + { + return 1; // TODO: Document error codes/print usage information + } + + if (LUA_OK != luaL_dofile(L, argv[2])) + { + return 2; // TODO: Document error codes/print usage information + } + + static const int max_clients = 200; + + int fdc = 0; + struct request * requests[max_clients]; + struct pollfd fdv[max_clients]; + + memset(requests, 0, sizeof(requests)); + memset(fdv, 0, sizeof(fdv)); + + fdv[0].fd = make_server(NULL, argv[1]); + fdv[0].events = POLLIN; + fdc++; + + if (-1 == fdv[0].fd) + { + return 1; // TODO: Document error codes/print usage information + } + + while (0 < fdc && -1 != poll(fdv, fdc, -1)) + { + int shift_by = 0; + + for (int i = 1; i < fdc; ++i) + { + shift_by = handle_client(L, &fdv[i], &requests[i], shift_by); + } + + fdc = handle_server(fdv, fdc - shift_by, max_clients); + } +} |