VirtualBox

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

Last change on this file since 28271 was 27509, checked in by vboxsync, 15 years ago

iprt: Poll on sockets on windows (untested). RTPollSetCount -> RTPollSetGetCount.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1/** @file
2 * IPRT - Polling I/O Handles.
3 */
4
5/*
6 * Copyright (C) 2010 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___iprt_poll_h
31#define ___iprt_poll_h
32
33#include <iprt/cdefs.h>
34#include <iprt/types.h>
35
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_rt_poll RTPoll - Polling I/O Handles
39 * @ingroup grp_rt
40 * @{
41 */
42
43/** @name Poll events
44 * @{ */
45/** Readable without blocking. */
46#define RTPOLL_EVT_READ RT_BIT_32(0)
47/** Writable without blocking. */
48#define RTPOLL_EVT_WRITE RT_BIT_32(1)
49/** Error condition, hangup, exception or similar. */
50#define RTPOLL_EVT_ERROR RT_BIT_32(2)
51/** Mask of the valid bits. */
52#define RTPOLL_EVT_VALID_MASK UINT32_C(0x00000007)
53/** @} */
54
55/**
56 * Polls on the specified poll set until an event occures on one of the handles
57 * or the timeout expires.
58 *
59 * @returns IPRT status code.
60 * @retval VINF_SUCCESS if an event occured on a handle. Note that these
61 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
62 * @retval VERR_WRONG_ORDER if another thread is already accessing the set. The
63 * user is responsible for ensuring single threaded access.
64 * @retval VERR_TIMEOUT if @a cMillies ellapsed without any events.
65 * @retval VERR_DEADLOCK if @a cMillies is set to RT_INDEFINITE_WAIT and there
66 * are no valid handles in the set.
67 *
68 * @param hPollSet The set to poll on.
69 * @param cMillies Number of milliseconds to wait. Use
70 * RT_INDEFINITE_WAIT to wait for ever.
71 * @param pfEvents Where to return details about the events that
72 * occured. Optional.
73 * @param pid Where to return the ID associated with the
74 * handle when calling RTPollSetAdd. Optional.
75 *
76 * @sa RTPollNoResume
77 *
78 * @remarks The caller is responsible for ensuring
79 */
80RTDECL(int) RTPoll(RTPOLLSET hPollSet, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid);
81
82/**
83 * Same as RTPoll except that it will return when interrupted.
84 *
85 * @returns IPRT status code.
86 * @retval VINF_SUCCESS if an event occured on a handle. Note that these
87 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
88 * @retval VERR_WRONG_ORDER if another thread is already accessing the set. The
89 * user is responsible for ensuring single threaded access.
90 * @retval VERR_TIMEOUT if @a cMillies ellapsed without any events.
91 * @retval VERR_DEADLOCK if @a cMillies is set to RT_INDEFINITE_WAIT and there
92 * are no valid handles in the set.
93 * @retval VERR_INTERRUPTED if a signal or other asynchronous event interrupted
94 * the polling.
95 *
96 * @param hPollSet The set to poll on.
97 * @param cMillies Number of milliseconds to wait. Use
98 * RT_INDEFINITE_WAIT to wait for ever.
99 * @param pfEvents Where to return details about the events that
100 * occured. Optional.
101 * @param pid Where to return the ID associated with the
102 * handle when calling RTPollSetAdd. Optional.
103 */
104RTDECL(int) RTPollNoResume(RTPOLLSET hPollSet, RTMSINTERVAL cMillies, uint32_t *pfEvents, uint32_t *pid);
105
106/**
107 * Creates a poll set with no members.
108 *
109 * @returns IPRT status code.
110 * @param phPollSet Where to return the poll set handle.
111 */
112RTDECL(int) RTPollSetCreate(PRTPOLLSET phPollSet);
113
114/**
115 * Destroys a poll set.
116 *
117 * @returns IPRT status code.
118 * @param hPollSet The poll set to destroy. NIL_POLLSET is quietly
119 * ignored (VINF_SUCCESS).
120 */
121RTDECL(int) RTPollSetDestroy(RTPOLLSET hPollSet);
122
123/**
124 * Adds a generic handle to the poll set.
125 *
126 * @returns IPRT status code
127 * @retval VERR_WRONG_ORDER if another thread is already accessing the set. The
128 * user is responsible for ensuring single threaded access.
129 * @retval VERR_POLL_HANDLE_NOT_POLLABLE if the specified handle is not
130 * pollable.
131 * @retval VERR_POLL_HANDLE_ID_EXISTS if the handle ID is already in use in the
132 * set.
133 *
134 * @param hPollSet The poll set to modify.
135 * @param pHandle The handle to add. NIL handles are quitely
136 * ignored.
137 * @param fEvents Which events to poll for.
138 * @param id The handle ID.
139 */
140RTDECL(int) RTPollSetAdd(RTPOLLSET hPollSet, PCRTHANDLE pHandle, uint32_t fEvents, uint32_t id);
141
142/**
143 * Removes a generic handle from the poll set.
144 *
145 * @returns IPRT status code
146 * @retval VERR_INVALID_HANDLE if @a hPollSet not valid.
147 * @retval VERR_WRONG_ORDER if another thread is already accessing the set. The
148 * user is responsible for ensuring single threaded access.
149 * @retval VERR_POLL_HANDLE_ID_NOT_FOUND if @a id doesn't resolve to a valid
150 * handle.
151 *
152 * @param hPollSet The poll set to modify.
153 * @param id The handle ID of the handle that should be
154 * removed.
155 */
156RTDECL(int) RTPollSetRemove(RTPOLLSET hPollSet, uint32_t id);
157
158
159/**
160 * Query a handle in the poll set by it's ID.
161 *
162 * @returns IPRT status code
163 * @retval VINF_SUCCESS if the handle was found. @a *pHandle is set.
164 * @retval VERR_INVALID_HANDLE if @a hPollSet is invalid.
165 * @retval VERR_WRONG_ORDER if another thread is already accessing the set. The
166 * user is responsible for ensuring single threaded access.
167 * @retval VERR_POLL_HANDLE_ID_NOT_FOUND if there is no handle with that ID.
168 *
169 * @param hPollSet The poll set to query.
170 * @param id The ID of the handle.
171 * @param pHandle Where to return the handle details. Optional.
172 */
173RTDECL(int) RTPollSetQueryHandle(RTPOLLSET hPollSet, uint32_t id, PRTHANDLE pHandle);
174
175/**
176 * Gets the number of handles in the set.
177 *
178 * @retval The handle count.
179 * @retval UINT32_MAX if @a hPollSet is invalid or there is concurrent access.
180 *
181 * @param hPollSet The poll set.
182 */
183RTDECL(uint32_t) RTPollSetGetCount(RTPOLLSET hPollSet);
184
185/**
186 * Adds a pipe handle to the set.
187 *
188 * @returns See RTPollSetAdd.
189 *
190 * @param hPollSet The poll set.
191 * @param hPipe The pipe handle.
192 * @param fEvents Which events to poll for.
193 * @param id The handle ID.
194 *
195 * @todo Maybe we could figure out what to poll for depending on the kind of
196 * pipe we're dealing with.
197 */
198DECLINLINE(int) RTPollSetAddPipe(RTPOLLSET hPollSet, RTPIPE hPipe, uint32_t fEvents, uint32_t id)
199{
200 RTHANDLE Handle;
201 Handle.enmType = RTHANDLETYPE_PIPE;
202 Handle.u.uInt = 0;
203 Handle.u.hPipe = hPipe;
204 return RTPollSetAdd(hPollSet, &Handle, fEvents, id);
205}
206
207/**
208 * Adds a socket handle to the set.
209 *
210 * @returns See RTPollSetAdd.
211 *
212 * @param hPollSet The poll set.
213 * @param hSocket The socket handle.
214 * @param fEvents Which events to poll for.
215 * @param id The handle ID.
216 */
217DECLINLINE(int) RTPollSetAddSocket(RTPOLLSET hPollSet, RTSOCKET hSocket, uint32_t fEvents, uint32_t id)
218{
219 RTHANDLE Handle;
220 Handle.enmType = RTHANDLETYPE_SOCKET;
221 Handle.u.uInt = 0;
222 Handle.u.hSocket = hSocket;
223 return RTPollSetAdd(hPollSet, &Handle, fEvents, id);
224}
225
226/** @} */
227
228RT_C_DECLS_END
229
230#endif
231
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette