diff options
author | Aki <please@ignore.pl> | 2021-08-15 20:04:35 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-08-15 20:04:35 +0200 |
commit | d4e5c2f12a284b64f6b68a994d63fe7babf7f46d (patch) | |
tree | 465b7f22baa92ada276b4f5be1a15a618225f100 /plop.c | |
parent | 906eb598f150931e821446e9dcf022ea9052ab36 (diff) | |
download | plop-d4e5c2f12a284b64f6b68a994d63fe7babf7f46d.zip plop-d4e5c2f12a284b64f6b68a994d63fe7babf7f46d.tar.gz plop-d4e5c2f12a284b64f6b68a994d63fe7babf7f46d.tar.bz2 |
Switched back to poll from epoll
Diffstat (limited to 'plop.c')
-rw-r--r-- | plop.c | 38 |
1 files changed, 16 insertions, 22 deletions
@@ -6,7 +6,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sys/epoll.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> @@ -21,7 +20,9 @@ struct plop plop = { .handler = PLOP_DEFAULT_HANDLER, .L = NULL, - .efd = -1, + .fds = NULL, + .data = NULL, + .nfds = 0, }; /// Initializes new Lua state for the server. @@ -147,7 +148,7 @@ void plop_drop_thread(const int ref) /// Handles client events. /// \param c Connection associated with the client -/// \return -1 if an error occured +/// \return -1 if an error occured, 1 if expecting to continue int plop_handle_client(struct connection * c) { int nargs = 0; @@ -174,7 +175,7 @@ int plop_handle_client(struct connection * c) } case LUA_YIELD: { - return 0; + return 1; } default: { @@ -199,8 +200,14 @@ int plop_handle_client(struct connection * c) /// \return -1 if an error occured int plop_handle_server(const int server) { - struct epoll_event e; - e.events = EPOLLIN | EPOLLOUT; // TODO: Add EPOLLHUP? + int i = 1; // Always skip server descriptor. + for (; i <= plop.nfds; ++i) + { + if (-1 == plop.fds[i].fd) + break; + if (plop.nfds == i) + return 0; + } const int client = accept(server, NULL, NULL); if (-1 == client) @@ -234,30 +241,17 @@ int plop_handle_server(const int server) } } - if (-1 == fcntl(client, F_SETFL, (fcntl(client, F_GETFL, 0) | O_NONBLOCK))) - { - close(client); - return 0; // TODO: Retriage this error at some point. - } - struct connection * connection = connection_new(client); if (NULL == connection) - { return -1; - } - connection->L = lua_newthread(plop.L); if (NULL == connection->L) - return -1; // TODO: Revisit error handling. + return -1; // TODO: Revisit error handling. connection->ref = luaL_ref(plop.L, LUA_REGISTRYINDEX); connection->fd = client; connection->push = 1; - e.data.ptr = connection; - - if (-1 == epoll_ctl(plop.efd, EPOLL_CTL_ADD, client, &e)) - { - return -1; - } + plop.fds[i].fd = client; + plop.data[i] = connection; return 0; } |