diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buffer.c | 23 | ||||
-rw-r--r-- | src/wsocket.c | 2 |
2 files changed, 12 insertions, 13 deletions
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) { | |||
64 | \*-------------------------------------------------------------------------*/ | 64 | \*-------------------------------------------------------------------------*/ |
65 | int buf_meth_send(lua_State *L, p_buf buf) { | 65 | int buf_meth_send(lua_State *L, p_buf buf) { |
66 | int top = lua_gettop(L); | 66 | int top = lua_gettop(L); |
67 | size_t total = 0; | ||
68 | int arg, err = IO_DONE; | ||
69 | p_tm tm = tm_markstart(buf->tm); | 67 | p_tm tm = tm_markstart(buf->tm); |
70 | for (arg = 2; arg <= top; arg++) { /* first arg is socket object */ | 68 | int err = IO_DONE; |
71 | size_t sent, count; | 69 | size_t size, sent; |
72 | const char *data = luaL_optlstring(L, arg, NULL, &count); | 70 | const char *data = luaL_checklstring(L, 2, &size); |
73 | if (!data || err != IO_DONE) break; | 71 | ssize_t start = (ssize_t) luaL_optnumber(L, 3, 1); |
74 | err = sendraw(buf, data, count, &sent); | 72 | ssize_t end = (ssize_t) luaL_optnumber(L, 4, -1); |
75 | total += sent; | 73 | if (start < 0) start = size+start+1; |
76 | } | 74 | if (end < 0) end = size+end+1; |
75 | if (start < 1) start = 1; | ||
76 | if (end > size) end = size; | ||
77 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); | ||
77 | /* check if there was an error */ | 78 | /* check if there was an error */ |
78 | if (err != IO_DONE) { | 79 | if (err != IO_DONE) { |
79 | lua_pushnil(L); | 80 | lua_pushnil(L); |
80 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); | 81 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); |
81 | lua_pushnumber(L, total); | 82 | lua_pushnumber(L, sent); |
82 | } else { | 83 | } else { |
83 | lua_pushnumber(L, total); | 84 | lua_pushnumber(L, sent); |
84 | lua_pushnil(L); | 85 | lua_pushnil(L); |
85 | lua_pushnil(L); | 86 | lua_pushnil(L); |
86 | } | 87 | } |
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) { | |||
373 | case WSANOTINITIALISED: | 373 | case WSANOTINITIALISED: |
374 | return "Successful WSAStartup not yet performed"; | 374 | return "Successful WSAStartup not yet performed"; |
375 | case WSAEDISCON: return "Graceful shutdown in progress"; | 375 | case WSAEDISCON: return "Graceful shutdown in progress"; |
376 | case WSATYPE_NOT_FOUND: return "Class type not found"; | ||
377 | case WSAHOST_NOT_FOUND: return "Host not found"; | 376 | case WSAHOST_NOT_FOUND: return "Host not found"; |
378 | case WSATRY_AGAIN: return "Nonauthoritative host not found"; | 377 | case WSATRY_AGAIN: return "Nonauthoritative host not found"; |
379 | case WSANO_RECOVERY: return "Nonrecoverable name lookup error"; | 378 | case WSANO_RECOVERY: return "Nonrecoverable name lookup error"; |
380 | case WSANO_DATA: return "Valid name, no data record of requested type"; | 379 | case WSANO_DATA: return "Valid name, no data record of requested type"; |
381 | case WSASYSCALLFAILURE: return "System call failure"; | ||
382 | default: return "Unknown error"; | 380 | default: return "Unknown error"; |
383 | } | 381 | } |
384 | } | 382 | } |