| 1 | /* |
| 2 | * Abstraction API/layer for the various ways PvPGN can inspect sockets state |
| 3 | * 2003 (C) |
| 4 | * |
| 5 | * Code is based on the ideas found in thttpd project. |
| 6 | * |
| 7 | * Linux epoll(4) based backend |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version 2 |
| 12 | * of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | #ifndef __INCLUDED_FDWATCH_EPOLL__ |
| 24 | #define __INCLUDED_FDWATCH_EPOLL__ |
| 25 | |
| 26 | #ifdef HAVE_EPOLL |
| 27 | |
| 28 | #ifdef HAVE_SYS_EPOLL_H |
| 29 | # include <sys/epoll.h> |
| 30 | #endif |
| 31 | |
| 32 | #include "scoped_array.h" |
| 33 | #include "fdwbackend.h" |
| 34 | |
| 35 | namespace pvpgn |
| 36 | { |
| 37 | |
| 38 | class FDWEpollBackend : public FDWBackend |
| 39 | { |
| 40 | public: |
| 41 | explicit FDWEpollBackend(int nfds_); |
| 42 | ~FDWEpollBackend() throw(); |
| 43 | |
| 44 | int add(int idx, unsigned rw); |
| 45 | int del(int idx); |
| 46 | int watch(long timeout_msecs); |
| 47 | void handle(); |
| 48 | |
| 49 | private: |
| 50 | int sr; |
| 51 | int epfd; |
| 52 | /* events to investigate */ |
| 53 | scoped_array<struct epoll_event> epevents; |
| 54 | }; |
| 55 | |
| 56 | } |
| 57 | |
| 58 | #endif /* HAVE_EPOLL */ |
| 59 | |
| 60 | #endif /* __INCLUDED_FDWATCH_EPOLL__ */ |