VirtualBox

source: vbox/trunk/include/iprt/localipc.h@ 58300

Last change on this file since 58300 was 58300, checked in by vboxsync, 9 years ago

RTLocalIpc: Added RTLocalIpcSessionRetain and RTLocalIpcSessionRelease.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 KB
Line 
1/** @file
2 * IPRT - Local IPC Server & Client.
3 */
4
5/*
6 * Copyright (C) 2006-2015 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_localipc_h
27#define ___iprt_localipc_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/thread.h>
32
33#ifdef IN_RING0
34# error "There are no RTLocalIpc APIs available Ring-0 Host Context!"
35#endif
36
37
38RT_C_DECLS_BEGIN
39
40/** @defgroup grp_rt_localipc RTLocalIpc - Local IPC
41 * @ingroup grp_rt
42 * @{
43 */
44
45/** Handle to a local IPC server instance. */
46typedef struct RTLOCALIPCSERVERINT *RTLOCALIPCSERVER;
47/** Pointer to a local IPC server handle. */
48typedef RTLOCALIPCSERVER *PRTLOCALIPCSERVER;
49/** Local IPC server handle nil value. */
50#define NIL_RTLOCALIPCSERVER ((RTLOCALIPCSERVER)0)
51
52/** Handle to a local ICP session instance. */
53typedef struct RTLOCALIPCSESSIONINT *RTLOCALIPCSESSION;
54/** Pointer to a local ICP session handle. */
55typedef RTLOCALIPCSESSION *PRTLOCALIPCSESSION;
56/** Local ICP session handle nil value. */
57#define NIL_RTLOCALIPCSESSION ((RTLOCALIPCSESSION)0)
58
59
60
61/**
62 * Create a local IPC server.
63 *
64 * @returns IPRT status code.
65 * @retval VINF_SUCCESS on success and *phServer containing the instance handle.
66 *
67 * @param phServer Where to put the server instance handle.
68 * @param pszName The server name. This must be unique and not include
69 * any special chars or slashes. It will be morphed into a
70 * unique platform specific identifier.
71 * @param fFlags Flags, see RTLOCALIPC_FLAGS_*.
72 */
73RTDECL(int) RTLocalIpcServerCreate(PRTLOCALIPCSERVER phServer, const char *pszName, uint32_t fFlags);
74
75/** @name RTLocalIpcServerCreate flags
76 * @{ */
77/** The server can handle multiple sessions. */
78#define RTLOCALIPC_FLAGS_MULTI_SESSION RT_BIT_32(0)
79/** Native name, as apposed to a portable one. */
80#define RTLOCALIPC_FLAGS_NATIVE_NAME RT_BIT_32(1)
81/** The mask of valid flags. */
82#define RTLOCALIPC_FLAGS_VALID_MASK UINT32_C(0x00000003)
83/** @} */
84
85/**
86 * Destroys a local IPC server.
87 *
88 * @returns IPRT status code.
89 * @retval VINF_SUCCESS if still other references or NIL.
90 * @retval VINF_OBJECT_DESTROYED if actually destroyed.
91 *
92 * @param hServer The server handle. The nil value is quietly ignored (VINF_SUCCESS).
93 */
94RTDECL(int) RTLocalIpcServerDestroy(RTLOCALIPCSERVER hServer);
95
96/**
97 * Listen for clients.
98 *
99 * @returns IPRT status code.
100 * @retval VINF_SUCCESS on success and *phClientSession containing the session handle.
101 * @retval VERR_CANCELLED if the listening was interrupted by RTLocalIpcServerCancel().
102 *
103 * @param hServer The server handle.
104 * @param phClientSession Where to store the client session handle on success.
105 *
106 */
107RTDECL(int) RTLocalIpcServerListen(RTLOCALIPCSERVER hServer, PRTLOCALIPCSESSION phClientSession);
108
109/**
110 * Cancel the current or subsequent RTLocalIpcServerListen call.
111 *
112 * @returns IPRT status code.
113 * @param hServer The server handle. The nil value is quietly ignored (VINF_SUCCESS).
114 */
115RTDECL(int) RTLocalIpcServerCancel(RTLOCALIPCSERVER hServer);
116
117
118/**
119 * Connects to a local IPC server.
120 *
121 * This is used a client process (or thread).
122 *
123 * @returns IPRT status code.
124 * @retval VINF_SUCCESS on success and *phSession holding the session handle.
125 *
126 * @param phSession Where to store the sesson handle on success.
127 * @param pszName The server name (see RTLocalIpcServerCreate for details).
128 * @param fFlags Flags, RTLOCALIPC_C_FLAGS_XXX.
129 */
130RTDECL(int) RTLocalIpcSessionConnect(PRTLOCALIPCSESSION phSession, const char *pszName, uint32_t fFlags);
131
132/** @name RTLOCALIPC_C_FLAGS_XXX - RTLocalIpcSessionConnect flags
133 * @{ */
134/** Native name, as apposed to a portable one. */
135#define RTLOCALIPC_C_FLAGS_NATIVE_NAME RT_BIT_32(0)
136/** The mask of valid flags. */
137#define RTLOCALIPC_C_FLAGS_VALID_MASK UINT32_C(0x00000001)
138/** @} */
139
140/**
141 * Closes the local IPC session.
142 *
143 * This can be used with sessions created by both RTLocalIpcSessionConnect
144 * and RTLocalIpcServerListen. It will release one cancel pending I/O and
145 * relase one reference (typically the implict reference from the create API).
146 *
147 * @returns IPRT status code.
148 * @retval VINF_SUCCESS if still other references or NIL.
149 * @retval VINF_OBJECT_DESTROYED if session destroyed.
150 *
151 * @param hSession The session handle. The nil value is quietly ignored (VINF_SUCCESS).
152 */
153RTDECL(int) RTLocalIpcSessionClose(RTLOCALIPCSESSION hSession);
154
155/**
156 * Retain a refence to the given session.
157 *
158 * @returns New reference count, UINT32_MAX if the handle is invalid.
159 * @param hSession The session handle.
160 */
161RTDECL(uint32_t) RTLocalIpcSessionRetain(RTLOCALIPCSESSION hSession);
162
163/**
164 * Releases a refence to the given session.
165 *
166 * This differs from RTLocalIpcSessionClose in that it won't cancel any pending
167 * I/O. So, better call RTLocalIpcSessionClose if you want to terminate the
168 * session.
169 *
170 * @returns New reference count, 0 if NIL handle, UINT32_MAX if the handle is
171 * invalid.
172 * @param hSession The session handle.
173 */
174RTDECL(uint32_t) RTLocalIpcSessionRelease(RTLOCALIPCSESSION hSession);
175
176
177/**
178 * Receive data from the other end of an local IPC session.
179 *
180 * This will block if there isn't any data.
181 *
182 * @returns IPRT status code.
183 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
184 *
185 * @param hSession The session handle.
186 * @param pvBuf Where to store the data.
187 * @param cbToRead How much to read. This is exact request if
188 * pcbRead is NULL, otherwise it's an upper limit.
189 * @param pcbRead Optional argument for indicating a partial read
190 * and returning the number of bytes actually read.
191 */
192RTDECL(int) RTLocalIpcSessionRead(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead);
193
194/**
195 * Receive pending data from the other end of an local IPC session.
196 *
197 * This will not block to wait for data.
198 *
199 * @returns IPRT status code.
200 * @retval VINF_TRY_AGAIN if no pending data (*pcbRead is set to 0).
201 * @retval VERR_CANCELLED if a previous operation was cancelled by
202 * RTLocalIpcSessionCancel (this operation isn't cancellable).
203 *
204 * @param hSession The session handle.
205 * @param pvBuf Where to store the data.
206 * @param cbToRead How much to read (upper limit).
207 * @param pcbRead Where to return exactly how much was read.
208 */
209RTDECL(int) RTLocalIpcSessionReadNB(RTLOCALIPCSESSION hSession, void *pvBuf, size_t cbToRead, size_t *pcbRead);
210
211/**
212 * Send data to the other end of an local IPC session.
213 *
214 * This may or may not block until the data is received by the other party,
215 * this is an implementation detail. If you want to make sure that the data
216 * has been received you should always call RTLocalIpcSessionFlush().
217 *
218 * @returns IPRT status code.
219 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
220 *
221 * @param hSession The session handle.
222 * @param pvBuf The data to write.
223 * @param cbToWrite How much to write.
224 */
225RTDECL(int) RTLocalIpcSessionWrite(RTLOCALIPCSESSION hSession, const void *pvBuf, size_t cbToWrite);
226
227/**
228 * Flush any buffered data and (perhaps) wait for the other party to receive it.
229 *
230 * The waiting for the other party to receive the data is
231 * implementation dependent.
232 *
233 * @returns IPRT status code.
234 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
235 *
236 * @param hSession The session handle.
237 */
238RTDECL(int) RTLocalIpcSessionFlush(RTLOCALIPCSESSION hSession);
239
240/**
241 * Wait for data to become ready for reading or for the session to be
242 * disconnected.
243 *
244 * @returns IPRT status code.
245 * @retval VINF_SUCCESS when there is data to read.
246 * @retval VERR_TIMEOUT if no data became available within the specified period (@a cMillies)
247 * @retval VERR_BROKEN_PIPE if the session was disconnected.
248 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
249 *
250 * @param hSession The session handle.
251 * @param cMillies The number of milliseconds to wait. Use RT_INDEFINITE_WAIT
252 * to wait forever.
253 *
254 * @remark VERR_INTERRUPTED will not be returned. If this is desired at some later point
255 * add a RTLocalIpcSessionWaitForDataNoResume() variant like we're using elsewhere.
256 */
257RTDECL(int) RTLocalIpcSessionWaitForData(RTLOCALIPCSESSION hSession, uint32_t cMillies);
258
259/**
260 * Cancells a pending or subsequent operation.
261 *
262 * Not all methods are cancellable, only those which are specfied
263 * returning VERR_CANCELLED. The others are assumed to not be blocking
264 * for ever and ever. However, the cancel is sticky, so the session must
265 * basically be trashed (closed) after calling this method.
266 *
267 * @returns IPRT status code.
268 *
269 * @param hSession The session handle.
270 */
271RTDECL(int) RTLocalIpcSessionCancel(RTLOCALIPCSESSION hSession);
272
273/**
274 * Query the process ID of the other party.
275 *
276 * This is an optional feature which may not be implemented, so don't
277 * depend on it and check for VERR_NOT_SUPPORTED.
278 *
279 * @returns IPRT status code.
280 * @retval VINF_SUCCESS and *pProcess on success.
281 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
282 * @retval VERR_NOT_SUPPORTED and *pProcess = NIL_RTPROCESS if not supported.
283 *
284 * @param hSession The session handle.
285 * @param pProcess Where to store the process ID.
286 */
287RTDECL(int) RTLocalIpcSessionQueryProcess(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess);
288
289/**
290 * Query the user ID of the other party.
291 *
292 * This is an optional feature which may not be implemented, so don't
293 * depend on it and check for VERR_NOT_SUPPORTED.
294 *
295 * @returns IPRT status code.
296 * @retval VINF_SUCCESS and *pUid on success.
297 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
298 * @retval VERR_NOT_SUPPORTED and *pUid = NIL_RTUID if not supported.
299 *
300 * @param hSession The session handle.
301 * @param pUid Where to store the user ID on success.
302 */
303RTDECL(int) RTLocalIpcSessionQueryUserId(RTLOCALIPCSESSION hSession, PRTUID pUid);
304
305/**
306 * Query the group ID of the other party.
307 *
308 * This is an optional feature which may not be implemented, so don't
309 * depend on it and check for VERR_NOT_SUPPORTED.
310 *
311 * @returns IPRT status code.
312 * @retval VINF_SUCCESS and *pUid on success.
313 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
314 * @retval VERR_NOT_SUPPORTED and *pGid = NIL_RTUID if not supported.
315 *
316 * @param hSession The session handle.
317 * @param pGid Where to store the group ID on success.
318 */
319RTDECL(int) RTLocalIpcSessionQueryGroupId(RTLOCALIPCSESSION hSession, PRTGID pGid);
320
321/** @} */
322RT_C_DECLS_END
323
324#endif
325
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