MCPcopy Create free account
hub / github.com/ElementsProject/elements / Wait

Method Wait

src/util/sock.cpp:108–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106}
107
108bool Sock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
109{
110#ifdef USE_POLL
111 pollfd fd;
112 fd.fd = m_socket;
113 fd.events = 0;
114 if (requested & RECV) {
115 fd.events |= POLLIN;
116 }
117 if (requested & SEND) {
118 fd.events |= POLLOUT;
119 }
120
121 if (poll(&fd, 1, count_milliseconds(timeout)) == SOCKET_ERROR) {
122 return false;
123 }
124
125 if (occurred != nullptr) {
126 *occurred = 0;
127 if (fd.revents & POLLIN) {
128 *occurred |= RECV;
129 }
130 if (fd.revents & POLLOUT) {
131 *occurred |= SEND;
132 }
133 }
134
135 return true;
136#else
137 if (!IsSelectableSocket(m_socket)) {
138 return false;
139 }
140
141 fd_set fdset_recv;
142 fd_set fdset_send;
143 FD_ZERO(&fdset_recv);
144 FD_ZERO(&fdset_send);
145
146 if (requested & RECV) {
147 FD_SET(m_socket, &fdset_recv);
148 }
149
150 if (requested & SEND) {
151 FD_SET(m_socket, &fdset_send);
152 }
153
154 timeval timeout_struct = MillisToTimeval(timeout);
155
156 if (select(m_socket + 1, &fdset_recv, &fdset_send, nullptr, &timeout_struct) == SOCKET_ERROR) {
157 return false;
158 }
159
160 if (occurred != nullptr) {
161 *occurred = 0;
162 if (FD_ISSET(m_socket, &fdset_recv)) {
163 *occurred |= RECV;
164 }
165 if (FD_ISSET(m_socket, &fdset_send)) {

Callers 5

AcceptMethod · 0.45
InterruptibleRecvFunction · 0.45
ConnectSocketDirectlyFunction · 0.45
ConnectBlockMethod · 0.45

Calls 3

count_millisecondsFunction · 0.85
IsSelectableSocketFunction · 0.85
MillisToTimevalFunction · 0.85

Tested by

no test coverage detected