summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2021-08-21 16:38:29 +0200
committerAki <please@ignore.pl>2021-08-21 16:38:29 +0200
commit506fa912f42d31fd1760d9b3b9f3fbcfe43da2be (patch)
treedc5377216a3634a2370e1885d0e892b1084ee9be
parentdf60d9f0684876fa74b882b086ca1205581f99cb (diff)
downloadplop-506fa912f42d31fd1760d9b3b9f3fbcfe43da2be.zip
plop-506fa912f42d31fd1760d9b3b9f3fbcfe43da2be.tar.gz
plop-506fa912f42d31fd1760d9b3b9f3fbcfe43da2be.tar.bz2
Moved error handling out of buffer_read_more
-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);