summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--buffer.c34
-rw-r--r--buffer.h2
2 files changed, 16 insertions, 20 deletions
diff --git a/buffer.c b/buffer.c
index 6835933..a3f527f 100644
--- a/buffer.c
+++ b/buffer.c
@@ -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;
diff --git a/buffer.h b/buffer.h
index f80c22c..c051f2d 100644
--- a/buffer.h
+++ b/buffer.h
@@ -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);