diff options
Diffstat (limited to 'src/buffer.c')
-rw-r--r-- | src/buffer.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/buffer.c b/src/buffer.c index 8fc1166..fff1634 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
@@ -38,7 +38,7 @@ int buffer_open(lua_State *L) { | |||
38 | } | 38 | } |
39 | 39 | ||
40 | /*-------------------------------------------------------------------------*\ | 40 | /*-------------------------------------------------------------------------*\ |
41 | * Initializes C structure | 41 | * Initializes C structure |
42 | \*-------------------------------------------------------------------------*/ | 42 | \*-------------------------------------------------------------------------*/ |
43 | void buffer_init(p_buffer buf, p_io io, p_timeout tm) { | 43 | void buffer_init(p_buffer buf, p_io io, p_timeout tm) { |
44 | buf->first = buf->last = 0; | 44 | buf->first = buf->last = 0; |
@@ -62,8 +62,8 @@ int buffer_meth_getstats(lua_State *L, p_buffer buf) { | |||
62 | * object:setstats() interface | 62 | * object:setstats() interface |
63 | \*-------------------------------------------------------------------------*/ | 63 | \*-------------------------------------------------------------------------*/ |
64 | int buffer_meth_setstats(lua_State *L, p_buffer buf) { | 64 | int buffer_meth_setstats(lua_State *L, p_buffer buf) { |
65 | buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); | 65 | buf->received = (long) luaL_optnumber(L, 2, (lua_Number) buf->received); |
66 | buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); | 66 | buf->sent = (long) luaL_optnumber(L, 3, (lua_Number) buf->sent); |
67 | if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); | 67 | if (lua_isnumber(L, 4)) buf->birthday = timeout_gettime() - lua_tonumber(L, 4); |
68 | lua_pushnumber(L, 1); | 68 | lua_pushnumber(L, 1); |
69 | return 1; | 69 | return 1; |
@@ -88,7 +88,7 @@ int buffer_meth_send(lua_State *L, p_buffer buf) { | |||
88 | /* check if there was an error */ | 88 | /* check if there was an error */ |
89 | if (err != IO_DONE) { | 89 | if (err != IO_DONE) { |
90 | lua_pushnil(L); | 90 | lua_pushnil(L); |
91 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); | 91 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); |
92 | lua_pushnumber(L, (lua_Number) (sent+start-1)); | 92 | lua_pushnumber(L, (lua_Number) (sent+start-1)); |
93 | } else { | 93 | } else { |
94 | lua_pushnumber(L, (lua_Number) (sent+start-1)); | 94 | lua_pushnumber(L, (lua_Number) (sent+start-1)); |
@@ -111,7 +111,7 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { | |||
111 | size_t size; | 111 | size_t size; |
112 | const char *part = luaL_optlstring(L, 3, "", &size); | 112 | const char *part = luaL_optlstring(L, 3, "", &size); |
113 | timeout_markstart(buf->tm); | 113 | timeout_markstart(buf->tm); |
114 | /* initialize buffer with optional extra prefix | 114 | /* initialize buffer with optional extra prefix |
115 | * (useful for concatenating previous partial results) */ | 115 | * (useful for concatenating previous partial results) */ |
116 | luaL_buffinit(L, &b); | 116 | luaL_buffinit(L, &b); |
117 | luaL_addlstring(&b, part, size); | 117 | luaL_addlstring(&b, part, size); |
@@ -119,12 +119,12 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { | |||
119 | if (!lua_isnumber(L, 2)) { | 119 | if (!lua_isnumber(L, 2)) { |
120 | const char *p= luaL_optstring(L, 2, "*l"); | 120 | const char *p= luaL_optstring(L, 2, "*l"); |
121 | if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b); | 121 | if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b); |
122 | else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); | 122 | else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b); |
123 | else luaL_argcheck(L, 0, 2, "invalid receive pattern"); | 123 | else luaL_argcheck(L, 0, 2, "invalid receive pattern"); |
124 | /* get a fixed number of bytes (minus what was already partially | 124 | /* get a fixed number of bytes (minus what was already partially |
125 | * received) */ | 125 | * received) */ |
126 | } else { | 126 | } else { |
127 | double n = lua_tonumber(L, 2); | 127 | double n = lua_tonumber(L, 2); |
128 | size_t wanted = (size_t) n; | 128 | size_t wanted = (size_t) n; |
129 | luaL_argcheck(L, n >= 0, 2, "invalid receive pattern"); | 129 | luaL_argcheck(L, n >= 0, 2, "invalid receive pattern"); |
130 | if (size == 0 || wanted > size) | 130 | if (size == 0 || wanted > size) |
@@ -135,8 +135,8 @@ int buffer_meth_receive(lua_State *L, p_buffer buf) { | |||
135 | /* we can't push anyting in the stack before pushing the | 135 | /* we can't push anyting in the stack before pushing the |
136 | * contents of the buffer. this is the reason for the complication */ | 136 | * contents of the buffer. this is the reason for the complication */ |
137 | luaL_pushresult(&b); | 137 | luaL_pushresult(&b); |
138 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); | 138 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); |
139 | lua_pushvalue(L, -2); | 139 | lua_pushvalue(L, -2); |
140 | lua_pushnil(L); | 140 | lua_pushnil(L); |
141 | lua_replace(L, -4); | 141 | lua_replace(L, -4); |
142 | } else { | 142 | } else { |
@@ -219,7 +219,7 @@ static int recvall(p_buffer buf, luaL_Buffer *b) { | |||
219 | } | 219 | } |
220 | 220 | ||
221 | /*-------------------------------------------------------------------------*\ | 221 | /*-------------------------------------------------------------------------*\ |
222 | * Reads a line terminated by a CR LF pair or just by a LF. The CR and LF | 222 | * Reads a line terminated by a CR LF pair or just by a LF. The CR and LF |
223 | * are not returned by the function and are discarded from the buffer | 223 | * are not returned by the function and are discarded from the buffer |
224 | \*-------------------------------------------------------------------------*/ | 224 | \*-------------------------------------------------------------------------*/ |
225 | static int recvline(p_buffer buf, luaL_Buffer *b) { | 225 | static int recvline(p_buffer buf, luaL_Buffer *b) { |
@@ -249,7 +249,7 @@ static int recvline(p_buffer buf, luaL_Buffer *b) { | |||
249 | static void buffer_skip(p_buffer buf, size_t count) { | 249 | static void buffer_skip(p_buffer buf, size_t count) { |
250 | buf->received += count; | 250 | buf->received += count; |
251 | buf->first += count; | 251 | buf->first += count; |
252 | if (buffer_isempty(buf)) | 252 | if (buffer_isempty(buf)) |
253 | buf->first = buf->last = 0; | 253 | buf->first = buf->last = 0; |
254 | } | 254 | } |
255 | 255 | ||