VirtualBox

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

Last change on this file since 77807 was 76585, checked in by vboxsync, 6 years ago

*: scm --fix-header-guard-endif

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

© 2024 Oracle
ContactPrivacy/Do Not Sell My InfoTerms of Use