reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Poll.hxx
Go to the documentation of this file.
1#if !defined(RESIP_POLL_HXX)
2#define RESIP_POLL_HXX
3
4#include <memory>
5#include <vector>
6
7namespace resip {
8
10
11class PollImpl;
12
25class Poll {
26
27 public:
28
29 class FDEntry {
30
31 friend class Poll;
32
33 public:
34
35 typedef unsigned short StateBitMask; // FDStateBitMask | ResipStateBitMask.
50
51 private:
52
53 static
54 int
55 compare(const Poll::FDEntry * leftFDEntry,
57
58 // Fields:
59 Poll * _poll;
60 int/*FD*/ _fd;
61 Poll::FDEntry::StateBitMask _stateBitMask;
62 unsigned short _index; // Within "_poll->_fdEntryVector".
63
64 public:
65
66 //constructor
67 FDEntry(Poll * poll,
68 bool isTransport,
69 int/*FD*/ fd);
70
71 //destructor
72 virtual ~FDEntry();
73
74 inline
75 int//FD
76 getFD() const
77 {
78 return _fd;
79 }
80
81 inline
84 {
85 return _stateBitMask;
86 }
87
88 void
90
91 protected:
92
93 void
95
96 virtual void doRead() {};
97 virtual void doWrite() {};
98 virtual void doError() {};
99
100 private:
101
102 // Copy constructor: declared but not defined
103 FDEntry(const Poll::FDEntry & from);
104
105 // Assignment: declared but not defined
107 operator=(const Poll::FDEntry & from);
108
109 };
110 friend class Poll::FDEntry;
111
112 private:
113 std::unique_ptr<PollImpl> mImpl;
114 public:
115
116 /*
117 "waitResult" is the result of method "wait" or "afterExternWait".
118 Returns the index of the entry with the smallest file descriptor >= "fd" in
119 "waitResult", or "waitResult.size()" if none exists.
120 */
121 static
122 int
123 findFDInWaitResult(int/*FD*/ fd,
124 const std::vector<Poll::FDEntry *> & waitResult);
125
126 //constructor
127 Poll();
128
129 //destructor
130 ~Poll();
131
132#ifdef RESIP_POLL_EXTERN // {
133
134 // The result is the set of entries in this poll object.
135 const std::vector<Poll::FDEntry *> &
137
138 /*
139 If "fd" has no entry in this poll object, ignore it and return false.
140 Otherwise, set the entry's FD state from "fdStateBitMask" and return true.
141 If the same "fd" is passed in multiple times, the "fdStateBitMask" are
142 or-ed together.
143 */
144 bool
145 setEntryFDStateForExternWait(int/*FD*/ fd,
147
148 // The result is identical to that of method "wait".
149 const std::vector<Poll::FDEntry *> &
151
152#else
153
154 /*
155 Wait for I/O on any of this poll object's entry's file descriptors.
156 More precisely, wait for the file descriptor of any entry with a pending
157 write to be writable or for any entry's file descriptor to have readable
158 input or an error.
159 If "timeoutMilliSeconds" is negative, it means wait indefinitely, otherwise
160 it indicates the maximum period to wait.
161 The result is an array of the entries for the file descriptors that are
162 readable, writable, or error, as specified by each entry's FD state.
163 The result contains no duplicates and is sorted by file descriptor.
164 (To service file descriptors with round-robin prioritization, remember the
165 last file descriptor serviced and use method "Poll::findFDInWaitResult" to
166 find the index in the result array of the highest priority entry.)
167 The result is valid until the next call to this method, method
168 "beforeExternWait", or the destructor.
169 At some point before then, for each entry in the result, method
170 "Poll::FDEntry::clearFDState" must be called.
171 */
172 const std::vector<Poll::FDEntry *> &
174
175#endif
176
177 private:
178
179 // Copy constructor: declared but not defined
180 Poll(const Poll & from);
181
182 // Assignment: declared but not defined
183 Poll &
184 operator=(const Poll & from);
185
186};
187
189
190} // namespace resip
191
192#endif
193
194/* ====================================================================
195 * The Vovida Software License, Version 1.0
196 *
197 * Copyright (c) 2000-2005 Jacob Butcher
198 *
199 * Redistribution and use in source and binary forms, with or without
200 * modification, are permitted provided that the following conditions
201 * are met:
202 *
203 * 1. Redistributions of source code must retain the above copyright
204 * notice, this list of conditions and the following disclaimer.
205 *
206 * 2. Redistributions in binary form must reproduce the above copyright
207 * notice, this list of conditions and the following disclaimer in
208 * the documentation and/or other materials provided with the
209 * distribution.
210 *
211 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
212 * and "Vovida Open Communication Application Library (VOCAL)" must
213 * not be used to endorse or promote products derived from this
214 * software without prior written permission. For written
215 * permission, please contact vocal@vovida.org.
216 *
217 * 4. Products derived from this software may not be called "VOCAL", nor
218 * may "VOCAL" appear in their name, without prior written
219 * permission of Vovida Networks, Inc.
220 *
221 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
222 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
223 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
224 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
225 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
226 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
227 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
228 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
229 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
230 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
232 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
233 * DAMAGE.
234 *
235 */
StateBitMask ResipStateBitMask
Definition Poll.hxx:49
Poll::FDEntry::StateBitMask getStateBitMask() const
Definition Poll.hxx:83
int getFD() const
Definition Poll.hxx:76
unsigned short StateBitMask
Definition Poll.hxx:35
virtual ~FDEntry()
Definition Poll.cxx:116
virtual void doRead()
Definition Poll.hxx:96
virtual void doError()
Definition Poll.hxx:98
void setIsWritePending(bool isWritePending)
Definition Poll.cxx:144
StateBitMask FDStateBitMask
Definition Poll.hxx:44
virtual void doWrite()
Definition Poll.hxx:97
This class abstracts the Unix system call "poll".
Definition Poll.hxx:25
const std::vector< Poll::FDEntry * > & wait(int timeoutMilliSeconds)
defined(RESIP_POLL_EXTERN) } {
static int findFDInWaitResult(int fd, const std::vector< Poll::FDEntry * > &waitResult)
Definition Poll.cxx:179
dcm! – add UnusedChecking(_enum) below;
void list()
Definition userAdmin.cxx:66