forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_loop.hh
44 lines (32 loc) · 1.15 KB
/
event_loop.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#ifndef EVENT_LOOP_HH
#define EVENT_LOOP_HH
#include <functional>
#include <utility>
#include <list>
#include "poller.hh"
#include "file_descriptor.hh"
#include "signalfd.hh"
#include "child_process.hh"
#include "util.hh"
class EventLoop
{
private:
SignalMask signals_;
Poller poller_;
std::list<std::pair<ChildProcess, bool>> child_processes_;
PollerShortNames::Result handle_signal( const signalfd_siginfo & sig );
protected:
void add_action( Poller::Action action ) { poller_.add_action( action ); }
int internal_loop( const std::function<int(void)> & wait_time );
public:
EventLoop();
void add_simple_input_handler( FileDescriptor & fd, const Poller::Action::CallbackType & callback );
void add_child_process( ChildProcess && child_process, bool exit_when_terminated = true )
{
child_processes_.emplace_back( std::make_pair( std::move( child_process ), exit_when_terminated ) );
}
int loop( void ) { return internal_loop( [] () { return -1; } ); } /* no timeout */
virtual ~EventLoop() {}
};
#endif /* EVENT_LOOP_HH */