From 38c611cff6d03383e111dd4c9c9f2c5f8dfc87d6 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 21 Aug 2021 16:44:02 +0200 Subject: Moved error handling and lua state out of buffer_prepare_at_least --- stream.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'stream.c') 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); -- cgit v1.1