MCPcopy Create free account
hub / github.com/Tencent/UnLua / buffer_meth_send

Function buffer_meth_send

Plugins/UnLuaExtensions/LuaSocket/Source/src/buffer.cpp:72–100  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * object:send() interface \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

70* object:send() interface
71\*-------------------------------------------------------------------------*/
72int 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

Callers 3

meth_sendFunction · 0.85
meth_sendFunction · 0.85
meth_sendFunction · 0.85

Calls 10

lua_gettopFunction · 0.85
luaL_checklstringFunction · 0.85
luaL_optnumberFunction · 0.85
timeout_markstartFunction · 0.85
sendrawFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
lua_pushnumberFunction · 0.85
timeout_gettimeFunction · 0.85
timeout_getstartFunction · 0.85

Tested by

no test coverage detected