widl: Add support for function parameter flags to SLTG typelib generator.
[wine.git] / server / async.c
blob80129ac0ac3c7947986a11ab603a95533b3e9011
1 /*
2 * Server-side async I/O support
4 * Copyright (C) 2007 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winternl.h"
31 #include "object.h"
32 #include "file.h"
33 #include "request.h"
34 #include "process.h"
35 #include "handle.h"
37 struct async
39 struct object obj; /* object header */
40 struct thread *thread; /* owning thread */
41 struct list queue_entry; /* entry in async queue list */
42 struct list process_entry; /* entry in process list */
43 struct async_queue *queue; /* queue containing this async */
44 struct fd *fd; /* fd associated with an unqueued async */
45 struct timeout_user *timeout;
46 unsigned int timeout_status; /* status to report upon timeout */
47 struct event *event;
48 async_data_t data; /* data for async I/O call */
49 struct iosb *iosb; /* I/O status block */
50 obj_handle_t wait_handle; /* pre-allocated wait handle */
51 unsigned int initial_status; /* status returned from initial request */
52 unsigned int signaled :1;
53 unsigned int pending :1; /* request successfully queued, but pending */
54 unsigned int direct_result :1;/* a flag if we're passing result directly from request instead of APC */
55 unsigned int alerted :1; /* fd is signaled, but we are waiting for client-side I/O */
56 unsigned int terminated :1; /* async has been terminated */
57 unsigned int canceled :1; /* have we already queued cancellation for this async? */
58 unsigned int unknown_status :1; /* initial status is not known yet */
59 unsigned int blocking :1; /* async is blocking */
60 struct completion *completion; /* completion associated with fd */
61 apc_param_t comp_key; /* completion key associated with fd */
62 unsigned int comp_flags; /* completion flags */
63 async_completion_callback completion_callback; /* callback to be called on completion */
64 void *completion_callback_private; /* argument to completion_callback */
67 static void async_dump( struct object *obj, int verbose );
68 static int async_signaled( struct object *obj, struct wait_queue_entry *entry );
69 static void async_satisfied( struct object * obj, struct wait_queue_entry *entry );
70 static void async_destroy( struct object *obj );
72 static const struct object_ops async_ops =
74 sizeof(struct async), /* size */
75 &no_type, /* type */
76 async_dump, /* dump */
77 add_queue, /* add_queue */
78 remove_queue, /* remove_queue */
79 async_signaled, /* signaled */
80 async_satisfied, /* satisfied */
81 no_signal, /* signal */
82 no_get_fd, /* get_fd */
83 default_map_access, /* map_access */
84 default_get_sd, /* get_sd */
85 default_set_sd, /* set_sd */
86 no_get_full_name, /* get_full_name */
87 no_lookup_name, /* lookup_name */
88 no_link_name, /* link_name */
89 NULL, /* unlink_name */
90 no_open_file, /* open_file */
91 no_kernel_obj_list, /* get_kernel_obj_list */
92 no_close_handle, /* close_handle */
93 async_destroy /* destroy */
96 static inline void async_reselect( struct async *async )
98 if (async->queue && async->fd) fd_reselect_async( async->fd, async->queue );
101 static void async_dump( struct object *obj, int verbose )
103 struct async *async = (struct async *)obj;
104 assert( obj->ops == &async_ops );
105 fprintf( stderr, "Async thread=%p\n", async->thread );
108 static int async_signaled( struct object *obj, struct wait_queue_entry *entry )
110 struct async *async = (struct async *)obj;
111 assert( obj->ops == &async_ops );
112 return async->signaled;
115 static void async_satisfied( struct object *obj, struct wait_queue_entry *entry )
117 struct async *async = (struct async *)obj;
118 assert( obj->ops == &async_ops );
120 /* we only return an async handle for asyncs created via create_request_async() */
121 assert( async->iosb );
123 if (async->direct_result)
125 async_set_result( &async->obj, async->iosb->status, async->iosb->result );
126 async->direct_result = 0;
129 if (async->initial_status == STATUS_PENDING && async->blocking)
130 set_wait_status( entry, async->iosb->status );
131 else
132 set_wait_status( entry, async->initial_status );
134 /* close wait handle here to avoid extra server round trip */
135 if (async->wait_handle)
137 close_handle( async->thread->process, async->wait_handle );
138 async->wait_handle = 0;
142 static void async_destroy( struct object *obj )
144 struct async *async = (struct async *)obj;
145 assert( obj->ops == &async_ops );
147 list_remove( &async->process_entry );
149 if (async->queue)
151 list_remove( &async->queue_entry );
152 async_reselect( async );
154 else if (async->fd) release_object( async->fd );
156 if (async->timeout) remove_timeout_user( async->timeout );
157 if (async->completion) release_object( async->completion );
158 if (async->event) release_object( async->event );
159 if (async->iosb) release_object( async->iosb );
160 release_object( async->thread );
163 /* notifies client thread of new status of its async request */
164 void async_terminate( struct async *async, unsigned int status )
166 struct iosb *iosb = async->iosb;
168 if (async->terminated) return;
170 async->terminated = 1;
171 if (async->iosb && async->iosb->status == STATUS_PENDING) async->iosb->status = status;
172 if (status == STATUS_ALERTED)
173 async->alerted = 1;
175 /* if no APC could be queued (e.g. the process is terminated),
176 * thread_queue_apc() may trigger async_set_result(), which may drop the
177 * last reference to the async, so grab a temporary reference here */
178 grab_object( async );
180 if (!async->direct_result)
182 apc_call_t data;
184 memset( &data, 0, sizeof(data) );
185 data.type = APC_ASYNC_IO;
186 data.async_io.user = async->data.user;
187 data.async_io.result = iosb ? iosb->result : 0;
189 /* this can happen if the initial status was unknown (i.e. for device
190 * files). the client should not fill the IOSB in this case; pass it as
191 * NULL to communicate that.
192 * note that we check the IOSB status and not the initial status */
193 if (NT_ERROR( status ) && (!is_fd_overlapped( async->fd ) || !async->pending))
194 data.async_io.sb = 0;
195 else
196 data.async_io.sb = async->data.iosb;
198 /* if there is output data, the client needs to make an extra request
199 * to retrieve it; use STATUS_ALERTED to signal this case */
200 if (iosb && iosb->out_data)
201 data.async_io.status = STATUS_ALERTED;
202 else
203 data.async_io.status = status;
205 thread_queue_apc( async->thread->process, async->thread, &async->obj, &data );
208 async_reselect( async );
210 release_object( async );
213 /* callback for timeout on an async request */
214 static void async_timeout( void *private )
216 struct async *async = private;
218 async->timeout = NULL;
219 async_terminate( async, async->timeout_status );
222 /* free an async queue, cancelling all async operations */
223 void free_async_queue( struct async_queue *queue )
225 struct async *async, *next;
227 LIST_FOR_EACH_ENTRY_SAFE( async, next, &queue->queue, struct async, queue_entry )
229 if (!async->completion) async->completion = fd_get_completion( async->fd, &async->comp_key );
230 async->fd = NULL;
231 async_terminate( async, STATUS_HANDLES_CLOSED );
232 async->queue = NULL;
233 release_object( &async->obj );
237 void queue_async( struct async_queue *queue, struct async *async )
239 /* fd will be set to NULL in free_async_queue when fd is destroyed */
240 release_object( async->fd );
242 async->queue = queue;
243 grab_object( async );
244 list_add_tail( &queue->queue, &async->queue_entry );
246 set_fd_signaled( async->fd, 0 );
249 /* create an async on a given queue of a fd */
250 struct async *create_async( struct fd *fd, struct thread *thread, const async_data_t *data, struct iosb *iosb )
252 struct event *event = NULL;
253 struct async *async;
255 if (data->event && !(event = get_event_obj( thread->process, data->event, EVENT_MODIFY_STATE )))
256 return NULL;
258 if (!(async = alloc_object( &async_ops )))
260 if (event) release_object( event );
261 return NULL;
264 async->thread = (struct thread *)grab_object( thread );
265 async->event = event;
266 async->data = *data;
267 async->timeout = NULL;
268 async->queue = NULL;
269 async->fd = (struct fd *)grab_object( fd );
270 async->initial_status = STATUS_PENDING;
271 async->signaled = 0;
272 async->pending = 1;
273 async->wait_handle = 0;
274 async->direct_result = 0;
275 async->alerted = 0;
276 async->terminated = 0;
277 async->canceled = 0;
278 async->unknown_status = 0;
279 async->blocking = !is_fd_overlapped( fd );
280 async->completion = fd_get_completion( fd, &async->comp_key );
281 async->comp_flags = 0;
282 async->completion_callback = NULL;
283 async->completion_callback_private = NULL;
285 if (iosb) async->iosb = (struct iosb *)grab_object( iosb );
286 else async->iosb = NULL;
288 list_add_head( &thread->process->asyncs, &async->process_entry );
289 if (event) reset_event( event );
291 if (async->completion && data->apc)
293 release_object( async );
294 set_error( STATUS_INVALID_PARAMETER );
295 return NULL;
298 return async;
301 /* set the initial status of an async whose status was previously unknown
302 * the initial status may be STATUS_PENDING */
303 void async_set_initial_status( struct async *async, unsigned int status )
305 async->initial_status = status;
306 async->unknown_status = 0;
309 void set_async_pending( struct async *async )
311 if (!async->terminated)
312 async->pending = 1;
315 void async_wake_obj( struct async *async )
317 assert( !async->unknown_status );
318 if (!async->blocking)
320 async->signaled = 1;
321 wake_up( &async->obj, 0 );
325 static void async_call_completion_callback( struct async *async )
327 if (async->completion_callback)
328 async->completion_callback( async->completion_callback_private );
329 async->completion_callback = NULL;
332 /* return async object status and wait handle to client */
333 obj_handle_t async_handoff( struct async *async, data_size_t *result, int force_blocking )
335 async->blocking = force_blocking || async->blocking;
337 if (async->unknown_status)
339 /* even the initial status is not known yet */
340 set_error( STATUS_PENDING );
341 return async->wait_handle;
344 if (get_error() == STATUS_ALERTED)
346 /* give the client opportunity to complete synchronously. after the
347 * client performs the I/O, it reports the result back to the server
348 * via the set_async_direct_result request. if it turns out that the
349 * I/O request is not actually immediately satiable, the client may
350 * then choose to re-queue the async by reporting STATUS_PENDING
351 * instead.
353 * since we're deferring the initial I/O (to the client), we mark the
354 * async as having unknown initial status (unknown_status = 1). note
355 * that we don't reuse async_set_unknown_status() here. this is because
356 * the one responsible for performing the I/O is not the device driver,
357 * but instead the client that requested the I/O in the first place.
359 * also, async_set_unknown_status() would set direct_result to zero
360 * forcing APC_ASYNC_IO to fire in async_terminate(), which is not
361 * useful due to subtle semantic differences between synchronous and
362 * asynchronous completion.
364 async->unknown_status = 1;
365 async_terminate( async, STATUS_ALERTED );
366 return async->wait_handle;
369 async->initial_status = get_error();
371 if (!async->pending && NT_ERROR( get_error() ))
373 async->iosb->status = get_error();
374 async_call_completion_callback( async );
376 close_handle( async->thread->process, async->wait_handle );
377 async->wait_handle = 0;
378 return 0;
381 if (get_error() != STATUS_PENDING)
383 /* status and data are already set and returned */
384 async_terminate( async, get_error() );
386 else if (async->iosb->status != STATUS_PENDING)
388 /* result is already available in iosb, return it */
389 if (async->iosb->out_data)
391 set_reply_data_ptr( async->iosb->out_data, async->iosb->out_size );
392 async->iosb->out_data = NULL;
396 if (async->iosb->status != STATUS_PENDING)
398 if (result) *result = async->iosb->result;
399 async->signaled = 1;
401 else
403 async->direct_result = 0;
404 async->pending = 1;
405 if (!async->blocking)
407 close_handle( async->thread->process, async->wait_handle);
408 async->wait_handle = 0;
411 async->initial_status = async->iosb->status;
412 set_error( async->iosb->status );
413 return async->wait_handle;
416 /* complete a request-based async with a pre-allocated buffer */
417 void async_request_complete( struct async *async, unsigned int status, data_size_t result,
418 data_size_t out_size, void *out_data )
420 struct iosb *iosb = async_get_iosb( async );
422 /* the async may have already been canceled */
423 if (iosb->status != STATUS_PENDING)
425 release_object( iosb );
426 free( out_data );
427 return;
430 iosb->status = status;
431 iosb->result = result;
432 iosb->out_data = out_data;
433 iosb->out_size = out_size;
435 release_object( iosb );
437 async_terminate( async, status );
440 /* complete a request-based async */
441 void async_request_complete_alloc( struct async *async, unsigned int status, data_size_t result,
442 data_size_t out_size, const void *out_data )
444 void *out_data_copy = NULL;
446 if (out_size && !(out_data_copy = memdup( out_data, out_size )))
448 async_terminate( async, STATUS_NO_MEMORY );
449 return;
452 async_request_complete( async, status, result, out_size, out_data_copy );
455 /* mark an async as having unknown initial status */
456 void async_set_unknown_status( struct async *async )
458 async->unknown_status = 1;
459 async->direct_result = 0;
462 /* set the timeout of an async operation */
463 void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status )
465 if (async->timeout) remove_timeout_user( async->timeout );
466 if (timeout != TIMEOUT_INFINITE) async->timeout = add_timeout_user( timeout, async_timeout, async );
467 else async->timeout = NULL;
468 async->timeout_status = status;
471 /* set a callback to be notified when the async is completed */
472 void async_set_completion_callback( struct async *async, async_completion_callback func, void *private )
474 async->completion_callback = func;
475 async->completion_callback_private = private;
478 static void add_async_completion( struct async *async, apc_param_t cvalue, unsigned int status,
479 apc_param_t information )
481 if (async->fd && !async->completion) async->completion = fd_get_completion( async->fd, &async->comp_key );
482 if (async->completion) add_completion( async->completion, async->comp_key, cvalue, status, information );
485 /* store the result of the client-side async callback */
486 void async_set_result( struct object *obj, unsigned int status, apc_param_t total )
488 struct async *async = (struct async *)obj;
490 if (obj->ops != &async_ops) return; /* in case the client messed up the APC results */
492 assert( async->terminated ); /* it must have been woken up if we get a result */
494 if (async->unknown_status) async_set_initial_status( async, status );
496 if (async->alerted && status == STATUS_PENDING) /* restart it */
498 async->terminated = 0;
499 async->alerted = 0;
500 async_reselect( async );
502 else
504 if (async->timeout) remove_timeout_user( async->timeout );
505 async->timeout = NULL;
506 async->terminated = 1;
507 if (async->iosb) async->iosb->status = status;
509 /* don't signal completion if the async failed synchronously
510 * this can happen if the initial status was unknown (i.e. for device files)
511 * note that we check the IOSB status here, not the initial status */
512 if (async->pending || !NT_ERROR( status ))
514 if (async->data.apc)
516 apc_call_t data;
517 memset( &data, 0, sizeof(data) );
518 data.type = APC_USER;
519 data.user.func = async->data.apc;
520 data.user.args[0] = async->data.apc_context;
521 data.user.args[1] = async->data.iosb;
522 data.user.args[2] = 0;
523 thread_queue_apc( NULL, async->thread, NULL, &data );
525 else if (async->data.apc_context && (async->pending ||
526 !(async->comp_flags & FILE_SKIP_COMPLETION_PORT_ON_SUCCESS)))
528 add_async_completion( async, async->data.apc_context, status, total );
531 if (async->event) set_event( async->event );
532 else if (async->fd) set_fd_signaled( async->fd, 1 );
535 if (!async->signaled)
537 async->signaled = 1;
538 wake_up( &async->obj, 0 );
541 async_call_completion_callback( async );
543 if (async->queue)
545 list_remove( &async->queue_entry );
546 async_reselect( async );
547 async->fd = NULL;
548 async->queue = NULL;
549 release_object( async );
554 int async_queue_has_waiting_asyncs( struct async_queue *queue )
556 struct async *async;
558 LIST_FOR_EACH_ENTRY( async, &queue->queue, struct async, queue_entry )
559 if (!async->unknown_status) return 1;
561 return 0;
564 /* check if an async operation is waiting to be alerted */
565 int async_waiting( struct async_queue *queue )
567 struct list *ptr;
568 struct async *async;
570 if (!(ptr = list_head( &queue->queue ))) return 0;
571 async = LIST_ENTRY( ptr, struct async, queue_entry );
572 return !async->terminated;
575 static int cancel_async( struct process *process, struct object *obj, struct thread *thread, client_ptr_t iosb )
577 struct async *async;
578 int woken = 0;
580 /* FIXME: it would probably be nice to replace the "canceled" flag with a
581 * single LIST_FOR_EACH_ENTRY_SAFE, but currently cancelling an async can
582 * cause other asyncs to be removed via async_reselect() */
584 restart:
585 LIST_FOR_EACH_ENTRY( async, &process->asyncs, struct async, process_entry )
587 if (async->terminated || async->canceled) continue;
588 if ((!obj || (get_fd_user( async->fd ) == obj)) &&
589 (!thread || async->thread == thread) &&
590 (!iosb || async->data.iosb == iosb))
592 async->canceled = 1;
593 fd_cancel_async( async->fd, async );
594 woken++;
595 goto restart;
598 return woken;
601 static int cancel_blocking( struct process *process, struct thread *thread, client_ptr_t iosb )
603 struct async *async;
604 int woken = 0;
606 restart:
607 LIST_FOR_EACH_ENTRY( async, &process->asyncs, struct async, process_entry )
609 if (async->terminated || async->canceled) continue;
610 if (async->blocking && async->thread == thread &&
611 (!iosb || async->data.iosb == iosb))
613 async->canceled = 1;
614 fd_cancel_async( async->fd, async );
615 woken++;
616 goto restart;
619 return woken;
622 void cancel_process_asyncs( struct process *process )
624 cancel_async( process, NULL, NULL, 0 );
627 int async_close_obj_handle( struct object *obj, struct process *process, obj_handle_t handle )
629 /* Handle a special case when the last object handle in the given process is closed.
630 * If this is the last object handle overall that is handled in object's close_handle and
631 * destruction. */
632 struct async *async;
634 if (obj->handle_count == 1 || get_obj_handle_count( process, obj ) != 1) return 1;
636 restart:
637 LIST_FOR_EACH_ENTRY( async, &process->asyncs, struct async, process_entry )
639 if (async->terminated || async->canceled || get_fd_user( async->fd ) != obj) continue;
640 if (!async->completion || !async->data.apc_context || async->event) continue;
642 async->canceled = 1;
643 fd_cancel_async( async->fd, async );
644 goto restart;
646 return 1;
649 void cancel_terminating_thread_asyncs( struct thread *thread )
651 struct async *async;
653 restart:
654 LIST_FOR_EACH_ENTRY( async, &thread->process->asyncs, struct async, process_entry )
656 if (async->thread != thread || async->terminated || async->canceled) continue;
657 if (async->completion && async->data.apc_context && !async->event) continue;
659 async->canceled = 1;
660 fd_cancel_async( async->fd, async );
661 goto restart;
665 /* wake up async operations on the queue */
666 void async_wake_up( struct async_queue *queue, unsigned int status )
668 struct list *ptr, *next;
670 LIST_FOR_EACH_SAFE( ptr, next, &queue->queue )
672 struct async *async = LIST_ENTRY( ptr, struct async, queue_entry );
673 async_terminate( async, status );
674 if (status == STATUS_ALERTED) break; /* only wake up the first one */
678 static void iosb_dump( struct object *obj, int verbose );
679 static void iosb_destroy( struct object *obj );
681 static const struct object_ops iosb_ops =
683 sizeof(struct iosb), /* size */
684 &no_type, /* type */
685 iosb_dump, /* dump */
686 no_add_queue, /* add_queue */
687 NULL, /* remove_queue */
688 NULL, /* signaled */
689 NULL, /* satisfied */
690 no_signal, /* signal */
691 no_get_fd, /* get_fd */
692 default_map_access, /* map_access */
693 default_get_sd, /* get_sd */
694 default_set_sd, /* set_sd */
695 no_get_full_name, /* get_full_name */
696 no_lookup_name, /* lookup_name */
697 no_link_name, /* link_name */
698 NULL, /* unlink_name */
699 no_open_file, /* open_file */
700 no_kernel_obj_list, /* get_kernel_obj_list */
701 no_close_handle, /* close_handle */
702 iosb_destroy /* destroy */
705 static void iosb_dump( struct object *obj, int verbose )
707 assert( obj->ops == &iosb_ops );
708 fprintf( stderr, "I/O status block\n" );
711 static void iosb_destroy( struct object *obj )
713 struct iosb *iosb = (struct iosb *)obj;
715 free( iosb->in_data );
716 free( iosb->out_data );
719 /* allocate iosb struct */
720 static struct iosb *create_iosb( const void *in_data, data_size_t in_size, data_size_t out_size )
722 struct iosb *iosb;
724 if (!(iosb = alloc_object( &iosb_ops ))) return NULL;
726 iosb->status = STATUS_PENDING;
727 iosb->result = 0;
728 iosb->in_size = in_size;
729 iosb->in_data = NULL;
730 iosb->out_size = out_size;
731 iosb->out_data = NULL;
733 if (in_size && !(iosb->in_data = memdup( in_data, in_size )))
735 release_object( iosb );
736 iosb = NULL;
739 return iosb;
742 /* create an async associated with iosb for async-based requests
743 * returned async must be passed to async_handoff */
744 struct async *create_request_async( struct fd *fd, unsigned int comp_flags, const async_data_t *data )
746 struct async *async;
747 struct iosb *iosb;
749 if (!(iosb = create_iosb( get_req_data(), get_req_data_size(), get_reply_max_size() )))
750 return NULL;
752 async = create_async( fd, current, data, iosb );
753 release_object( iosb );
754 if (async)
756 if (!(async->wait_handle = alloc_handle( current->process, async, SYNCHRONIZE, 0 )))
758 release_object( async );
759 return NULL;
761 async->pending = 0;
762 async->direct_result = 1;
763 async->comp_flags = comp_flags;
765 return async;
768 struct iosb *async_get_iosb( struct async *async )
770 return async->iosb ? (struct iosb *)grab_object( async->iosb ) : NULL;
773 struct thread *async_get_thread( struct async *async )
775 return async->thread;
778 /* find the first pending async in queue */
779 struct async *find_pending_async( struct async_queue *queue )
781 struct async *async;
782 LIST_FOR_EACH_ENTRY( async, &queue->queue, struct async, queue_entry )
783 if (!async->terminated) return (struct async *)grab_object( async );
784 return NULL;
787 /* cancels sync I/O on a thread */
788 DECL_HANDLER(cancel_sync)
790 struct thread *thread = get_thread_from_handle( req->handle, THREAD_TERMINATE );
792 if (thread)
794 if (!cancel_blocking( current->process, thread, req->iosb ))
795 set_error( STATUS_NOT_FOUND );
796 release_object( thread );
800 /* cancels all async I/O */
801 DECL_HANDLER(cancel_async)
803 struct object *obj = get_handle_obj( current->process, req->handle, 0, NULL );
804 struct thread *thread = req->only_thread ? current : NULL;
806 if (obj)
808 int count = cancel_async( current->process, obj, thread, req->iosb );
809 if (!count && req->iosb) set_error( STATUS_NOT_FOUND );
810 release_object( obj );
814 /* get async result from associated iosb */
815 DECL_HANDLER(get_async_result)
817 struct iosb *iosb = NULL;
818 struct async *async;
820 LIST_FOR_EACH_ENTRY( async, &current->process->asyncs, struct async, process_entry )
821 if (async->data.user == req->user_arg)
823 iosb = async->iosb;
824 break;
827 if (!iosb)
829 set_error( STATUS_INVALID_PARAMETER );
830 return;
833 if (iosb->out_data)
835 data_size_t size = min( iosb->out_size, get_reply_max_size() );
836 if (size)
838 set_reply_data_ptr( iosb->out_data, size );
839 iosb->out_data = NULL;
842 set_error( iosb->status );
845 /* notify direct completion of async and close the wait handle if not blocking */
846 DECL_HANDLER(set_async_direct_result)
848 struct async *async = (struct async *)get_handle_obj( current->process, req->handle, 0, &async_ops );
849 unsigned int status = req->status;
851 if (!async) return;
853 if (!async->unknown_status || !async->terminated || !async->alerted)
855 set_error( STATUS_INVALID_PARAMETER );
856 release_object( &async->obj );
857 return;
860 if (status == STATUS_PENDING)
862 async->direct_result = 0;
863 async->pending = 1;
865 else if (req->mark_pending)
867 async->pending = 1;
870 /* if the I/O has completed successfully (or unsuccessfully, and
871 * async->pending is set), the client would have already set the IOSB.
872 * therefore, we can do async_set_result() directly and let the client skip
873 * waiting on wait_handle.
875 async_set_result( &async->obj, status, req->information );
877 /* close wait handle here to avoid extra server round trip, if the I/O
878 * either has completed, or is pending and not blocking.
880 if (status != STATUS_PENDING || !async->blocking)
882 close_handle( async->thread->process, async->wait_handle );
883 async->wait_handle = 0;
886 /* report back to the client whether the wait handle has been closed.
887 * handle will be 0 if closed by us; otherwise the original value is
888 * retained
890 reply->handle = async->wait_handle;
892 release_object( &async->obj );