cheshirekow  v0.1.0
epoll.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (josh.bialkowski@gmail.com)
3  *
4  * This file is part of cpp-nix.
5  *
6  * cpp-nix is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * cpp-nix is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with cpp-nix. If not, see <http://www.gnu.org/licenses/>.
18  */
25 #ifndef CPP_NIX_EPOLL_H_
26 #define CPP_NIX_EPOLL_H_
27 
28 #include <sys/epoll.h>
29 
30 namespace nix {
31 namespace epoll {
32 
33 struct Flags {
34  public:
35  Flags(int flags)
36  : m_flags(flags) {
37  }
38 
39  int Get() {
40  return m_flags;
41  }
42 
43  private:
44  int m_flags;
45 };
46 
47 }
48 
49 class Epoll {
50  public:
51  Epoll() {
52  m_epfd = epoll_create(1);
53  }
54 
56  m_epfd = epoll_create1(flags.Get());
57  }
58 
59  ~Epoll() {
60  if (m_epfd > 0) {
61  close(m_epfd);
62  }
63  }
64 
65  int GetFd() {
66  return m_epfd;
67  }
68 
69  int Add(int fd, epoll_event* event) {
70  return epoll_ctl(m_epfd, EPOLL_CTL_ADD, fd, event);
71  }
72 
73  int Modify(int fd, epoll_event* event) {
74  return epoll_ctl(m_epfd, EPOLL_CTL_ADD, fd, event);
75  }
76 
77  int Delete(int fd) {
78  return epoll_ctl(m_epfd, EPOLL_CTL_DEL, fd, NULL);
79  }
80 
81  int Wait(struct epoll_event *events, int maxevents, int timeout) {
82  return epoll_wait(m_epfd, events, maxevents, timeout);
83  }
84 
85  int Pwait(epoll_event *events, int maxevents, int timeout,
86  const sigset_t *sigmask) {
87  return epoll_pwait(m_epfd, events, maxevents, timeout, sigmask);
88  }
89 
90  private:
91  int m_epfd;
92 };
93 
94 } // namespace nix
95 
96 #endif // CPP_NIX_EPOLL_H_
Epoll(epoll::Flags flags)
Definition: epoll.h:55
int m_epfd
Definition: epoll.h:91
~Epoll()
Definition: epoll.h:59
int Modify(int fd, epoll_event *event)
Definition: epoll.h:73
int Add(int fd, epoll_event *event)
Definition: epoll.h:69
int Pwait(epoll_event *events, int maxevents, int timeout, const sigset_t *sigmask)
Definition: epoll.h:85
Flags(int flags)
Definition: epoll.h:35
int Wait(struct epoll_event *events, int maxevents, int timeout)
Definition: epoll.h:81
int Delete(int fd)
Definition: epoll.h:77
int GetFd()
Definition: epoll.h:65
Epoll()
Definition: epoll.h:51