diff options
-rw-r--r-- | buffer.c | 34 | ||||
-rw-r--r-- | buffer.h | 2 |
2 files changed, 16 insertions, 20 deletions
@@ -30,18 +30,14 @@ int buffer_grow(struct buffer * b) return allocated; } -int buffer_read_more(lua_State * L, int fd, struct buffer * in, int minimum_length, lua_KContext ctx) +int buffer_read_more(int fd, struct buffer * in, int minimum_length) { const int free_space = in->allocated + in->offset - in->length - 1; while (free_space < minimum_length) { - const int res = buffer_grow(in); - if (-1 == res) - { - lua_pushstring(L, strerror(errno)); - return lua_error(L); - } + if (-1 == buffer_grow(in)) + return -1; } if (0 < in->offset) @@ -54,17 +50,7 @@ int buffer_read_more(lua_State * L, int fd, struct buffer * in, int minimum_leng int length = read(fd, in->data + in->length, free_space); if (-1 == length) - { - if (EWOULDBLOCK == errno || EAGAIN == errno) - { - return lua_yieldk(L, 0, ctx, stream_readk); - } - else - { - lua_pushstring(L, strerror(errno)); - return lua_error(L); - } - } + return -1; in->length += length; @@ -77,7 +63,17 @@ int buffer_prepare_at_least(lua_State * L, int fd, struct buffer * in, int minim if (remaining_bytes < minimum_length) { - return buffer_read_more(L, fd, in, minimum_length, ctx); + 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 remaining_bytes; @@ -12,6 +12,6 @@ struct buffer }; int buffer_grow(struct buffer *); -int buffer_read_more(lua_State *, const int, struct buffer *, const int, lua_KContext); +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_until(struct buffer *, const char *, const int); |