1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, Async I/O Completion.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2007 innotek GmbH
|
---|
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 ___VBox_pdmasynccompletion_h
|
---|
27 | #define ___VBox_pdmasynccompletion_h
|
---|
28 |
|
---|
29 | #include <VBox/types.h>
|
---|
30 | #include <VBox/err.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 | __BEGIN_DECLS
|
---|
34 |
|
---|
35 | /** @defgroup grp_pdm_async_completion Async I/O Completion
|
---|
36 | * @ingroup grp_pdm
|
---|
37 | * @{
|
---|
38 | */
|
---|
39 |
|
---|
40 | /** Pointer to a PDM async completion template handle. */
|
---|
41 | typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
|
---|
42 | /** Pointer to a PDM async completion template handle pointer. */
|
---|
43 | typedef PPDMASYNCCOMPLETIONTEMPLATE *PPPDMASYNCCOMPLETIONTEMPLATE;
|
---|
44 |
|
---|
45 | /** Pointer to a PDM async completion task handle. */
|
---|
46 | typedef struct PDMASYNCCOMPLETIONTASK *PPDMASYNCCOMPLETIONTASK;
|
---|
47 | /** Pointer to a PDM async completion task handle pointer. */
|
---|
48 | typedef PPDMASYNCCOMPLETIONTASK *PPPDMASYNCCOMPLETIONTASK;
|
---|
49 |
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Completion callback for devices.
|
---|
53 | *
|
---|
54 | * @param pDevIns The device instance.
|
---|
55 | * @param pTask Pointer to the completion task.
|
---|
56 | * The task is at the time of the call setup to be resumed. So, the callback must
|
---|
57 | * call PDMR3AsyncCompletionSuspend or PDMR3AsyncCompletionDestroy if any other
|
---|
58 | * action is wanted upon return.
|
---|
59 | * @param pvCtx Pointer to any additional, OS specific, completion context. TBD.
|
---|
60 | * @param pvUser User argument.
|
---|
61 | */
|
---|
62 | typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDEV(PPDMDEVINS pDevIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser);
|
---|
63 | /** Pointer to a FNPDMASYNCCOMPLETEDEV(). */
|
---|
64 | typedef FNPDMASYNCCOMPLETEDEV *PFNPDMASYNCCOMPLETEDEV;
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Completion callback for drivers.
|
---|
69 | *
|
---|
70 | * @param pDrvIns The driver instance.
|
---|
71 | * @param pTask Pointer to the completion task.
|
---|
72 | * The task is at the time of the call setup to be resumed. So, the callback must
|
---|
73 | * call PDMR3AsyncCompletionSuspend or PDMR3AsyncCompletionDestroy if any other
|
---|
74 | * action is wanted upon return.
|
---|
75 | * @param pvCtx Pointer to any additional, OS specific, completion context. TBD.
|
---|
76 | * @param pvUser User argument.
|
---|
77 | */
|
---|
78 | typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDRV(PPDMDRVINS pDrvIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser);
|
---|
79 | /** Pointer to a FNPDMASYNCCOMPLETEDRV(). */
|
---|
80 | typedef FNPDMASYNCCOMPLETEDRV *PFNPDMASYNCCOMPLETEDRV;
|
---|
81 |
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Completion callback for USB devices.
|
---|
85 | *
|
---|
86 | * @param pUsbIns The USB device instance.
|
---|
87 | * @param pTask Pointer to the completion task.
|
---|
88 | * The task is at the time of the call setup to be resumed. So, the callback must
|
---|
89 | * call PDMR3AsyncCompletionSuspend or PDMR3AsyncCompletionDestroy if any other
|
---|
90 | * action is wanted upon return.
|
---|
91 | * @param pvCtx Pointer to any additional, OS specific, completion context. TBD.
|
---|
92 | * @param pvUser User argument.
|
---|
93 | */
|
---|
94 | typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEUSB(PPDMUSBINS pUsbIns, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser);
|
---|
95 | /** Pointer to a FNPDMASYNCCOMPLETEUSB(). */
|
---|
96 | typedef FNPDMASYNCCOMPLETEUSB *PFNPDMASYNCCOMPLETEUSB;
|
---|
97 |
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * Completion callback for internal.
|
---|
101 | *
|
---|
102 | * @param pVM Pointer to the shared VM structure.
|
---|
103 | * @param pTask Pointer to the completion task.
|
---|
104 | * The task is at the time of the call setup to be resumed. So, the callback must
|
---|
105 | * call PDMR3AsyncCompletionSuspend or PDMR3AsyncCompletionDestroy if any other
|
---|
106 | * action is wanted upon return.
|
---|
107 | * @param pvCtx Pointer to any additional, OS specific, completion context. TBD.
|
---|
108 | * @param pvUser User argument for the task.
|
---|
109 | * @param pvUser2 User argument for the template.
|
---|
110 | */
|
---|
111 | typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEINT(PVM pVM, PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx, void *pvUser, void *pvUser2);
|
---|
112 | /** Pointer to a FNPDMASYNCCOMPLETEINT(). */
|
---|
113 | typedef FNPDMASYNCCOMPLETEINT *PFNPDMASYNCCOMPLETEINT;
|
---|
114 |
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Creates a async completion template for a device instance.
|
---|
118 | *
|
---|
119 | * The template is used when creating new completion tasks.
|
---|
120 | *
|
---|
121 | * @returns VBox status code.
|
---|
122 | * @param pVM Pointer to the shared VM structure.
|
---|
123 | * @param pDevIns The device instance.
|
---|
124 | * @param ppTemplate Where to store the template pointer on success.
|
---|
125 | * @param pfnCompleted The completion callback routine.
|
---|
126 | * @param pszDesc Description.
|
---|
127 | */
|
---|
128 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc);
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Creates a async completion template for a driver instance.
|
---|
132 | *
|
---|
133 | * The template is used when creating new completion tasks.
|
---|
134 | *
|
---|
135 | * @returns VBox status code.
|
---|
136 | * @param pVM Pointer to the shared VM structure.
|
---|
137 | * @param pDrvIns The driver instance.
|
---|
138 | * @param ppTemplate Where to store the template pointer on success.
|
---|
139 | * @param pfnCompleted The completion callback routine.
|
---|
140 | * @param pszDesc Description.
|
---|
141 | */
|
---|
142 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDRV pfnCompleted, const char *pszDesc);
|
---|
143 |
|
---|
144 | /**
|
---|
145 | * Creates a async completion template for a USB device instance.
|
---|
146 | *
|
---|
147 | * The template is used when creating new completion tasks.
|
---|
148 | *
|
---|
149 | * @returns VBox status code.
|
---|
150 | * @param pVM Pointer to the shared VM structure.
|
---|
151 | * @param pUsbIns The USB device instance.
|
---|
152 | * @param ppTemplate Where to store the template pointer on success.
|
---|
153 | * @param pfnCompleted The completion callback routine.
|
---|
154 | * @param pszDesc Description.
|
---|
155 | */
|
---|
156 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * Creates a async completion template for internally by the VMM.
|
---|
160 | *
|
---|
161 | * The template is used when creating new completion tasks.
|
---|
162 | *
|
---|
163 | * @returns VBox status code.
|
---|
164 | * @param pVM Pointer to the shared VM structure.
|
---|
165 | * @param ppTemplate Where to store the template pointer on success.
|
---|
166 | * @param pfnCompleted The completion callback routine.
|
---|
167 | * @param pvUser2 The 2nd user argument for the callback.
|
---|
168 | * @param pszDesc Description.
|
---|
169 | */
|
---|
170 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateCreateInternal(PVM pVM, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEINT pfnCompleted, void *pvUser2, const char *pszDesc);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Destroys the specified async completion template.
|
---|
174 | *
|
---|
175 | * @returns VBox status codes:
|
---|
176 | * @retval VINF_SUCCESS on success.
|
---|
177 | * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if the template is still in use.
|
---|
178 | *
|
---|
179 | * @param pTemplate The template in question.
|
---|
180 | */
|
---|
181 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateDestroy(PPDMASYNCCOMPLETIONTEMPLATE pTemplate);
|
---|
182 |
|
---|
183 | /**
|
---|
184 | * Destroys all the specified async completion templates for the given device instance.
|
---|
185 | *
|
---|
186 | * @returns VBox status codes:
|
---|
187 | * @retval VINF_SUCCESS on success.
|
---|
188 | * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
|
---|
189 | *
|
---|
190 | * @param pVM Pointer to the shared VM structure.
|
---|
191 | * @param pDevIns The device instance.
|
---|
192 | */
|
---|
193 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
|
---|
194 |
|
---|
195 | /**
|
---|
196 | * Destroys all the specified async completion templates for the given driver instance.
|
---|
197 | *
|
---|
198 | * @returns VBox status codes:
|
---|
199 | * @retval VINF_SUCCESS on success.
|
---|
200 | * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
|
---|
201 | *
|
---|
202 | * @param pVM Pointer to the shared VM structure.
|
---|
203 | * @param pDrvIns The driver instance.
|
---|
204 | */
|
---|
205 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Destroys all the specified async completion templates for the given USB device instance.
|
---|
209 | *
|
---|
210 | * @returns VBox status codes:
|
---|
211 | * @retval VINF_SUCCESS on success.
|
---|
212 | * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
|
---|
213 | *
|
---|
214 | * @param pVM Pointer to the shared VM structure.
|
---|
215 | * @param pUsbIns The USB device instance.
|
---|
216 | */
|
---|
217 | PDMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
|
---|
218 |
|
---|
219 | /**
|
---|
220 | * Async completion task type
|
---|
221 | */
|
---|
222 | typedef enum PDMASYNCCOMPLETIONTASKTYPE
|
---|
223 | {
|
---|
224 | /** Socket. */
|
---|
225 | PDMASYNCCOMPLETIONTASKTYPE_SOCKET = 0,
|
---|
226 | /** Host OS specific. */
|
---|
227 | PDMASYNCCOMPLETIONTASKTYPE_HOST,
|
---|
228 | /** Number of supported backends. This has to be last entry! */
|
---|
229 | PDMASYNCCOMPLETIONTASKTYPE_SUPPORTED
|
---|
230 | } PDMASYNCCOMPLETIONTASKTYPE;
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Get the backend name of a task type.
|
---|
234 | *
|
---|
235 | * @returns Name of the backend.
|
---|
236 | * @param enmTaskType The task type to get the backend name from.
|
---|
237 | */
|
---|
238 | PDMR3DECL(const char *) PDMR3AsyncCompletionGetBackendName(PDMASYNCCOMPLETIONTASKTYPE enmTaskType);
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Creates a completion task.
|
---|
242 | *
|
---|
243 | * @returns VBox status code.
|
---|
244 | * @param ppTask Where to store the task handle on success.
|
---|
245 | * @param pTemplate The async completion template.
|
---|
246 | * @param enmType The type of the task.
|
---|
247 | * @param pvCtx The task specific context.
|
---|
248 | * @param pvUser The user argument for the callback.
|
---|
249 | */
|
---|
250 | PDMR3DECL(int) PDMR3AsyncCompletionTaskCreate(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, PDMASYNCCOMPLETIONTASKTYPE enmType, void *pvCtx, void *pvUser);
|
---|
251 |
|
---|
252 | /**
|
---|
253 | * Associate a task with a type specific context.
|
---|
254 | *
|
---|
255 | * @returns VBox status code.
|
---|
256 | * @param pTask The task to associate the context with.
|
---|
257 | * @param pvCtx Pointer to the context.
|
---|
258 | */
|
---|
259 | PDMR3DECL(int) PDMR3AsyncCompletionTaskAssociate(PPDMASYNCCOMPLETIONTASK pTask, void *pvCtx);
|
---|
260 |
|
---|
261 | /**
|
---|
262 | * Start processing the task handle.
|
---|
263 | * The task must have a type specific context.
|
---|
264 | *
|
---|
265 | * @returns VBox status code.
|
---|
266 | * @param pTask Pointer to the task which should be submited.
|
---|
267 | */
|
---|
268 | PDMR3DECL(int) PDMR3AsyncCompletionTaskSubmit(PPDMASYNCCOMPLETIONTASK pTask);
|
---|
269 |
|
---|
270 | /**
|
---|
271 | * Sets the user argument of a completion task.
|
---|
272 | *
|
---|
273 | * @returns VBox status code.
|
---|
274 | * @param pTask The async completion task.
|
---|
275 | * @param pvUser The user argument for the callback.
|
---|
276 | */
|
---|
277 | PDMR3DECL(int) PDMR3AsyncCompletionTaskSetUserArg(PPDMASYNCCOMPLETIONTASK pTask, void *pvUser);
|
---|
278 |
|
---|
279 | /**
|
---|
280 | * Suspends a async completion task.
|
---|
281 | *
|
---|
282 | * @returns VBox status codes:
|
---|
283 | * @retval VINF_SUCCESS on success.
|
---|
284 | * @retval VERR_PDM_ASYNC_COMPLETION_ALREADY_SUSPENDED if already suspended.
|
---|
285 | * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts).
|
---|
286 | * @param pTask The async completion task.
|
---|
287 | */
|
---|
288 | PDMR3DECL(int) PDMR3AsyncCompletionTaskSuspend(PPDMASYNCCOMPLETIONTASK pTask);
|
---|
289 |
|
---|
290 | /**
|
---|
291 | * Suspends a async completion task.
|
---|
292 | *
|
---|
293 | * @returns VBox status codes:
|
---|
294 | * @retval VINF_SUCCESS on success.
|
---|
295 | * @retval VERR_PDM_ASYNC_COMPLETION_NOT_SUSPENDED if not suspended.
|
---|
296 | * @retval VERR_INVALID_HANDLE if pTask is invalid (asserts).
|
---|
297 | * @param pTask The async completion task.
|
---|
298 | */
|
---|
299 | PDMR3DECL(int) PDMR3AsyncCompletionTaskResume(PPDMASYNCCOMPLETIONTASK pTask);
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Cancels a async completion task.
|
---|
303 | * The task doesn't have to be suspended.
|
---|
304 | *
|
---|
305 | * @returns VBox status code
|
---|
306 | * @param pTask The Task to cancel.
|
---|
307 | */
|
---|
308 | PDMR3DECL(int) PDMR3AsyncCompletionTaskCancel(PPDMASYNCCOMPLETIONTASK pTask);
|
---|
309 |
|
---|
310 | /**
|
---|
311 | * Destroys a async completion task.
|
---|
312 | *
|
---|
313 | * The task doesn't have to be suspended or anything.
|
---|
314 | *
|
---|
315 | * @returns VBox status codes:
|
---|
316 | * @retval VINF_SUCCESS on success.
|
---|
317 | * @retval VERR_INVALID_HANDLE if pTask is invalid but not NIL (asserts).
|
---|
318 | * @param pTask The async completion task.
|
---|
319 | */
|
---|
320 | PDMR3DECL(int) PDMR3AsyncCompletionTaskDestroy(PPDMASYNCCOMPLETIONTASK pTask);
|
---|
321 |
|
---|
322 | /*
|
---|
323 | * Host specific wrapper functions for the above API
|
---|
324 | */
|
---|
325 | #if defined(RT_OS_LINUX)
|
---|
326 |
|
---|
327 | struct iocb;
|
---|
328 |
|
---|
329 | /**
|
---|
330 | * Creates a completion task for an IO operation on Linux.
|
---|
331 | *
|
---|
332 | * The pvCtx callback argument will be pIoCB.
|
---|
333 | *
|
---|
334 | * @returns VBox status code.
|
---|
335 | * @param ppTask Where to store the task handle on success.
|
---|
336 | * @param pTemplate The async completion template.
|
---|
337 | * @param pIoCB The asynchronous I/O control block to wait for.
|
---|
338 | * @param pvUser The user argument for the callback.
|
---|
339 | */
|
---|
340 | DECLINLINE(int) PDMR3AsyncCompletionCreateLnxIO(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, const struct iocb *pIoCB, void *pvUser)
|
---|
341 | {
|
---|
342 | int rc = VINF_SUCCESS;
|
---|
343 | PPDMASYNCCOMPLETIONTASK pTask;
|
---|
344 |
|
---|
345 | rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)pIoCB, pvUser);
|
---|
346 | if (VBOX_FAILURE(rc))
|
---|
347 | {
|
---|
348 | AssertMsgFailed(("Creating Linux task failed\n"));
|
---|
349 | return rc;
|
---|
350 | }
|
---|
351 |
|
---|
352 | rc = PDMR3AsyncCompletionTaskSubmit(pTask);
|
---|
353 | if (VBOX_FAILURE(rc))
|
---|
354 | {
|
---|
355 | AssertMsgFailed(("Submitting Linux task failed\n"));
|
---|
356 | PDMR3AsyncCompletionTaskDestroy(pTask);
|
---|
357 | return rc;
|
---|
358 | }
|
---|
359 |
|
---|
360 | *ppTask = pTask;
|
---|
361 |
|
---|
362 | return rc;
|
---|
363 | }
|
---|
364 | #endif /* RT_OS_LINUX */
|
---|
365 |
|
---|
366 | #if defined(RT_OS_SOLARIS) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX)
|
---|
367 |
|
---|
368 | struct aiocb;
|
---|
369 |
|
---|
370 | /**
|
---|
371 | * Creates a completion task for an AIO operation on Unix like systems like Solaris, Darwin or FreeBSD.
|
---|
372 | * This method must be used too on Linux if the real asynchronous solution is not available.
|
---|
373 | *
|
---|
374 | * The pvCtx callback argument will be pAioCB.
|
---|
375 | *
|
---|
376 | * @returns VBox status code.
|
---|
377 | * @param ppTask Where to store the task handle on success.
|
---|
378 | * @param pTemplate The async completion template.
|
---|
379 | * @param pIoCB The asynchronous I/O control block to wait for.
|
---|
380 | * @param pvUser The user argument for the callback.
|
---|
381 | */
|
---|
382 | DECLINLINE(int) PDMR3AsyncCompletionCreateUnxAIO(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, const struct aiocb *pAioCB, void *pvUser)
|
---|
383 | {
|
---|
384 | int rc = VINF_SUCCESS;
|
---|
385 | PPDMASYNCCOMPLETIONTASK pTask;
|
---|
386 |
|
---|
387 | rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)pAioCB, pvUser);
|
---|
388 | if (VBOX_FAILURE(rc))
|
---|
389 | {
|
---|
390 | AssertMsgFailed(("Creating AIO task failed\n"));
|
---|
391 | return rc;
|
---|
392 | }
|
---|
393 |
|
---|
394 | rc = PDMR3AsyncCompletionTaskSubmit(pTask);
|
---|
395 | if (VBOX_FAILURE(rc))
|
---|
396 | {
|
---|
397 | AssertMsgFailed(("Submitting AIO task failed\n"));
|
---|
398 | PDMR3AsyncCompletionTaskDestroy(pTask);
|
---|
399 | return rc;
|
---|
400 | }
|
---|
401 |
|
---|
402 | *ppTask = pTask;
|
---|
403 |
|
---|
404 | return rc;
|
---|
405 | }
|
---|
406 | #endif /* RT_OS_SOLARIS || RT_OS_DARWIN || RT_OS_FREEBSD || RT_OS_LINUX */
|
---|
407 |
|
---|
408 | #ifdef RT_OS_OS2
|
---|
409 | /**
|
---|
410 | * Creates a completion task for an event semaphore on OS/2.
|
---|
411 | *
|
---|
412 | * The pvCtx callback argument will be hev.
|
---|
413 | *
|
---|
414 | * @returns VBox status code.
|
---|
415 | * @param ppTask Where to store the task handle on success.
|
---|
416 | * @param pTemplate The async completion template.
|
---|
417 | * @param hev The handle of the event semaphore to wait on.
|
---|
418 | * @param pvUser The user argument for the callback.
|
---|
419 | */
|
---|
420 | DECLINLINE(int) PDMR3AsyncCompletionCreateOs2Event(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, unsigned long hev, void *pvUser)
|
---|
421 | {
|
---|
422 | int rc = VINF_SUCCESS;
|
---|
423 | PPDMASYNCCOMPLETIONTASK pTask;
|
---|
424 |
|
---|
425 | rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)&hev, pvUser);
|
---|
426 | if (VBOX_FAILURE(rc))
|
---|
427 | {
|
---|
428 | AssertMsgFailed(("Creating OS/2 task failed\n"));
|
---|
429 | return rc;
|
---|
430 | }
|
---|
431 |
|
---|
432 | rc = PDMR3AsyncCompletionTaskSubmit(pTask);
|
---|
433 | if (VBOX_FAILURE(rc))
|
---|
434 | {
|
---|
435 | AssertMsgFailed(("Submitting OS/2 task failed\n"));
|
---|
436 | PDMR3AsyncCompletionTaskDestroy(pTask);
|
---|
437 | return rc;
|
---|
438 | }
|
---|
439 |
|
---|
440 | *ppTask = pTask;
|
---|
441 |
|
---|
442 | return rc;
|
---|
443 | }
|
---|
444 | #endif /* RT_OS_OS2 */
|
---|
445 |
|
---|
446 | #ifdef RT_OS_WINDOWS
|
---|
447 | /**
|
---|
448 | * Creates a completion task for an object on Windows.
|
---|
449 | *
|
---|
450 | * The pvCtx callback argument will be hObject.
|
---|
451 | *
|
---|
452 | * @returns VBox status code.
|
---|
453 | * @param ppTask Where to store the task handle on success.
|
---|
454 | * @param pTemplate The async completion template.
|
---|
455 | * @param hObject The object to wait for.
|
---|
456 | * @param pvUser The user argument for the callback.
|
---|
457 | */
|
---|
458 | DECLINLINE(int) PDMR3AsyncCompletionCreateWinObject(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, void *hObject, void *pvUser)
|
---|
459 | {
|
---|
460 | int rc = VINF_SUCCESS;
|
---|
461 | PPDMASYNCCOMPLETIONTASK pTask;
|
---|
462 |
|
---|
463 | rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_HOST, (void *)hObject, pvUser);
|
---|
464 | if (VBOX_FAILURE(rc))
|
---|
465 | {
|
---|
466 | AssertMsgFailed(("Creating Windows task failed\n"));
|
---|
467 | return rc;
|
---|
468 | }
|
---|
469 |
|
---|
470 | rc = PDMR3AsyncCompletionTaskSubmit(pTask);
|
---|
471 | if (VBOX_FAILURE(rc))
|
---|
472 | {
|
---|
473 | AssertMsgFailed(("Submitting Windows task failed\n"));
|
---|
474 | PDMR3AsyncCompletionTaskDestroy(pTask);
|
---|
475 | return rc;
|
---|
476 | }
|
---|
477 |
|
---|
478 | *ppTask = pTask;
|
---|
479 |
|
---|
480 | return rc;
|
---|
481 | }
|
---|
482 | #endif /* RT_OS_WINDOWS */
|
---|
483 |
|
---|
484 | /**
|
---|
485 | * Socket completion context (pvCtx).
|
---|
486 | */
|
---|
487 | typedef struct PDMASYNCCOMPLETIONSOCKET
|
---|
488 | {
|
---|
489 | /** The socket. */
|
---|
490 | RTSOCKET Socket;
|
---|
491 | /** Readable. */
|
---|
492 | bool fReadable;
|
---|
493 | /** Writable. */
|
---|
494 | bool fWriteable;
|
---|
495 | /** Exceptions. */
|
---|
496 | bool fXcpt;
|
---|
497 | } PDMASYNCCOMPLETIONSOCKET;
|
---|
498 | /** Pointer to a socket completion context. */
|
---|
499 | typedef PDMASYNCCOMPLETIONSOCKET *PPDMASYNCCOMPLETIONSOCKET;
|
---|
500 |
|
---|
501 | /**
|
---|
502 | * Creates a completion task for a socket.
|
---|
503 | *
|
---|
504 | * The pvCtx callback argument will be pointing to a PDMASYNCCOMPLETIONSOCKET structure.
|
---|
505 | *
|
---|
506 | * @returns VBox status code.
|
---|
507 | * @param ppTask Where to store the task handle on success.
|
---|
508 | * @param pTemplate The async completion template.
|
---|
509 | * @param Socket The socket.
|
---|
510 | * @param fReadable Whether to callback when the socket becomes readable.
|
---|
511 | * @param fWriteable Whether to callback when the socket becomes writable.
|
---|
512 | * @param fXcpt Whether to callback on exception.
|
---|
513 | * @param pvUser The user argument for the callback.
|
---|
514 | */
|
---|
515 | DECLINLINE(int) PDMR3AsyncCompletionCreateSocket(PPPDMASYNCCOMPLETIONTASK ppTask, PPDMASYNCCOMPLETIONTEMPLATE pTemplate, RTSOCKET Socket, bool fReadable, bool fWriteable, bool fXcpt, void *pvUser)
|
---|
516 | {
|
---|
517 | int rc = VINF_SUCCESS;
|
---|
518 | PPDMASYNCCOMPLETIONTASK pTask;
|
---|
519 | PDMASYNCCOMPLETIONSOCKET SocketContext;
|
---|
520 |
|
---|
521 | SocketContext.Socket = Socket;
|
---|
522 | SocketContext.fReadable = fReadable;
|
---|
523 | SocketContext.fWriteable = fWriteable;
|
---|
524 | SocketContext.fXcpt = fXcpt;
|
---|
525 |
|
---|
526 | rc = PDMR3AsyncCompletionTaskCreate(&pTask, pTemplate, PDMASYNCCOMPLETIONTASKTYPE_SOCKET, (void *)&SocketContext, pvUser);
|
---|
527 | if (VBOX_FAILURE(rc))
|
---|
528 | {
|
---|
529 | AssertMsgFailed(("Creating Socket task failed\n"));
|
---|
530 | return rc;
|
---|
531 | }
|
---|
532 |
|
---|
533 | rc = PDMR3AsyncCompletionTaskSubmit(pTask);
|
---|
534 | if (VBOX_FAILURE(rc))
|
---|
535 | {
|
---|
536 | AssertMsgFailed(("Submitting Socket task failed\n"));
|
---|
537 | PDMR3AsyncCompletionTaskDestroy(pTask);
|
---|
538 | return rc;
|
---|
539 | }
|
---|
540 |
|
---|
541 | *ppTask = pTask;
|
---|
542 |
|
---|
543 | return rc;
|
---|
544 | }
|
---|
545 |
|
---|
546 | /**
|
---|
547 | * Modifies a socket completion task.
|
---|
548 | *
|
---|
549 | * @returns VBox status code.
|
---|
550 | * @retval VINF_SUCCESS on success.
|
---|
551 | * @retval VERR_NOT_SUPPORTED if the task isn't a socket task.
|
---|
552 | * @param pTemplate The async completion template.
|
---|
553 | * @param Socket The socket
|
---|
554 | * @param fReadable Whether to callback when the socket becomes readable.
|
---|
555 | * @param fWriteable Whether to callback when the socket becomes writable.
|
---|
556 | * @param fXcpt Whether to callback on exception.
|
---|
557 | */
|
---|
558 | DECLINLINE(int) PDMR3AsyncCompletionModifySocket(PPDMASYNCCOMPLETIONTASK pTask, RTSOCKET Socket, bool fReadable, bool fWriteable, bool fXcpt)
|
---|
559 | {
|
---|
560 | int rc = VINF_SUCCESS;
|
---|
561 | PDMASYNCCOMPLETIONSOCKET SocketContext;
|
---|
562 |
|
---|
563 | SocketContext.Socket = Socket;
|
---|
564 | SocketContext.fReadable = fReadable;
|
---|
565 | SocketContext.fWriteable = fWriteable;
|
---|
566 | SocketContext.fXcpt = fXcpt;
|
---|
567 |
|
---|
568 | rc = PDMR3AsyncCompletionTaskAssociate(pTask, &SocketContext);
|
---|
569 | if (VBOX_FAILURE(rc))
|
---|
570 | {
|
---|
571 | AssertMsgFailed(("Modifying Socket task failed\n"));
|
---|
572 | return rc;
|
---|
573 | }
|
---|
574 |
|
---|
575 | return rc;
|
---|
576 | }
|
---|
577 |
|
---|
578 | /** @} */
|
---|
579 |
|
---|
580 | __END_DECLS
|
---|
581 |
|
---|
582 | #endif
|
---|
583 |
|
---|
584 |
|
---|
585 |
|
---|