VirtualBox

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

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

include: Updated (C) year.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 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/** The mask of valid flags. */
80#define RTLOCALIPC_FLAGS_VALID_MASK UINT32_C(0x00000001)
81/** @} */
82
83/**
84 * Destroys a local IPC server.
85 *
86 * @returns IPRT status code.
87 *
88 * @param hServer The server handle. The nil value is quietly ignored (VINF_SUCCESS).
89 */
90RTDECL(int) RTLocalIpcServerDestroy(RTLOCALIPCSERVER hServer);
91
92/**
93 * Listen for clients.
94 *
95 * @returns IPRT status code.
96 * @retval VINF_SUCCESS on success and *phClientSession containing the session handle.
97 * @retval VERR_CANCELLED if the listening was interrupted by RTLocalIpcServerCancel().
98 *
99 * @param hServer The server handle.
100 * @param phClientSession Where to store the client session handle on success.
101 *
102 */
103RTDECL(int) RTLocalIpcServerListen(RTLOCALIPCSERVER hServer, PRTLOCALIPCSESSION phClientSession);
104
105/**
106 * Cancel the current or subsequent RTLocalIpcServerListen call.
107 *
108 * @returns IPRT status code.
109 * @param hServer The server handle. The nil value is quietly ignored (VINF_SUCCESS).
110 */
111RTDECL(int) RTLocalIpcServerCancel(RTLOCALIPCSERVER hServer);
112
113
114/**
115 * Connects to a local IPC server.
116 *
117 * This is used a client process (or thread).
118 *
119 * @returns IPRT status code.
120 * @retval VINF_SUCCESS on success and *phSession holding the session handle.
121 *
122 * @param phSession Where to store the sesson handle on success.
123 * @param pszName The server name (see RTLocalIpcServerCreate for details).
124 * @param fFlags Flags. Current undefined, pass 0.
125 */
126RTDECL(int) RTLocalIpcSessionConnect(PRTLOCALIPCSESSION phSession, const char *pszName, uint32_t fFlags);
127
128
129/**
130 * Closes the local IPC session.
131 *
132 * This can be used with sessions created by both RTLocalIpcSessionConnect
133 * and RTLocalIpcServerListen.
134 *
135 * @returns IPRT status code.
136 *
137 * @param hSession The session handle. The nil value is quietly ignored (VINF_SUCCESS).
138 */
139RTDECL(int) RTLocalIpcSessionClose(RTLOCALIPCSESSION hSession);
140
141/**
142 * Receive data from the other end of an local IPC session.
143 *
144 * This will block if there isn't any data.
145 *
146 * @returns IPRT status code.
147 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
148 *
149 * @param hSession The session handle.
150 * @param pvBuffer Where to store the data.
151 * @param cbBuffer If pcbRead is non-NULL this indicates the maximum number of
152 * bytes to read. If pcbRead is NULL then this is the exact number
153 * of bytes to read.
154 * @param pcbRead Optional argument for indicating a partial read and returning
155 * the number of bytes actually read.
156 * This may return 0 on some implementations?
157 */
158RTDECL(int) RTLocalIpcSessionRead(RTLOCALIPCSESSION hSession, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
159
160/**
161 * Send data to the other end of an local IPC session.
162 *
163 * This may or may not block until the data is received by the other party,
164 * this is an implementation detail. If you want to make sure that the data
165 * has been received you should always call RTLocalIpcSessionFlush().
166 *
167 * @returns IPRT status code.
168 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
169 *
170 * @param hSession The session handle.
171 * @param pvBuffer The data to write.
172 * @param cbBuffer The number of bytes to write.
173 */
174RTDECL(int) RTLocalIpcSessionWrite(RTLOCALIPCSESSION hSession, const void *pvBuffer, size_t cbBuffer);
175
176/**
177 * Flush any buffered data and (perhaps) wait for the other party to receive it.
178 *
179 * The waiting for the other party to receive the data is
180 * implementation dependent.
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 */
187RTDECL(int) RTLocalIpcSessionFlush(RTLOCALIPCSESSION hSession);
188
189/**
190 * Wait for data to become ready for reading or for the
191 * session to be disconnected.
192 *
193 * @returns IPRT status code.
194 * @retval VINF_SUCCESS when there is data to read.
195 * @retval VERR_TIMEOUT if no data became available within the specified period (@a cMillies)
196 * @retval VERR_BROKEN_PIPE if the session was disconnected.
197 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
198 *
199 * @param hSession The session handle.
200 * @param cMillies The number of milliseconds to wait. Use RT_INDEFINITE_WAIT
201 * to wait forever.
202 *
203 * @remark VERR_INTERRUPTED will not be returned. If this is desired at some later point
204 * add a RTLocalIpcSessionWaitForDataNoResume() variant like we're using elsewhere.
205 */
206RTDECL(int) RTLocalIpcSessionWaitForData(RTLOCALIPCSESSION hSession, uint32_t cMillies);
207
208/**
209 * Cancells a pending or subsequent operation.
210 *
211 * Not all methods are cancellable, only those which are specfied
212 * returning VERR_CANCELLED. The others are assumed to not be blocking
213 * for ever and ever.
214 *
215 * @returns IPRT status code.
216 *
217 * @param hSession The session handle.
218 */
219RTDECL(int) RTLocalIpcSessionCancel(RTLOCALIPCSESSION hSession);
220
221/**
222 * Query the process ID of the other party.
223 *
224 * This is an optional feature which may not be implemented, so don't
225 * depend on it and check for VERR_NOT_SUPPORTED.
226 *
227 * @returns IPRT status code.
228 * @retval VINF_SUCCESS and *pProcess on success.
229 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
230 * @retval VERR_NOT_SUPPORTED and *pProcess = NIL_RTPROCESS if not supported.
231 *
232 * @param hSession The session handle.
233 * @param pProcess Where to store the process ID.
234 */
235RTDECL(int) RTLocalIpcSessionQueryProcess(RTLOCALIPCSESSION hSession, PRTPROCESS pProcess);
236
237/**
238 * Query the user ID of the other party.
239 *
240 * This is an optional feature which may not be implemented, so don't
241 * depend on it and check for VERR_NOT_SUPPORTED.
242 *
243 * @returns IPRT status code.
244 * @retval VINF_SUCCESS and *pUid on success.
245 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
246 * @retval VERR_NOT_SUPPORTED and *pUid = NIL_RTUID if not supported.
247 *
248 * @param hSession The session handle.
249 * @param pUid Where to store the user ID on success.
250 */
251RTDECL(int) RTLocalIpcSessionQueryUserId(RTLOCALIPCSESSION hSession, PRTUID pUid);
252
253/**
254 * Query the group ID of the other party.
255 *
256 * This is an optional feature which may not be implemented, so don't
257 * depend on it and check for VERR_NOT_SUPPORTED.
258 *
259 * @returns IPRT status code.
260 * @retval VINF_SUCCESS and *pUid on success.
261 * @retval VERR_CANCELLED if the operation was cancelled by RTLocalIpcSessionCancel.
262 * @retval VERR_NOT_SUPPORTED and *pGid = NIL_RTUID if not supported.
263 *
264 * @param hSession The session handle.
265 * @param pGid Where to store the group ID on success.
266 */
267RTDECL(int) RTLocalIpcSessionQueryGroupId(RTLOCALIPCSESSION hSession, PRTGID pGid);
268
269/** @} */
270RT_C_DECLS_END
271
272#endif
273
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