/src/resiprocate/rutil/FdPoll.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | #if !defined(RESIP_FDPOLL_HXX) |
2 | | #define RESIP_FDPOLL_HXX |
3 | | |
4 | | #include "rutil/Socket.hxx" |
5 | | |
6 | | /* The Makefile system may define the following: |
7 | | * HAVE_EPOLL: system call epoll() is available |
8 | | * |
9 | | * An implementation based upon FdSet (and select()) is always available. |
10 | | * |
11 | | * This file and class is somewhat misnamed. It should really be |
12 | | * called "SocketEvent" or such. The name "FdPoll" originated |
13 | | * from an epoll-specific implementation. |
14 | | */ |
15 | | |
16 | | #if defined(HAVE_EPOLL) |
17 | | #define RESIP_POLL_IMPL_EPOLL |
18 | | #endif |
19 | | |
20 | | #if defined(HAVE_POLL) || (_WIN32_WINNT >= 0x0600) |
21 | | #define RESIP_POLL_IMPL_POLL |
22 | | #endif |
23 | | |
24 | | namespace resip { |
25 | | |
26 | | |
27 | | typedef unsigned short FdPollEventMask; |
28 | | #define FPEM_Read 0x0001 // POLLIN |
29 | | #define FPEM_Write 0x0002 // POLLOUT |
30 | | #define FPEM_Error 0x0004 // POLLERR (select exception) |
31 | | #define FPEM_Edge 0x4000 // EPOLLET |
32 | | |
33 | | class FdPollGrp; |
34 | | |
35 | | /** |
36 | | * This is opaque type used to identify a particular Item. It is assigned |
37 | | * when Item is allocated, and then used to modify or destroy the Item. |
38 | | * NOTE: FdPollItemFake doesn't exist: it is fictious, thus this type |
39 | | * can never be deferenced. |
40 | | */ |
41 | | typedef struct FdPollItemFake* FdPollItemHandle; |
42 | | |
43 | | class FdPollItemIf |
44 | | { |
45 | | //friend class FdPollGrp; |
46 | | public: |
47 | 0 | FdPollItemIf() { }; |
48 | | virtual ~FdPollItemIf(); |
49 | | |
50 | | /** |
51 | | Called by PollGrp when activity is possible |
52 | | **/ |
53 | | virtual void processPollEvent(FdPollEventMask mask) = 0; |
54 | | }; |
55 | | |
56 | | class FdPollItemBase : public FdPollItemIf |
57 | | { |
58 | | //friend class FdPollGrp; |
59 | | public: |
60 | | FdPollItemBase(FdPollGrp *grp, Socket fd, FdPollEventMask mask); |
61 | | virtual ~FdPollItemBase(); |
62 | | |
63 | | protected: |
64 | | |
65 | | FdPollGrp* mPollGrp; |
66 | | Socket mPollSocket; |
67 | | FdPollItemHandle mPollHandle; |
68 | | }; |
69 | | |
70 | | class FdSetIOObserver; |
71 | | |
72 | | class FdPollGrp |
73 | | { |
74 | | public: |
75 | | FdPollGrp(); |
76 | | virtual ~FdPollGrp(); |
77 | | |
78 | | typedef enum {FdSetImpl = 0, PollImpl, EPollImpl } ImplType; |
79 | | |
80 | | /// factory |
81 | | static FdPollGrp* create(const char *implName=NULL); |
82 | | /// Return candidate impl names with vertical bar (|) between them |
83 | | /// Intended for help messages |
84 | | static const char* getImplList(); |
85 | | |
86 | | virtual const char* getImplName() const = 0; |
87 | | virtual ImplType getImplType() const = 0; |
88 | | |
89 | | virtual FdPollItemHandle addPollItem(Socket sock, FdPollEventMask newMask, FdPollItemIf *item) = 0; |
90 | | virtual void modPollItem(FdPollItemHandle handle, FdPollEventMask newMask) = 0; |
91 | | virtual void delPollItem(FdPollItemHandle handle) = 0; |
92 | | |
93 | | virtual void registerFdSetIOObserver(FdSetIOObserver& observer) = 0; |
94 | | virtual void unregisterFdSetIOObserver(FdSetIOObserver& observer) = 0; |
95 | | |
96 | | /// Wait at most {ms} milliseconds. If any file activity has |
97 | | /// already occurs or occurs before {ms} expires, then |
98 | | /// FdPollItem will be informed (via cb method) and this method will |
99 | | /// return. Returns true iff any file activity occured. |
100 | | /// ms<0: wait forever, ms=0: don't wait, ms>0: wait this long |
101 | | /// NOTE: "forever" may be a little as 60sec or as much as forever |
102 | | virtual bool waitAndProcess(int ms=0) = 0; |
103 | | |
104 | | /// get the epoll-fd (epoll_create()) |
105 | | /// This is fd (type int), not Socket. It may be -1 if epoll |
106 | | /// is not enabled. |
107 | | virtual int getEPollFd() const; |
108 | | |
109 | | // Legacy API's (deprecated) - use waitAndProcess instead |
110 | | virtual void buildFdSet(FdSet& fdSet)=0; |
111 | | virtual bool processFdSet(FdSet& fdset)=0; |
112 | | |
113 | | protected: |
114 | | void processItem(FdPollItemIf *item, FdPollEventMask mask); |
115 | | }; |
116 | | |
117 | | |
118 | | |
119 | | /////////////////////////////////////////////////////////////////////////////// |
120 | | |
121 | | } // namespace resip |
122 | | |
123 | | #endif //!defined(RESIP_FDPOLL_HXX) |
124 | | |
125 | | /* ==================================================================== |
126 | | * The Vovida Software License, Version 1.0 |
127 | | * |
128 | | * Copyright (c) 2000-2005 Jacob Butcher |
129 | | * |
130 | | * Redistribution and use in source and binary forms, with or without |
131 | | * modification, are permitted provided that the following conditions |
132 | | * are met: |
133 | | * |
134 | | * 1. Redistributions of source code must retain the above copyright |
135 | | * notice, this list of conditions and the following disclaimer. |
136 | | * |
137 | | * 2. Redistributions in binary form must reproduce the above copyright |
138 | | * notice, this list of conditions and the following disclaimer in |
139 | | * the documentation and/or other materials provided with the |
140 | | * distribution. |
141 | | * |
142 | | * 3. The names "VOCAL", "Vovida Open Communication Application Library", |
143 | | * and "Vovida Open Communication Application Library (VOCAL)" must |
144 | | * not be used to endorse or promote products derived from this |
145 | | * software without prior written permission. For written |
146 | | * permission, please contact vocal@vovida.org. |
147 | | * |
148 | | * 4. Products derived from this software may not be called "VOCAL", nor |
149 | | * may "VOCAL" appear in their name, without prior written |
150 | | * permission of Vovida Networks, Inc. |
151 | | * |
152 | | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED |
153 | | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
154 | | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND |
155 | | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA |
156 | | * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES |
157 | | * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, |
158 | | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
159 | | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
160 | | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
161 | | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
162 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
163 | | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
164 | | * DAMAGE. |
165 | | * |
166 | | * vi: set shiftwidth=3 expandtab: |
167 | | */ |