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

Function socket_waitfd

Plugins/UnLuaExtensions/LuaSocket/Source/src/wsocket.cpp:56–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54#define WAITFD_C (WAITFD_E|WAITFD_W)
55
56int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
57 int ret;
58 fd_set rfds, wfds, efds, *rp = NULL, *wp = NULL, *ep = NULL;
59 struct timeval tv, *tp = NULL;
60 double t;
61 if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
62 if (sw & WAITFD_R) {
63 FD_ZERO(&rfds);
64 FD_SET(*ps, &rfds);
65 rp = &rfds;
66 }
67 if (sw & WAITFD_W) { FD_ZERO(&wfds); FD_SET(*ps, &wfds); wp = &wfds; }
68 if (sw & WAITFD_C) { FD_ZERO(&efds); FD_SET(*ps, &efds); ep = &efds; }
69 if ((t = timeout_get(tm)) >= 0.0) {
70 tv.tv_sec = (int) t;
71 tv.tv_usec = (int) ((t-tv.tv_sec)*1.0e6);
72 tp = &tv;
73 }
74 ret = select(0, rp, wp, ep, tp);
75 if (ret == -1) return WSAGetLastError();
76 if (ret == 0) return IO_TIMEOUT;
77 if (sw == WAITFD_C && FD_ISSET(*ps, &efds)) return IO_CLOSED;
78 return IO_DONE;
79}
80
81/*-------------------------------------------------------------------------*\
82* Select with int timeout in ms

Callers 6

socket_connectFunction · 0.70
socket_acceptFunction · 0.70
socket_sendFunction · 0.70
socket_sendtoFunction · 0.70
socket_recvFunction · 0.70
socket_recvfromFunction · 0.70

Calls 1

timeout_getFunction · 0.85

Tested by

no test coverage detected