From c8b402e00442cd249397d4d33d2723a1f08a8108 Mon Sep 17 00:00:00 2001 From: Diego Nehab Date: Sun, 18 Jul 2004 22:56:14 +0000 Subject: Changed send function. --- src/buffer.c | 23 ++++++++++++----------- src/wsocket.c | 2 -- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/buffer.c b/src/buffer.c index 33fae84..30be156 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -64,23 +64,24 @@ int buf_meth_getstats(lua_State *L, p_buf buf) { \*-------------------------------------------------------------------------*/ int buf_meth_send(lua_State *L, p_buf buf) { int top = lua_gettop(L); - size_t total = 0; - int arg, err = IO_DONE; p_tm tm = tm_markstart(buf->tm); - for (arg = 2; arg <= top; arg++) { /* first arg is socket object */ - size_t sent, count; - const char *data = luaL_optlstring(L, arg, NULL, &count); - if (!data || err != IO_DONE) break; - err = sendraw(buf, data, count, &sent); - total += sent; - } + int err = IO_DONE; + size_t size, sent; + const char *data = luaL_checklstring(L, 2, &size); + ssize_t start = (ssize_t) luaL_optnumber(L, 3, 1); + ssize_t end = (ssize_t) luaL_optnumber(L, 4, -1); + if (start < 0) start = size+start+1; + if (end < 0) end = size+end+1; + if (start < 1) start = 1; + if (end > size) end = size; + if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); /* check if there was an error */ if (err != IO_DONE) { lua_pushnil(L); lua_pushstring(L, buf->io->error(buf->io->ctx, err)); - lua_pushnumber(L, total); + lua_pushnumber(L, sent); } else { - lua_pushnumber(L, total); + lua_pushnumber(L, sent); lua_pushnil(L); lua_pushnil(L); } diff --git a/src/wsocket.c b/src/wsocket.c index d9da6fc..511dbdc 100644 --- a/src/wsocket.c +++ b/src/wsocket.c @@ -373,12 +373,10 @@ static const char *wstrerror(int err) { case WSANOTINITIALISED: return "Successful WSAStartup not yet performed"; case WSAEDISCON: return "Graceful shutdown in progress"; - case WSATYPE_NOT_FOUND: return "Class type not found"; case WSAHOST_NOT_FOUND: return "Host not found"; case WSATRY_AGAIN: return "Nonauthoritative host not found"; case WSANO_RECOVERY: return "Nonrecoverable name lookup error"; case WSANO_DATA: return "Valid name, no data record of requested type"; - case WSASYSCALLFAILURE: return "System call failure"; default: return "Unknown error"; } } -- cgit v1.2.3-55-g6feb