aboutsummaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-15 06:11:53 +0000
committerDiego Nehab <diego@tecgraf.puc-rio.br>2004-07-15 06:11:53 +0000
commit9a79d500eb3e015f5bf579aab714916d49c1f289 (patch)
treedb658e87a17e5417ec01ab4a1b0249bdaf2bd1d2 /src/buffer.c
parent471334c3d07f398e4b0859c43276341a28b91504 (diff)
downloadluasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.tar.gz
luasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.tar.bz2
luasocket-9a79d500eb3e015f5bf579aab714916d49c1f289.zip
Still need to fix windows. :o/
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c
index baa248a..33fae84 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -77,7 +77,7 @@ int buf_meth_send(lua_State *L, p_buf buf) {
77 /* check if there was an error */ 77 /* check if there was an error */
78 if (err != IO_DONE) { 78 if (err != IO_DONE) {
79 lua_pushnil(L); 79 lua_pushnil(L);
80 io_pusherror(L, buf->io, err); 80 lua_pushstring(L, buf->io->error(buf->io->ctx, err));
81 lua_pushnumber(L, total); 81 lua_pushnumber(L, total);
82 } else { 82 } else {
83 lua_pushnumber(L, total); 83 lua_pushnumber(L, total);
@@ -98,22 +98,26 @@ int buf_meth_receive(lua_State *L, p_buf buf) {
98 int err = IO_DONE, top = lua_gettop(L); 98 int err = IO_DONE, top = lua_gettop(L);
99 p_tm tm = tm_markstart(buf->tm); 99 p_tm tm = tm_markstart(buf->tm);
100 luaL_Buffer b; 100 luaL_Buffer b;
101 size_t size;
102 const char *part = luaL_optlstring(L, 3, "", &size);
103 /* initialize buffer with optional extra prefix
104 * (useful for concatenating previous partial results) */
101 luaL_buffinit(L, &b); 105 luaL_buffinit(L, &b);
102 /* receive all patterns */ 106 luaL_addlstring(&b, part, size);
107 /* receive new patterns */
103 if (!lua_isnumber(L, 2)) { 108 if (!lua_isnumber(L, 2)) {
104 static const char *patternnames[] = {"*l", "*a", NULL}; 109 const char *p= luaL_optstring(L, 2, "*l");
105 const char *pattern = luaL_optstring(L, 2, "*l"); 110 if (p[0] == '*' && p[1] == 'l') err = recvline(buf, &b);
106 /* get next pattern */ 111 else if (p[0] == '*' && p[1] == 'a') err = recvall(buf, &b);
107 int p = luaL_findstring(pattern, patternnames);
108 if (p == 0) err = recvline(buf, &b);
109 else if (p == 1) err = recvall(buf, &b);
110 else luaL_argcheck(L, 0, 2, "invalid receive pattern"); 112 else luaL_argcheck(L, 0, 2, "invalid receive pattern");
111 /* get a fixed number of bytes */ 113 /* get a fixed number of bytes */
112 } else err = recvraw(buf, (size_t) lua_tonumber(L, 2), &b); 114 } else err = recvraw(buf, (size_t) lua_tonumber(L, 2), &b);
113 /* check if there was an error */ 115 /* check if there was an error */
114 if (err != IO_DONE) { 116 if (err != IO_DONE) {
117 /* we can't push anyting in the stack before pushing the
118 * contents of the buffer. this is the reason for the complication */
115 luaL_pushresult(&b); 119 luaL_pushresult(&b);
116 io_pusherror(L, buf->io, err); 120 lua_pushstring(L, buf->io->error(buf->io->ctx, err));
117 lua_pushvalue(L, -2); 121 lua_pushvalue(L, -2);
118 lua_pushnil(L); 122 lua_pushnil(L);
119 lua_replace(L, -4); 123 lua_replace(L, -4);