# HG changeset patch # User David Demelier # Date 1474647608 -7200 # Node ID 3d37e1afec54e7969b9b060b7ae5e030310c4d7f # Parent 90909cf677b163418935a31d38d49f7a0047371f Irccd: the class is Irccd is now pollable, #561 diff -r 90909cf677b1 -r 3d37e1afec54 lib/irccd/irccd.cpp --- a/lib/irccd/irccd.cpp Mon Sep 19 13:42:54 2016 +0200 +++ b/lib/irccd/irccd.cpp Fri Sep 23 18:20:08 2016 +0200 @@ -58,44 +58,21 @@ void Irccd::run() { while (m_running) { - poll(); + poll(250); dispatch(); } } -void Irccd::poll() +void Irccd::prepare(fd_set &in, fd_set &out, net::Handle &max) { - fd_set setinput; - fd_set setoutput; - net::Handle max = 0; - - FD_ZERO(&setinput); - FD_ZERO(&setoutput); - for (const auto &service : m_services) - service->prepare(setinput, setoutput, max); - - // Do the selection. - struct timeval tv; + service->prepare(in, out, max); +} - tv.tv_sec = 5; - tv.tv_usec = 250000; - - int error = select(max + 1, &setinput, &setoutput, nullptr, &tv); - - // Skip anyway if requested to stop - if (!m_running) - return; - - // Skip on error. - if (error < 0 && errno != EINTR) { - log::warning() << "irccd: " << net::error(error) << endl; - return; - } - - // Process after selection. +void Irccd::sync(fd_set &in, fd_set &out) +{ for (const auto &service : m_services) - service->sync(setinput, setoutput); + service->sync(in, out); } void Irccd::dispatch() diff -r 90909cf677b1 -r 3d37e1afec54 lib/irccd/irccd.hpp --- a/lib/irccd/irccd.hpp Mon Sep 19 13:42:54 2016 +0200 +++ b/lib/irccd/irccd.hpp Fri Sep 23 18:20:08 2016 +0200 @@ -30,6 +30,7 @@ #include #include +#include "pollable.hpp" #include "sysconfig.hpp" /** @@ -50,7 +51,7 @@ * \class Irccd * \brief Irccd main instance. */ -class Irccd { +class Irccd : public Pollable { private: // Main loop stuff. std::atomic m_running{true}; @@ -151,6 +152,23 @@ } /** + * Prepare the services for selection. + * + * \param in the input set + * \param out the output set + * \param max the maximum handle + */ + IRCCD_EXPORT void prepare(fd_set &in, fd_set &out, net::Handle &max) override; + + /** + * Synchronize the services. + * + * \param in the input set + * \param out the output set + */ + IRCCD_EXPORT void sync(fd_set &in, fd_set &out) override; + + /** * Add an event to the queue. This will immediately signals the event loop * to interrupt itself to dispatch the pending events. * @@ -165,11 +183,6 @@ IRCCD_EXPORT void run(); /** - * Poll the next events without blocking (250 ms max). - */ - IRCCD_EXPORT void poll(); - - /** * Dispatch the pending events, usually after calling poll(). */ IRCCD_EXPORT void dispatch();