aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 363da3d..5be0faf 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -42,7 +42,7 @@ int buffer_open(lua_State *L) {
42* Initializes C structure 42* Initializes C structure
43\*-------------------------------------------------------------------------*/ 43\*-------------------------------------------------------------------------*/
44void buffer_init(p_buffer buf, p_io io, p_timeout tm) { 44void buffer_init(p_buffer buf, p_io io, p_timeout tm) {
45 buf->first = buf->last = 0; 45 buf->first = buf->last = 0;
46 buf->io = io; 46 buf->io = io;
47 buf->tm = tm; 47 buf->tm = tm;
48 buf->received = buf->sent = 0; 48 buf->received = buf->sent = 0;
@@ -122,9 +122,15 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) {
122 if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b); 122 if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);
123 else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); 123 else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b);
124 else luaL_argcheck(L, 0, 2, "invalid receive pattern"); 124 else luaL_argcheck(L, 0, 2, "invalid receive pattern");
125 /* get a fixed number of bytes (minus what was already partially 125 /* get a fixed number of bytes (minus what was already partially
126 * received) */ 126 * received) */
127 } else err = recvraw(buf, (size_t) lua_tonumber(L, 2)-size, &b); 127 } else {
128 double n = lua_tonumber(L, 2);
129 size_t wanted = (size_t) n;
130 luaL_argcheck(L, n >= 0, 2, "invalid receive pattern");
131 if (size == 0 || wanted > size)
132 err = recvraw(buf, wanted-size, &b);
133 }
128 /* check if there was an error */ 134 /* check if there was an error */
129 if (err != IO_DONE) { 135 if (err != IO_DONE) {
130 /* we can't push anyting in the stack before pushing the 136 /* we can't push anyting in the stack before pushing the