MCPcopy Create free account
hub / github.com/apache/thrift / l_socket_receive

Function l_socket_receive

lib/lua/src/luasocket.c:247–274  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245
246#define LUA_READ_STEP 8192
247static int l_socket_receive(lua_State *L) {
248 p_tcp self = (p_tcp) checktype(L, 1, SOCKET_CONN);
249 p_tcp handle = (p_tcp) checktype(L, 2, SOCKET_CONN);
250 size_t len = luaL_checknumber(L, 3);
251 char buf[LUA_READ_STEP];
252 const char *err = NULL;
253 int received;
254 size_t got = 0, step = 0;
255 luaL_Buffer b;
256
257 luaL_buffinit(L, &b);
258 do {
259 step = (LUA_READ_STEP < len - got ? LUA_READ_STEP : len - got);
260 err = tcp_raw_receive(&handle->sock, buf, step, self->timeout, &received);
261 if (err == NULL) {
262 luaL_addlstring(&b, buf, received);
263 got += received;
264 }
265 } while (err == NULL && got < len);
266
267 if (err) {
268 lua_pushnil(L);
269 lua_pushstring(L, err);
270 return 2;
271 }
272 luaL_pushresult(&b);
273 return 1;
274}
275
276// settimeout(timeout)
277static int l_socket_settimeout(lua_State *L) {

Callers

nothing calls this directly

Calls 2

checktypeFunction · 0.85
tcp_raw_receiveFunction · 0.85

Tested by

no test coverage detected