-------------------------------------------------------------------------*\ * object:send() interface \*-------------------------------------------------------------------------*/
| 70 | * object:send() interface |
| 71 | \*-------------------------------------------------------------------------*/ |
| 72 | int buffer_meth_send(lua_State *L, p_buffer buf) { |
| 73 | int top = lua_gettop(L); |
| 74 | int err = IO_DONE; |
| 75 | size_t size = 0, sent = 0; |
| 76 | const char *data = luaL_checklstring(L, 2, &size); |
| 77 | long start = (long) luaL_optnumber(L, 3, 1); |
| 78 | long end = (long) luaL_optnumber(L, 4, -1); |
| 79 | timeout_markstart(buf->tm); |
| 80 | if (start < 0) start = (long) (size+start+1); |
| 81 | if (end < 0) end = (long) (size+end+1); |
| 82 | if (start < 1) start = (long) 1; |
| 83 | if (end > (long) size) end = (long) size; |
| 84 | if (start <= end) err = sendraw(buf, data+start-1, end-start+1, &sent); |
| 85 | /* check if there was an error */ |
| 86 | if (err != IO_DONE) { |
| 87 | lua_pushnil(L); |
| 88 | lua_pushstring(L, buf->io->error(buf->io->ctx, err)); |
| 89 | lua_pushnumber(L, (lua_Number) (sent+start-1)); |
| 90 | } else { |
| 91 | lua_pushnumber(L, (lua_Number) (sent+start-1)); |
| 92 | lua_pushnil(L); |
| 93 | lua_pushnil(L); |
| 94 | } |
| 95 | #ifdef LUASOCKET_DEBUG |
| 96 | /* push time elapsed during operation as the last return value */ |
| 97 | lua_pushnumber(L, timeout_gettime() - timeout_getstart(buf->tm)); |
| 98 | #endif |
| 99 | return lua_gettop(L) - top; |
| 100 | } |
| 101 | |
| 102 | /*-------------------------------------------------------------------------*\ |
| 103 | * object:receive() interface |
no test coverage detected