MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Poll

Method Poll

lib/base/socket.cpp:367–414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367bool Socket::Poll(bool read, bool write, struct timeval *timeout)
368{
369 int rc;
370
371#ifdef _WIN32
372 fd_set readfds, writefds, exceptfds;
373
374 FD_ZERO(&readfds);
375 if (read)
376 FD_SET(GetFD(), &readfds);
377
378 FD_ZERO(&writefds);
379 if (write)
380 FD_SET(GetFD(), &writefds);
381
382 FD_ZERO(&exceptfds);
383 FD_SET(GetFD(), &exceptfds);
384
385 rc = select(GetFD() + 1, &readfds, &writefds, &exceptfds, timeout);
386
387 if (rc < 0) {
388 Log(LogCritical, "Socket")
389 << "select() failed with error code " << WSAGetLastError() << ", \"" << Utility::FormatErrorNumber(WSAGetLastError()) << "\"";
390
391 BOOST_THROW_EXCEPTION(socket_error()
392 << boost::errinfo_api_function("select")
393 << errinfo_win32_error(WSAGetLastError()));
394 }
395#else /* _WIN32 */
396 pollfd pfd;
397 pfd.fd = GetFD();
398 pfd.events = (read ? POLLIN : 0) | (write ? POLLOUT : 0);
399 pfd.revents = 0;
400
401 rc = poll(&pfd, 1, timeout ? (timeout->tv_sec + 1000 + timeout->tv_usec / 1000) : -1);
402
403 if (rc < 0) {
404 Log(LogCritical, "Socket")
405 << "poll() failed with error code " << errno << ", \"" << Utility::FormatErrorNumber(errno) << "\"";
406
407 BOOST_THROW_EXCEPTION(socket_error()
408 << boost::errinfo_api_function("poll")
409 << boost::errinfo_errno(errno));
410 }
411#endif /* _WIN32 */
412
413 return (rc != 0);
414}
415
416void Socket::MakeNonBlocking()
417{

Callers 2

CommandPipeThreadMethod · 0.80
ServerThreadProcMethod · 0.80

Calls 2

LogClass · 0.85
socket_errorClass · 0.85

Tested by

no test coverage detected