diff options
author | Aki <please@ignore.pl> | 2021-03-05 00:48:57 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-03-05 00:48:57 +0100 |
commit | 0c9cc5dd53a4f34c9ebc28c24f31a8c62e5ffe3a (patch) | |
tree | 78ee8eb91d31689f9c99ff8de57a80bc5ce96af3 | |
parent | 2906145eec3c752f6c197c39611984aa91ab5a6e (diff) | |
download | plop-0c9cc5dd53a4f34c9ebc28c24f31a8c62e5ffe3a.zip plop-0c9cc5dd53a4f34c9ebc28c24f31a8c62e5ffe3a.tar.gz plop-0c9cc5dd53a4f34c9ebc28c24f31a8c62e5ffe3a.tar.bz2 |
Implemented flush continuation
-rw-r--r-- | plop.c | 2 | ||||
-rw-r--r-- | stream.c | 33 |
2 files changed, 23 insertions, 12 deletions
@@ -195,7 +195,7 @@ int plop_handle_client(lua_State * L, struct epoll_event * event) int plop_handle_server(lua_State * L, const int efd, const int server) { struct epoll_event e; - e.events = EPOLLIN; // TODO: Add EPOLLOUT? + e.events = EPOLLIN | EPOLLOUT; // TODO: Add EPOLLHUP? const int client = accept(server, NULL, NULL); if (-1 == client) @@ -352,11 +352,32 @@ int stream_flush(lua_State * L) return lua_error(L); } + return stream_flushk(L, LUA_OK, (lua_KContext) s); +} + +/// Continuation of the flush operation. +/// \param L Lua state in which Stream resides +/// \param status Unused +/// \param ctx Address of the stream context in memory +/// \return Number of the results pushed to the stack +int stream_flushk(lua_State * L, const int status, lua_KContext ctx) +{ + struct stream * s = (struct stream *) ctx; + (void) status; + const int bytes_written = write(s->fd, s->out.data, s->out.length); if (-1 == bytes_written) { - // TODO: Errors and yield + if (EAGAIN == errno || EWOULDBLOCK == errno) + { + return lua_yieldk(L, 0, ctx, stream_flushk); + } + else + { + lua_pushstring(L, strerror(errno)); + return lua_error(L); + } } else { @@ -367,16 +388,6 @@ int stream_flush(lua_State * L) return 0; } -/// Continuation of the flush operation. -/// \param L Lua state in which Stream resides -/// \param status Unused -/// \param ctx TODO -/// \return Number of the results pushed to the stack -int stream_flushk(lua_State * L, const int status, lua_KContext ctx) -{ - return 0; -} - /// Discards the contents of output buffer without writing it anywhere. /// \param L Lua state in which Stream resides /// \return Number of the results pushed to the stack |