diff options
author | Aki <please@ignore.pl> | 2021-08-21 16:44:02 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2021-08-21 16:44:02 +0200 |
commit | 38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6 (patch) | |
tree | 57439eec383ce29988c7b486278752090266577f /stream.c | |
parent | 506fa912f42d31fd1760d9b3b9f3fbcfe43da2be (diff) | |
download | plop-38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6.zip plop-38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6.tar.gz plop-38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6.tar.bz2 |
Moved error handling and lua state out of buffer_prepare_at_least
Diffstat (limited to 'stream.c')
-rw-r--r-- | stream.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -155,7 +155,17 @@ int stream_readk(lua_State * L, int status, lua_KContext ctx) int remaining_bytes; do { - remaining_bytes = buffer_prepare_at_least(L, s->fd, &s->in, (int) pattern_length, ctx); + remaining_bytes = buffer_prepare_at_least(s->fd, &s->in, (int) pattern_length); + if (-1 == remaining_bytes) + { + if (EWOULDBLOCK == errno || EAGAIN == errno) + return lua_yieldk(L, 0, ctx, stream_readk); + else + { + lua_pushstring(L, strerror(errno)); + return lua_error(L); + } + } offset = buffer_until(&s->in, pattern, (int) pattern_length); } while (-1 == offset && 0 < remaining_bytes); |