diff options
-rw-r--r-- | buffer.c | 16 | ||||
-rw-r--r-- | buffer.h | 4 | ||||
-rw-r--r-- | stream.c | 12 |
3 files changed, 14 insertions, 18 deletions
@@ -5,10 +5,6 @@ #include <string.h> #include <unistd.h> -#include <lua.h> - -#include "stream.h" - int buffer_grow(struct buffer * b) { int allocated = b->allocated + 1024; @@ -57,7 +53,7 @@ int buffer_read_more(int fd, struct buffer * in, int minimum_length) return length; } -int buffer_prepare_at_least(lua_State * L, int fd, struct buffer * in, int minimum_length, lua_KContext ctx) +int buffer_prepare_at_least(int fd, struct buffer * in, int minimum_length) { const int remaining_bytes = in->length - in->next; @@ -65,15 +61,7 @@ int buffer_prepare_at_least(lua_State * L, int fd, struct buffer * in, int minim { const int res = buffer_read_more(fd, in, minimum_length); if (-1 == res) - { - if (EWOULDBLOCK == errno || EAGAIN == errno) - return lua_yieldk(L, 0, ctx, stream_readk); - else - { - lua_pushstring(L, strerror(errno)); - return lua_error(L); - } - } + return res; } return remaining_bytes; @@ -1,7 +1,5 @@ #pragma once -#include <lua.h> - struct buffer { char * data; @@ -13,5 +11,5 @@ struct buffer int buffer_grow(struct buffer *); int buffer_read_more(const int, struct buffer *, const int); -int buffer_prepare_at_least(lua_State *, const int, struct buffer *, const int, lua_KContext); +int buffer_prepare_at_least(const int, struct buffer *, const int); int buffer_until(struct buffer *, const char *, const int); @@ -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); |