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

Function socket_wait

lib/lua/src/usocket.c:50–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48#define WAIT_MODE_W 2
49#define WAIT_MODE_C (WAIT_MODE_R|WAIT_MODE_W)
50T_ERRCODE socket_wait(p_socket sock, int mode, int timeout) {
51 int ret = 0;
52 fd_set rfds, wfds;
53 struct timeval tv;
54 double end, t;
55 if (!timeout) {
56 return TIMEOUT;
57 }
58
59 end = __gettime() + timeout/1000;
60 do {
61 FD_ZERO(&rfds);
62 FD_ZERO(&wfds);
63
64 // Specify what I/O operations we care about
65 if (mode & WAIT_MODE_R) {
66 FD_SET(*sock, &rfds);
67 }
68 if (mode & WAIT_MODE_W) {
69 FD_SET(*sock, &wfds);
70 }
71
72 // Check for timeout
73 t = end - __gettime();
74 if (t < 0.0) {
75 break;
76 }
77
78 // Wait
79 tv.tv_sec = (int)t;
80 tv.tv_usec = (int)((t - tv.tv_sec) * 1.0e6);
81 ret = select(*sock+1, &rfds, &wfds, NULL, &tv);
82 } while (ret == -1 && errno == EINTR);
83 if (ret == -1) {
84 return errno;
85 }
86
87 // Check for timeout
88 if (ret == 0) {
89 return TIMEOUT;
90 }
91
92 return SUCCESS;
93}
94
95////////////////////////////////////////////////////////////////////////////////
96// General

Callers 4

socket_acceptFunction · 0.85
socket_connectFunction · 0.85
socket_sendFunction · 0.85
socket_recvFunction · 0.85

Calls 1

__gettimeFunction · 0.85

Tested by

no test coverage detected