VirtualBox

source: vbox/trunk/include/iprt/poll.h@ 73768

Last change on this file since 73768 was 70478, checked in by vboxsync, 6 years ago

iprt/poll.h: Clearifcation of RTPollSetAdd wrt to order.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/** @file
2 * IPRT - Polling I/O Handles.
3 */
4
5/*
6 * Copyright (C) 2010-2017 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_poll_h
27#define ___iprt_poll_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31
32RT_C_DECLS_BEGIN
33
34/** @defgroup grp_rt_poll RTPoll - Polling I/O Handles
35 * @ingroup grp_rt
36 * @{
37 */
38
39/** @name Poll events
40 * @{ */
41/** Readable without blocking. */
42#define RTPOLL_EVT_READ RT_BIT_32(0)
43/** Writable without blocking. */
44#define RTPOLL_EVT_WRITE RT_BIT_32(1)
45/** Error condition, hangup, exception or similar. */
46#define RTPOLL_EVT_ERROR RT_BIT_32(2)
47/** Mask of the valid bits. */
48#define RTPOLL_EVT_VALID_MASK UINT32_C(0x00000007)
49/** @} */
50
51/**
52 * Polls on the specified poll set until an event occurs on one of the handles
53 * or the timeout expires.
54 *
55 * @returns IPRT status code.
56 * @retval VINF_SUCCESS if an event occurred on a handle. Note that these
57 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
58 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
59 * user is responsible for ensuring single threaded access.
60 * @retval VERR_TIMEOUT if @a cMillies ellapsed without any events.
61 * @retval VERR_DEADLOCK if @a cMillies is set to RT_INDEFINITE_WAIT and there
62 * are no valid handles in the set.
63 *
64 * @param hPollSet The set to poll on.
65 * @param cMillies Number of milliseconds to wait. Use
66 * RT_INDEFINITE_WAIT to wait for ever.
67 * @param pfEvents Where to return details about the events that
68 * occurred. Optional.
69 * @param pid Where to return the ID associated with the
70 * handle when calling RTPollSetAdd. Optional.
71 *
72 * @sa RTPollNoResume
73 *
74 * @remarks The caller is responsible for ensuring
75 */
76RTDECL(int) RTPoll(RTPOLLSET hPollSet, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid);
77
78/**
79 * Same as RTPoll except that it will return when interrupted.
80 *
81 * @returns IPRT status code.
82 * @retval VINF_SUCCESS if an event occurred on a handle. Note that these
83 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
84 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
85 * user is responsible for ensuring single threaded access.
86 * @retval VERR_TIMEOUT if @a cMillies ellapsed without any events.
87 * @retval VERR_DEADLOCK if @a cMillies is set to RT_INDEFINITE_WAIT and there
88 * are no valid handles in the set.
89 * @retval VERR_INTERRUPTED if a signal or other asynchronous event interrupted
90 * the polling.
91 *
92 * @param hPollSet The set to poll on.
93 * @param cMillies Number of milliseconds to wait. Use
94 * RT_INDEFINITE_WAIT to wait for ever.
95 * @param pfEvents Where to return details about the events that
96 * occurred. Optional.
97 * @param pid Where to return the ID associated with the
98 * handle when calling RTPollSetAdd. Optional.
99 */
100RTDECL(int) RTPollNoResume(RTPOLLSET hPollSet, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid);
101
102/**
103 * Creates a poll set with no members.
104 *
105 * @returns IPRT status code.
106 * @param phPollSet Where to return the poll set handle.
107 */
108RTDECL(int) RTPollSetCreate(PRTPOLLSET phPollSet);
109
110/**
111 * Destroys a poll set.
112 *
113 * @returns IPRT status code.
114 * @param hPollSet The poll set to destroy. NIL_POLLSET is quietly
115 * ignored (VINF_SUCCESS).
116 */
117RTDECL(int) RTPollSetDestroy(RTPOLLSET hPollSet);
118
119/**
120 * Adds a generic handle to the poll set.
121 *
122 * If a handle is entered more than once, it is recommended to add the one with
123 * RTPOLL_EVT_ERROR first to ensure that you get the right ID back when an error
124 * actually occurs. On some hosts it is possible that polling for
125 * RTPOLL_EVT_READ on a socket may cause it to return error conditions because
126 * the two cannot so easily be distinguished.
127 *
128 * Also note that RTPOLL_EVT_ERROR may be returned by RTPoll even if not asked
129 * for.
130 *
131 * @returns IPRT status code
132 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
133 * user is responsible for ensuring single threaded access.
134 * @retval VERR_POLL_HANDLE_NOT_POLLABLE if the specified handle is not
135 * pollable.
136 * @retval VERR_POLL_HANDLE_ID_EXISTS if the handle ID is already in use in the
137 * set.
138 *
139 * @param hPollSet The poll set to modify.
140 * @param pHandle The handle to add. NIL handles are quietly
141 * ignored.
142 * @param fEvents Which events to poll for.
143 * @param id The handle ID.
144 */
145RTDECL(int) RTPollSetAdd(RTPOLLSET hPollSet, PCRTHANDLE pHandle, uint32_t fEvents, uint32_t id);
146
147/**
148 * Removes a generic handle from the poll set.
149 *
150 * @returns IPRT status code
151 * @retval VERR_INVALID_HANDLE if @a hPollSet not valid.
152 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
153 * user is responsible for ensuring single threaded access.
154 * @retval VERR_POLL_HANDLE_ID_NOT_FOUND if @a id doesn't resolve to a valid
155 * handle.
156 *
157 * @param hPollSet The poll set to modify.
158 * @param id The handle ID of the handle that should be
159 * removed.
160 */
161RTDECL(int) RTPollSetRemove(RTPOLLSET hPollSet, uint32_t id);
162
163
164/**
165 * Query a handle in the poll set by it's ID.
166 *
167 * @returns IPRT status code
168 * @retval VINF_SUCCESS if the handle was found. @a *pHandle is set.
169 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
170 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
171 * user is responsible for ensuring single threaded access.
172 * @retval VERR_POLL_HANDLE_ID_NOT_FOUND if there is no handle with that ID.
173 *
174 * @param hPollSet The poll set to query.
175 * @param id The ID of the handle.
176 * @param pHandle Where to return the handle details. Optional.
177 */
178RTDECL(int) RTPollSetQueryHandle(RTPOLLSET hPollSet, uint32_t id, PRTHANDLE pHandle);
179
180/**
181 * Gets the number of handles in the set.
182 *
183 * @retval The handle count.
184 * @retval UINT32_MAX if @a hPollSet is invalid or there is concurrent access.
185 *
186 * @param hPollSet The poll set.
187 */
188RTDECL(uint32_t) RTPollSetGetCount(RTPOLLSET hPollSet);
189
190/**
191 * Modifies the events to poll for for the given id.
192 *
193 * @returns IPRT status code.
194 * @retval VERR_INVALID_HANDLE if @a hPollSet not valid.
195 * @retval VERR_CONCURRENT_ACCESS if another thread is already accessing the set. The
196 * user is responsible for ensuring single threaded access.
197 * @retval VERR_POLL_HANDLE_ID_NOT_FOUND if @a id doesn't resolve to a valid
198 * handle.
199 *
200 * @param hPollSet The poll set to modify.
201 * @param id The handle ID to change the events for.
202 * @param fEvents Which events to poll for.
203 */
204RTDECL(int) RTPollSetEventsChange(RTPOLLSET hPollSet, uint32_t id, uint32_t fEvents);
205
206/**
207 * Adds a pipe handle to the set.
208 *
209 * @returns See RTPollSetAdd.
210 *
211 * @param hPollSet The poll set.
212 * @param hPipe The pipe handle.
213 * @param fEvents Which events to poll for.
214 * @param id The handle ID.
215 *
216 * @todo Maybe we could figure out what to poll for depending on the kind of
217 * pipe we're dealing with.
218 */
219DECLINLINE(int) RTPollSetAddPipe(RTPOLLSET hPollSet, RTPIPE hPipe, uint32_t fEvents, uint32_t id)
220{
221 RTHANDLE Handle;
222 Handle.enmType = RTHANDLETYPE_PIPE;
223 Handle.u.uInt = 0;
224 Handle.u.hPipe = hPipe;
225 return RTPollSetAdd(hPollSet, &Handle, fEvents, id);
226}
227
228/**
229 * Adds a socket handle to the set.
230 *
231 * @returns See RTPollSetAdd.
232 *
233 * @param hPollSet The poll set.
234 * @param hSocket The socket handle.
235 * @param fEvents Which events to poll for.
236 * @param id The handle ID.
237 */
238DECLINLINE(int) RTPollSetAddSocket(RTPOLLSET hPollSet, RTSOCKET hSocket, uint32_t fEvents, uint32_t id)
239{
240 RTHANDLE Handle;
241 Handle.enmType = RTHANDLETYPE_SOCKET;
242 Handle.u.uInt = 0;
243 Handle.u.hSocket = hSocket;
244 return RTPollSetAdd(hPollSet, &Handle, fEvents, id);
245}
246
247/** @} */
248
249RT_C_DECLS_END
250
251#endif
252
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use