Subordination
A framework for distributed programming
basic_handler.hh
1 #ifndef SUBORDINATION_PPL_BASIC_HANDLER_HH
2 #define SUBORDINATION_PPL_BASIC_HANDLER_HH
3 
4 #include <iosfwd>
5 
6 #include <unistdx/io/epoll_event>
7 #include <unistdx/io/poller>
8 
9 #include <subordination/ppl/pipeline_base.hh>
10 
11 namespace sbn {
12 
13  class basic_handler: public pipeline_base {
14 
15  public:
16 
17  virtual void
18  handle(const sys::epoll_event& ev) {
19  this->consume_pipe(ev.fd());
20  }
21 
23  virtual void
24  remove(sys::event_poller& poller) {}
25 
27  virtual void
28  flush() {}
29 
30  virtual void
31  write(std::ostream& out) const {
32  out << "handler";
33  }
34 
35  inline friend std::ostream&
36  operator<<(std::ostream& out, const basic_handler& rhs) {
37  rhs.write(out);
38  return out;
39  }
40 
41  private:
42 
43  void
44  consume_pipe(sys::fd_type fd) {
45  const size_t n = 20;
46  char tmp[n];
47  ssize_t c;
48  while ((c = ::read(fd, tmp, n)) != -1) ;
49  }
50 
51 
52  };
53 
54 }
55 
56 #endif // vim:filetype=cpp
Definition: basic_handler.hh:13
virtual void remove(sys::event_poller &poller)
Called when the handler is removed from the poller.
Definition: basic_handler.hh:24
Definition: pipeline_base.hh:17
virtual void flush()
Flush dirty buffers (if needed).
Definition: basic_handler.hh:28
T write(T... args)