| 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 | * *BSD kqueue() 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_KQUEUE__ |
| 24 | #define __INCLUDED_FDWATCH_KQUEUE__ |
| 25 | |
| 26 | #ifdef HAVE_KQUEUE |
| 27 | |
| 28 | #ifdef HAVE_SYS_TYPES_H |
| 29 | # include <sys/types.h> |
| 30 | #endif |
| 31 | #ifdef HAVE_SYS_EVENT_H |
| 32 | # include <sys/event.h> |
| 33 | #endif |
| 34 | #ifdef HAVE_SYS_TIME_H |
| 35 | # include <sys/time.h> |
| 36 | #endif |
| 37 | |
| 38 | #include "scoped_array.h" |
| 39 | #include "fdwbackend.h" |
| 40 | |
| 41 | namespace pvpgn |
| 42 | { |
| 43 | |
| 44 | class FDWKqueueBackend : public FDWBackend |
| 45 | { |
| 46 | public: |
| 47 | explicit FDWKqueueBackend(int nfds_); |
| 48 | ~FDWKqueueBackend() throw(); |
| 49 | |
| 50 | int add(int idx, unsigned rw); |
| 51 | int del(int idx); |
| 52 | int watch(long timeout_msecs); |
| 53 | void handle(); |
| 54 | |
| 55 | private: |
| 56 | int sr; |
| 57 | int kq; |
| 58 | /* changes to make to kqueue */ |
| 59 | scoped_array<struct kevent> kqchanges; |
| 60 | /* events to investigate */ |
| 61 | scoped_array<struct kevent> kqevents; |
| 62 | /* r/w indices from idx to the kqchanges index where the change is stored */ |
| 63 | scoped_array<int> rridx, wridx; |
| 64 | unsigned nochanges; |
| 65 | }; |
| 66 | |
| 67 | } |
| 68 | |
| 69 | #endif /* HAVE_KQUEUE */ |
| 70 | |
| 71 | #endif /* __INCLUDED_FDWATCH_KQUEUE__ */ |