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

Function socket_waitfd

Plugins/UnLuaExtensions/LuaSocket/Source/src/usocket.cpp:27–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25#define WAITFD_W POLLOUT
26#define WAITFD_C (POLLIN|POLLOUT)
27int socket_waitfd(p_socket ps, int sw, p_timeout tm) {
28 int ret;
29 struct pollfd pfd;
30 pfd.fd = *ps;
31 pfd.events = sw;
32 pfd.revents = 0;
33 if (timeout_iszero(tm)) return IO_TIMEOUT; /* optimize timeout == 0 case */
34 do {
35 int t = (int)(timeout_getretry(tm)*1e3);
36 ret = poll(&pfd, 1, t >= 0? t: -1);
37 } while (ret == -1 && errno == EINTR);
38 if (ret == -1) return errno;
39 if (ret == 0) return IO_TIMEOUT;
40 if (sw == WAITFD_C && (pfd.revents & (POLLIN|POLLERR))) return IO_CLOSED;
41 return IO_DONE;
42}
43#else
44
45#define WAITFD_R 1

Callers 8

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

Calls 1

timeout_getretryFunction · 0.85

Tested by

no test coverage detected