MCPcopy Create free account
hub / github.com/dermesser/libsocket / wait

Method wait

headers/select.hpp:185–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

183 */
184template <typename SockT>
185typename selectset<SockT>::ready_socks selectset<SockT>::wait(
186 long long microsecs) {
187 int n = 0;
188
189 struct timespec* timeout = NULL;
190 struct timespec _timeout;
191
192 if (microsecs != 0) {
193 timeout = &_timeout;
194
195 long long nanosecs = microsecs * 1000;
196 long long nanopart = nanosecs % 1000000000;
197 long long secpart = (nanosecs - nanopart) / 1000000000;
198
199 _timeout.tv_sec = secpart;
200 _timeout.tv_nsec = nanopart;
201 }
202
203 n = ppoll((poll::pollfd*)pollfd_set.data(), pollfd_set.size(), timeout,
204 NULL);
205
206 ready_socks rwfds;
207
208 if (n < 0) {
209 std::string err(strerror(errno));
210
211 throw socket_exception(__FILE__, __LINE__,
212 "selectset::wait(): Error at ppoll(): " + err);
213
214 } else if (n == 0) // time is over, no filedescriptor is ready
215 {
216 rwfds.first.resize(0);
217 rwfds.second.resize(0);
218
219 return rwfds;
220 }
221
222 std::vector<poll::pollfd>::iterator end = pollfd_set.end();
223
224 for (std::vector<poll::pollfd>::iterator iter = pollfd_set.begin();
225 iter != end; ++iter) {
226 if (iter->revents & POLLIN) rwfds.first.push_back(fdsockmap[iter->fd]);
227
228 if (iter->revents & POLLOUT)
229 rwfds.second.push_back(fdsockmap[iter->fd]);
230 }
231
232 return rwfds;
233}
234
235} // namespace libsocket
236

Callers

nothing calls this directly

Calls 1

socket_exceptionClass · 0.85

Tested by

no test coverage detected