int Dispatcher::waitFor( FdMask& rmaskret, FdMask& wmaskret, FdMask& emaskret, timeval* howlong ) { int nfound; do { rmaskret = *_rmask; wmaskret = *_wmask; emaskret = *_emask; howlong = calculateTimeout(howlong); #if defined(hpux) nfound = select( _nfds, (int*)&rmaskret, (int*)&wmaskret, (int*)&emaskret, howlong ); #else nfound = select(_nfds, &rmaskret, &wmaskret, &emaskret, howlong); #endif if (nfound < 0) { handleError(); } } while (nfound < 0); return nfound; /* Timed out or input available */ }
int Dispatcher::waitFor( FdMask& rmaskret, FdMask& wmaskret, FdMask& emaskret, timeval* howlong ) { int nfound; #if defined(HAVE_BSD_SIGNALS) // ifdef SV_INTERRUPT /* BSD-style */ static struct sigvec sv, osv; #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ static struct sigaction sa, osa; #else /* System V-style */ void (*osig)(); #endif if (!_cqueue->isEmpty()) { #if defined(HAVE_BSD_SIGNALS) // #ifdef SV_INTERRUPT /* BSD-style */ sv.sv_handler = fxSIGVECHANDLER(&Dispatcher::sigCLD); sv.sv_flags = SV_INTERRUPT; sigvec(SIGCLD, &sv, &osv); #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ sa.sa_handler = fxSIGACTIONHANDLER(&Dispatcher::sigCLD); sa.sa_flags = SA_INTERRUPT; sigaction(SIGCLD, &sa, &osa); #else /* System V-style */ osig = (void (*)())signal(SIGCLD, fxSIGHANDLER(&Dispatcher::sigCLD)); #endif } do { rmaskret = *_rmask; wmaskret = *_wmask; emaskret = *_emask; howlong = calculateTimeout(howlong); //#if 0 && defined(hpux) // nfound = select( // _nfds, (int*)&rmaskret, (int*)&wmaskret, (int*)&emaskret, howlong // ); //#else nfound = select(_nfds, &rmaskret, &wmaskret, &emaskret, howlong); //#endif } while (nfound < 0 && !handleError()); if (!_cqueue->isEmpty()) { #if defined(HAVE_BSD_SIGNALS) // #ifdef SV_INTERRUPT /* BSD-style */ sigvec(SIGCLD, &osv, (struct sigvec*) 0); #elif defined(HAVE_POSIX_SIGNALS) // #ifdef SA_NOCLDSTOP /* POSIX */ sigaction(SIGCLD, &osa, (struct sigaction*) 0); #else /* System V-style */ (void) signal(SIGCLD, fxSIGHANDLER(osig)); #endif } return nfound; /* Timed out or input available */ }
bool ZMQDevice::run() { zmq_msg_t msg; if (zmq_msg_init(&msg) != 0) { return false; } SCOPE_EXIT { int errno_ = errno; zmq_msg_close(&msg); errno = errno_; }; zmq_pollitem_t items[2]; items[0].socket = Native::data<ZMQSocket>(front)->socket->z_socket; items[0].fd = 0; items[0].events = ZMQ_POLLIN; items[0].revents = 0; items[1].socket = Native::data<ZMQSocket>(back)->socket->z_socket; items[1].fd = 0; items[1].events = ZMQ_POLLIN; items[1].revents = 0; void* captureSock = nullptr; if (!capture.isNull()) { captureSock = Native::data<ZMQSocket>(capture)->socket->z_socket; } uint64_t lastMessageReceived = ZMQ::clock(); idle_cb.scheduled_at = lastMessageReceived + idle_cb.timeout; timer_cb.scheduled_at = lastMessageReceived + timer_cb.timeout; while (true) { int rc = zmq_poll(items, 2, calculateTimeout()); if (rc < 0) { return false; } uint64_t currentTime = ZMQ::clock(); if (rc > 0) { lastMessageReceived = currentTime; } if (timer_cb.initialized && timer_cb.timeout > 0) { if (timer_cb.scheduled_at <= currentTime) { if (!timer_cb.invoke(currentTime)) { return true; } } } if (rc == 0 && idle_cb.initialized && idle_cb.timeout > 0) { if ((currentTime - lastMessageReceived) >= idle_cb.timeout && idle_cb.scheduled_at <= currentTime) { if (!idle_cb.invoke(currentTime)) { return true; } } continue; } if (items[0].revents & ZMQ_POLLIN) { if (!ZMQDevice::handleSocketRecieved(items[0].socket, items[1].socket, captureSock, &msg)) { return false; } } if (items[1].revents & ZMQ_POLLIN) { if (!ZMQDevice::handleSocketRecieved(items[1].socket, items[0].socket, captureSock, &msg)) { return false; } } } return false; }