summaryrefslogtreecommitdiffhomepage
path: root/stream.c
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-08-21 16:44:02 +0200
committerAki <please@ignore.pl>2021-08-21 16:44:02 +0200
commit38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6 (patch)
tree57439eec383ce29988c7b486278752090266577f /stream.c
parent506fa912f42d31fd1760d9b3b9f3fbcfe43da2be (diff)
downloadplop-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.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/stream.c b/stream.c
index 9cf475e..eb1d0ea 100644
--- a/stream.c
+++ b/stream.c
@@ -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);