2.6. Reactor Event Loop

Class Reactor defines two member functions for processing event loop:


class Reactor {
public:
    void waitForEvents (void);
    void waitForEvents (TimeVal* tv_);

    void stopReactor (void);

    // other methods ...
};
	

The first method with no arguments will block forever, processing data until stopReactor() method is called to terminate Reactor event loop. For example, one possible way of writing GenServer-based Reactor-only application event loop:

Example 2-10. Reactor Event Loop


class Foo : public GenServer, public Singleton<Foo>
{
public:
    void processServer () 
    {
        while (!stopServer ()) 
        {
            m_reactor.waitForEvents ();
        }
        m_reactor.stopReactor ();
    }
    // other methods ...
};
	  

See Example 1-5 for another example.

The second method allows to process events with timeout. It is used mostly for cooperative work with some other event loops in your program (such as Gtk+ or Xt library event loop). See Section 1.7 for further details.