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

Function global_select

Plugins/UnLuaExtensions/LuaSocket/Source/src/select.cpp:52–83  ·  view source on GitHub ↗

=========================================================================*\ * Global Lua functions \*=========================================================================*/ -------------------------------------------------------------------------*\ * Waits for a set of sockets until a condition is met or timeout. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

50* Waits for a set of sockets until a condition is met or timeout.
51\*-------------------------------------------------------------------------*/
52static int global_select(lua_State *L) {
53 int rtab, wtab, itab, ret, ndirty;
54 t_socket max_fd = SOCKET_INVALID;
55 fd_set rset, wset;
56 t_timeout tm;
57 double t = luaL_optnumber(L, 3, -1);
58 FD_ZERO(&rset); FD_ZERO(&wset);
59 lua_settop(L, 3);
60 lua_newtable(L); itab = lua_gettop(L);
61 lua_newtable(L); rtab = lua_gettop(L);
62 lua_newtable(L); wtab = lua_gettop(L);
63 collect_fd(L, 1, itab, &rset, &max_fd);
64 collect_fd(L, 2, itab, &wset, &max_fd);
65 ndirty = check_dirty(L, 1, rtab, &rset);
66 t = ndirty > 0? 0.0: t;
67 timeout_init(&tm, t, -1);
68 timeout_markstart(&tm);
69 ret = socket_select(max_fd+1, &rset, &wset, NULL, &tm);
70 if (ret > 0 || ndirty > 0) {
71 return_fd(L, &rset, max_fd+1, itab, rtab, ndirty);
72 return_fd(L, &wset, max_fd+1, itab, wtab, 0);
73 make_assoc(L, rtab);
74 make_assoc(L, wtab);
75 return 2;
76 } else if (ret == 0) {
77 lua_pushstring(L, "timeout");
78 return 3;
79 } else {
80 luaL_error(L, "select failed");
81 return 3;
82 }
83}
84
85/*=========================================================================*\
86* Internal functions

Callers

nothing calls this directly

Calls 12

luaL_optnumberFunction · 0.85
lua_settopFunction · 0.85
lua_gettopFunction · 0.85
collect_fdFunction · 0.85
check_dirtyFunction · 0.85
timeout_initFunction · 0.85
timeout_markstartFunction · 0.85
return_fdFunction · 0.85
make_assocFunction · 0.85
lua_pushstringFunction · 0.85
luaL_errorFunction · 0.85
socket_selectFunction · 0.70

Tested by

no test coverage detected