server: Added infrastructure for access rights mapping.
[wine/gsoc_dplay.git] / server / named_pipe.c
blob07a7ceb28d0fadd649ce6379877bf52614eb1c64
1 /*
2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
5 * Copyright (C) 2001 Mike McCormack
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * TODO:
22 * message mode
25 #include "config.h"
26 #include "wine/port.h"
28 #include <assert.h>
29 #include <fcntl.h>
30 #include <string.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_SOCKET_H
37 #include <sys/socket.h>
38 #endif
39 #include <time.h>
40 #include <unistd.h>
41 #ifdef HAVE_POLL_H
42 #include <poll.h>
43 #endif
45 #include "ntstatus.h"
46 #define WIN32_NO_STATUS
47 #include "windef.h"
48 #include "winternl.h"
50 #include "file.h"
51 #include "handle.h"
52 #include "thread.h"
53 #include "request.h"
55 enum pipe_state
57 ps_idle_server,
58 ps_wait_open,
59 ps_connected_server,
60 ps_wait_disconnect,
61 ps_disconnected_server,
62 ps_wait_connect
65 struct named_pipe;
67 struct pipe_server
69 struct object obj; /* object header */
70 struct fd *fd; /* pipe file descriptor */
71 struct list entry; /* entry in named pipe servers list */
72 enum pipe_state state; /* server state */
73 struct pipe_client *client; /* client that this server is connected to */
74 struct named_pipe *pipe;
75 struct timeout_user *flush_poll;
76 struct event *event;
77 struct list wait_q; /* only a single one can be queued */
78 unsigned int options; /* pipe options */
81 struct pipe_client
83 struct object obj; /* object header */
84 struct fd *fd; /* pipe file descriptor */
85 struct pipe_server *server; /* server that this client is connected to */
86 unsigned int flags; /* file flags */
89 struct named_pipe
91 struct object obj; /* object header */
92 unsigned int flags;
93 unsigned int maxinstances;
94 unsigned int outsize;
95 unsigned int insize;
96 unsigned int timeout;
97 unsigned int instances;
98 struct list servers; /* list of servers using this pipe */
99 struct list waiters; /* list of clients waiting to connect */
102 struct named_pipe_device
104 struct object obj; /* object header */
105 struct fd *fd; /* pseudo-fd for ioctls */
106 struct namespace *pipes; /* named pipe namespace */
109 static void named_pipe_dump( struct object *obj, int verbose );
110 static void named_pipe_destroy( struct object *obj );
112 static const struct object_ops named_pipe_ops =
114 sizeof(struct named_pipe), /* size */
115 named_pipe_dump, /* dump */
116 no_add_queue, /* add_queue */
117 NULL, /* remove_queue */
118 NULL, /* signaled */
119 NULL, /* satisfied */
120 no_signal, /* signal */
121 no_get_fd, /* get_fd */
122 no_map_access, /* map_access */
123 no_lookup_name, /* lookup_name */
124 no_close_handle, /* close_handle */
125 named_pipe_destroy /* destroy */
128 /* server end functions */
129 static void pipe_server_dump( struct object *obj, int verbose );
130 static struct fd *pipe_server_get_fd( struct object *obj );
131 static void pipe_server_destroy( struct object *obj);
132 static int pipe_server_flush( struct fd *fd, struct event **event );
133 static int pipe_server_get_info( struct fd *fd );
135 static const struct object_ops pipe_server_ops =
137 sizeof(struct pipe_server), /* size */
138 pipe_server_dump, /* dump */
139 default_fd_add_queue, /* add_queue */
140 default_fd_remove_queue, /* remove_queue */
141 default_fd_signaled, /* signaled */
142 no_satisfied, /* satisfied */
143 no_signal, /* signal */
144 pipe_server_get_fd, /* get_fd */
145 no_map_access, /* map_access */
146 no_lookup_name, /* lookup_name */
147 no_close_handle, /* close_handle */
148 pipe_server_destroy /* destroy */
151 static const struct fd_ops pipe_server_fd_ops =
153 default_fd_get_poll_events, /* get_poll_events */
154 default_poll_event, /* poll_event */
155 pipe_server_flush, /* flush */
156 pipe_server_get_info, /* get_file_info */
157 default_fd_queue_async, /* queue_async */
158 default_fd_cancel_async, /* cancel_async */
161 /* client end functions */
162 static void pipe_client_dump( struct object *obj, int verbose );
163 static struct fd *pipe_client_get_fd( struct object *obj );
164 static void pipe_client_destroy( struct object *obj );
165 static int pipe_client_flush( struct fd *fd, struct event **event );
166 static int pipe_client_get_info( struct fd *fd );
168 static const struct object_ops pipe_client_ops =
170 sizeof(struct pipe_client), /* size */
171 pipe_client_dump, /* dump */
172 default_fd_add_queue, /* add_queue */
173 default_fd_remove_queue, /* remove_queue */
174 default_fd_signaled, /* signaled */
175 no_satisfied, /* satisfied */
176 no_signal, /* signal */
177 pipe_client_get_fd, /* get_fd */
178 no_map_access, /* map_access */
179 no_lookup_name, /* lookup_name */
180 no_close_handle, /* close_handle */
181 pipe_client_destroy /* destroy */
184 static const struct fd_ops pipe_client_fd_ops =
186 default_fd_get_poll_events, /* get_poll_events */
187 default_poll_event, /* poll_event */
188 pipe_client_flush, /* flush */
189 pipe_client_get_info, /* get_file_info */
190 default_fd_queue_async, /* queue_async */
191 default_fd_cancel_async /* cancel_async */
194 static void named_pipe_device_dump( struct object *obj, int verbose );
195 static struct fd *named_pipe_device_get_fd( struct object *obj );
196 static struct object *named_pipe_device_lookup_name( struct object *obj,
197 struct unicode_str *name, unsigned int attr );
198 static void named_pipe_device_destroy( struct object *obj );
200 static const struct object_ops named_pipe_device_ops =
202 sizeof(struct named_pipe_device), /* size */
203 named_pipe_device_dump, /* dump */
204 no_add_queue, /* add_queue */
205 NULL, /* remove_queue */
206 NULL, /* signaled */
207 no_satisfied, /* satisfied */
208 no_signal, /* signal */
209 named_pipe_device_get_fd, /* get_fd */
210 no_map_access, /* map_access */
211 named_pipe_device_lookup_name, /* lookup_name */
212 no_close_handle, /* close_handle */
213 named_pipe_device_destroy /* destroy */
216 static const struct fd_ops named_pipe_device_fd_ops =
218 default_fd_get_poll_events, /* get_poll_events */
219 default_poll_event, /* poll_event */
220 no_flush, /* flush */
221 no_get_file_info, /* get_file_info */
222 default_fd_queue_async, /* queue_async */
223 default_fd_cancel_async /* cancel_async */
226 static void named_pipe_dump( struct object *obj, int verbose )
228 struct named_pipe *pipe = (struct named_pipe *) obj;
229 assert( obj->ops == &named_pipe_ops );
230 fprintf( stderr, "Named pipe " );
231 dump_object_name( &pipe->obj );
232 fprintf( stderr, "\n" );
235 static void pipe_server_dump( struct object *obj, int verbose )
237 struct pipe_server *server = (struct pipe_server *) obj;
238 assert( obj->ops == &pipe_server_ops );
239 fprintf( stderr, "Named pipe server pipe=%p state=%d\n", server->pipe, server->state );
242 static void pipe_client_dump( struct object *obj, int verbose )
244 struct pipe_client *client = (struct pipe_client *) obj;
245 assert( obj->ops == &pipe_client_ops );
246 fprintf( stderr, "Named pipe client server=%p\n", client->server );
249 static void named_pipe_destroy( struct object *obj)
251 struct named_pipe *pipe = (struct named_pipe *) obj;
253 assert( list_empty( &pipe->servers ) );
254 assert( !pipe->instances );
255 async_terminate_queue( &pipe->waiters, STATUS_HANDLES_CLOSED );
258 static struct fd *pipe_client_get_fd( struct object *obj )
260 struct pipe_client *client = (struct pipe_client *) obj;
261 if (client->fd)
262 return (struct fd *) grab_object( client->fd );
263 set_error( STATUS_PIPE_DISCONNECTED );
264 return NULL;
267 static struct fd *pipe_server_get_fd( struct object *obj )
269 struct pipe_server *server = (struct pipe_server *) obj;
271 switch(server->state)
273 case ps_connected_server:
274 case ps_wait_disconnect:
275 assert( server->fd );
276 return (struct fd *) grab_object( server->fd );
278 case ps_wait_open:
279 case ps_idle_server:
280 set_error( STATUS_PIPE_LISTENING );
281 break;
283 case ps_disconnected_server:
284 case ps_wait_connect:
285 set_error( STATUS_PIPE_DISCONNECTED );
286 break;
288 return NULL;
292 static void notify_empty( struct pipe_server *server )
294 if (!server->flush_poll)
295 return;
296 assert( server->state == ps_connected_server );
297 assert( server->event );
298 remove_timeout_user( server->flush_poll );
299 server->flush_poll = NULL;
300 set_event( server->event );
301 release_object( server->event );
302 server->event = NULL;
305 static void do_disconnect( struct pipe_server *server )
307 /* we may only have a server fd, if the client disconnected */
308 if (server->client)
310 assert( server->client->server == server );
311 assert( server->client->fd );
312 release_object( server->client->fd );
313 server->client->fd = NULL;
315 assert( server->fd );
316 release_object( server->fd );
317 server->fd = NULL;
320 static void pipe_server_destroy( struct object *obj)
322 struct pipe_server *server = (struct pipe_server *)obj;
324 assert( obj->ops == &pipe_server_ops );
326 if (server->fd)
328 notify_empty( server );
329 do_disconnect( server );
332 if (server->client)
334 server->client->server = NULL;
335 server->client = NULL;
338 async_terminate_head( &server->wait_q, STATUS_HANDLES_CLOSED );
340 assert( server->pipe->instances );
341 server->pipe->instances--;
343 list_remove( &server->entry );
344 release_object( server->pipe );
347 static void pipe_client_destroy( struct object *obj)
349 struct pipe_client *client = (struct pipe_client *)obj;
350 struct pipe_server *server = client->server;
352 assert( obj->ops == &pipe_client_ops );
354 if (server)
356 notify_empty( server );
358 switch(server->state)
360 case ps_connected_server:
361 /* Don't destroy the server's fd here as we can't
362 do a successful flush without it. */
363 server->state = ps_wait_disconnect;
364 release_object( client->fd );
365 client->fd = NULL;
366 break;
367 case ps_disconnected_server:
368 server->state = ps_wait_connect;
369 break;
370 case ps_idle_server:
371 case ps_wait_open:
372 case ps_wait_disconnect:
373 case ps_wait_connect:
374 assert( 0 );
376 assert( server->client );
377 server->client = NULL;
378 client->server = NULL;
380 assert( !client->fd );
383 static void named_pipe_device_dump( struct object *obj, int verbose )
385 assert( obj->ops == &named_pipe_device_ops );
386 fprintf( stderr, "Named pipe device\n" );
389 static struct fd *named_pipe_device_get_fd( struct object *obj )
391 struct named_pipe_device *device = (struct named_pipe_device *)obj;
392 return device->fd;
395 static struct object *named_pipe_device_lookup_name( struct object *obj, struct unicode_str *name,
396 unsigned int attr )
398 struct named_pipe_device *device = (struct named_pipe_device*)obj;
399 struct object *found;
401 assert( obj->ops == &named_pipe_device_ops );
402 assert( device->pipes );
404 if ((found = find_object( device->pipes, name, attr | OBJ_CASE_INSENSITIVE )))
405 name->len = 0;
407 return found;
410 static void named_pipe_device_destroy( struct object *obj )
412 struct named_pipe_device *device = (struct named_pipe_device*)obj;
413 assert( obj->ops == &named_pipe_device_ops );
414 if (device->fd) release_object( device->fd );
415 if (device->pipes) free( device->pipes );
418 /* this will be deleted as soon an we fix wait_named_pipe */
419 static struct named_pipe_device *named_pipe_device;
421 struct named_pipe_device *create_named_pipe_device( struct directory *root,
422 const struct unicode_str *name )
424 struct named_pipe_device *dev;
426 if ((dev = create_named_object_dir( root, name, 0, &named_pipe_device_ops )) &&
427 get_error() != STATUS_OBJECT_NAME_EXISTS)
429 dev->pipes = NULL;
430 if (!(dev->fd = alloc_pseudo_fd( &named_pipe_device_fd_ops, &dev->obj )) ||
431 !(dev->pipes = create_namespace( 7 )))
433 release_object( dev );
434 dev = NULL;
437 named_pipe_device = dev;
438 return dev;
441 static int pipe_data_remaining( struct pipe_server *server )
443 struct pollfd pfd;
444 int fd;
446 assert( server->client );
448 fd = get_unix_fd( server->client->fd );
449 if (fd < 0)
450 return 0;
451 pfd.fd = fd;
452 pfd.events = POLLIN;
453 pfd.revents = 0;
455 if (0 > poll( &pfd, 1, 0 ))
456 return 0;
458 return pfd.revents&POLLIN;
461 static void check_flushed( void *arg )
463 struct pipe_server *server = (struct pipe_server*) arg;
465 assert( server->event );
466 if (pipe_data_remaining( server ))
468 struct timeval tv;
470 gettimeofday( &tv, NULL );
471 add_timeout( &tv, 100 );
472 server->flush_poll = add_timeout_user( &tv, check_flushed, server );
474 else
476 /* notify_empty( server ); */
477 server->flush_poll = NULL;
478 set_event( server->event );
479 release_object( server->event );
480 server->event = NULL;
484 static int pipe_server_flush( struct fd *fd, struct event **event )
486 struct pipe_server *server = get_fd_user( fd );
488 if (!server)
489 return 0;
491 if (server->state != ps_connected_server)
492 return 0;
494 /* FIXME: if multiple threads flush the same pipe,
495 maybe should create a list of processes to notify */
496 if (server->flush_poll)
497 return 0;
499 if (pipe_data_remaining( server ))
501 struct timeval tv;
503 /* this kind of sux -
504 there's no unix way to be alerted when a pipe becomes empty */
505 server->event = create_event( NULL, NULL, 0, 0, 0 );
506 if (!server->event)
507 return 0;
508 gettimeofday( &tv, NULL );
509 add_timeout( &tv, 100 );
510 server->flush_poll = add_timeout_user( &tv, check_flushed, server );
511 *event = server->event;
514 return 0;
517 static int pipe_client_flush( struct fd *fd, struct event **event )
519 /* FIXME: what do we have to do for this? */
520 return 0;
523 static inline int is_overlapped( unsigned int options )
525 return !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
528 static int pipe_server_get_info( struct fd *fd )
530 struct pipe_server *server = get_fd_user( fd );
531 int flags = FD_FLAG_AVAILABLE;
533 if (is_overlapped( server->options )) flags |= FD_FLAG_OVERLAPPED;
535 return flags;
538 static int pipe_client_get_info( struct fd *fd )
540 struct pipe_client *client = get_fd_user( fd );
541 int flags = FD_FLAG_AVAILABLE;
543 if (is_overlapped( client->flags )) flags |= FD_FLAG_OVERLAPPED;
545 return flags;
548 static struct named_pipe *create_named_pipe( struct directory *root, const struct unicode_str *name,
549 unsigned int attr )
551 struct object *obj;
552 struct named_pipe *pipe = NULL;
553 struct unicode_str new_name;
555 if (!name || !name->len) return alloc_object( &named_pipe_ops );
557 if (!(obj = find_object_dir( root, name, attr, &new_name ))) return NULL;
558 if (!new_name.len)
560 if (attr & OBJ_OPENIF && obj->ops == &named_pipe_ops)
561 set_error( STATUS_OBJECT_NAME_EXISTS );
562 else
564 release_object( obj );
565 obj = NULL;
566 if (attr & OBJ_OPENIF)
567 set_error( STATUS_OBJECT_TYPE_MISMATCH );
568 else
569 set_error( STATUS_OBJECT_NAME_COLLISION );
571 return (struct named_pipe *)obj;
574 if (obj->ops != &named_pipe_device_ops)
575 set_error( STATUS_OBJECT_TYPE_MISMATCH );
576 else
578 struct named_pipe_device *dev = (struct named_pipe_device *)obj;
579 if ((pipe = create_object( dev->pipes, &named_pipe_ops, &new_name, NULL )))
580 clear_error();
583 release_object( obj );
584 return pipe;
587 static struct pipe_server *get_pipe_server_obj( struct process *process,
588 obj_handle_t handle, unsigned int access )
590 struct object *obj;
591 obj = get_handle_obj( process, handle, access, &pipe_server_ops );
592 return (struct pipe_server *) obj;
595 static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options )
597 struct pipe_server *server;
599 server = alloc_object( &pipe_server_ops );
600 if (!server)
601 return NULL;
603 server->fd = NULL;
604 server->pipe = pipe;
605 server->state = ps_idle_server;
606 server->client = NULL;
607 server->flush_poll = NULL;
608 server->options = options;
609 list_init( &server->wait_q );
611 list_add_head( &pipe->servers, &server->entry );
612 grab_object( pipe );
614 return server;
617 static struct pipe_client *create_pipe_client( struct pipe_server *server, unsigned int flags )
619 struct pipe_client *client;
621 client = alloc_object( &pipe_client_ops );
622 if (!client)
623 return NULL;
625 client->fd = NULL;
626 client->server = server;
627 client->flags = flags;
629 return client;
632 static inline struct pipe_server *find_server( struct named_pipe *pipe, enum pipe_state state )
634 struct pipe_server *server;
636 LIST_FOR_EACH_ENTRY( server, &pipe->servers, struct pipe_server, entry )
638 if (server->state == state) return (struct pipe_server *)grab_object( server );
640 return NULL;
643 static inline struct pipe_server *find_server2( struct named_pipe *pipe,
644 enum pipe_state state1, enum pipe_state state2 )
646 struct pipe_server *server;
648 LIST_FOR_EACH_ENTRY( server, &pipe->servers, struct pipe_server, entry )
650 if (server->state == state1 || server->state == state2)
651 return (struct pipe_server *)grab_object( server );
653 return NULL;
656 DECL_HANDLER(create_named_pipe)
658 struct named_pipe *pipe;
659 struct pipe_server *server;
660 struct unicode_str name;
661 struct directory *root = NULL;
663 reply->handle = 0;
664 get_req_unicode_str( &name );
665 if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
666 return;
668 pipe = create_named_pipe( root, &name, req->attributes | OBJ_OPENIF );
670 if (root) release_object( root );
671 if (!pipe) return;
673 if (get_error() != STATUS_OBJECT_NAME_EXISTS)
675 /* initialize it if it didn't already exist */
676 pipe->instances = 0;
677 list_init( &pipe->servers );
678 list_init( &pipe->waiters );
679 pipe->insize = req->insize;
680 pipe->outsize = req->outsize;
681 pipe->maxinstances = req->maxinstances;
682 pipe->timeout = req->timeout;
683 pipe->flags = req->flags;
685 else
687 if (pipe->maxinstances <= pipe->instances)
689 set_error( STATUS_INSTANCE_NOT_AVAILABLE );
690 release_object( pipe );
691 return;
693 if ((pipe->maxinstances != req->maxinstances) ||
694 (pipe->timeout != req->timeout) ||
695 (pipe->flags != req->flags))
697 set_error( STATUS_ACCESS_DENIED );
698 release_object( pipe );
699 return;
701 set_error( 0 ); /* clear the name collision */
704 server = create_pipe_server( pipe, req->options );
705 if (server)
707 reply->handle = alloc_handle( current->process, server, req->access, req->attributes );
708 server->pipe->instances++;
709 release_object( server );
712 release_object( pipe );
715 DECL_HANDLER(open_named_pipe)
717 struct pipe_server *server;
718 struct pipe_client *client;
719 struct unicode_str name;
720 struct directory *root = NULL;
721 struct named_pipe *pipe;
722 int fds[2];
724 get_req_unicode_str( &name );
725 if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
726 return;
728 pipe = open_object_dir( root, &name, req->attributes, &named_pipe_ops );
730 if (root) release_object( root );
731 if (!pipe) return;
733 server = find_server2( pipe, ps_idle_server, ps_wait_open );
734 release_object( pipe );
736 if (!server)
738 set_error( STATUS_PIPE_NOT_AVAILABLE );
739 return;
742 client = create_pipe_client( server, req->flags );
743 if (client)
745 if (!socketpair( PF_UNIX, SOCK_STREAM, 0, fds ))
747 int res = 0;
749 assert( !client->fd );
750 assert( !server->fd );
752 /* for performance reasons, only set nonblocking mode when using
753 * overlapped I/O. Otherwise, we will be doing too much busy
754 * looping */
755 if (is_overlapped( req->flags ))
756 res = fcntl( fds[1], F_SETFL, O_NONBLOCK );
757 if ((res != -1) && is_overlapped( server->options ))
758 res = fcntl( fds[0], F_SETFL, O_NONBLOCK );
760 client->fd = create_anonymous_fd( &pipe_client_fd_ops,
761 fds[1], &client->obj );
762 server->fd = create_anonymous_fd( &pipe_server_fd_ops,
763 fds[0], &server->obj );
764 if (client->fd && server->fd && res != 1)
766 if (server->state == ps_wait_open)
767 async_terminate_head( &server->wait_q, STATUS_SUCCESS );
768 assert( list_empty( &server->wait_q ) );
769 server->state = ps_connected_server;
770 server->client = client;
771 client->server = server;
772 reply->handle = alloc_handle( current->process, client, req->access, req->attributes );
775 else
776 file_set_error();
778 release_object( client );
780 release_object( server );
783 DECL_HANDLER(connect_named_pipe)
785 struct pipe_server *server;
787 server = get_pipe_server_obj(current->process, req->handle, 0);
788 if (!server)
789 return;
791 switch(server->state)
793 case ps_idle_server:
794 case ps_wait_connect:
795 assert( !server->fd );
796 server->state = ps_wait_open;
797 create_async( current, NULL, &server->wait_q,
798 req->func, req->event, NULL );
799 async_terminate_queue( &server->pipe->waiters, STATUS_SUCCESS );
800 break;
801 case ps_connected_server:
802 assert( server->fd );
803 set_error( STATUS_PIPE_CONNECTED );
804 break;
805 case ps_disconnected_server:
806 set_error( STATUS_PIPE_BUSY );
807 break;
808 case ps_wait_disconnect:
809 set_error( STATUS_NO_DATA_DETECTED );
810 break;
811 case ps_wait_open:
812 set_error( STATUS_INVALID_HANDLE );
813 break;
816 release_object(server);
819 DECL_HANDLER(wait_named_pipe)
821 struct named_pipe *pipe;
822 struct pipe_server *server;
823 struct unicode_str name;
825 get_req_unicode_str( &name );
826 pipe = (struct named_pipe *)find_object( named_pipe_device->pipes, &name, OBJ_CASE_INSENSITIVE );
827 if (!pipe)
829 set_error( STATUS_PIPE_NOT_AVAILABLE );
830 return;
832 server = find_server( pipe, ps_wait_open );
833 if (server)
835 /* there's already a server waiting for a client to connect */
836 thread_queue_apc( current, NULL, req->func, APC_ASYNC_IO,
837 1, req->overlapped, NULL, (void *)STATUS_SUCCESS );
838 release_object( server );
840 else
842 int timeout;
843 if (req->timeout == NMPWAIT_USE_DEFAULT_WAIT)
844 timeout = pipe->timeout;
845 else
846 timeout = req->timeout;
848 if (req->timeout == NMPWAIT_WAIT_FOREVER)
849 create_async( current, NULL, &pipe->waiters,
850 req->func, req->overlapped, NULL );
851 else
852 create_async( current, &timeout, &pipe->waiters,
853 req->func, req->overlapped, NULL );
856 release_object( pipe );
859 DECL_HANDLER(disconnect_named_pipe)
861 struct pipe_server *server;
863 reply->fd = -1;
864 server = get_pipe_server_obj( current->process, req->handle, 0 );
865 if (!server)
866 return;
867 switch(server->state)
869 case ps_connected_server:
870 assert( server->fd );
871 assert( server->client );
872 assert( server->client->fd );
874 notify_empty( server );
876 /* Dump the client and server fds, but keep the pointers
877 around - client loses all waiting data */
878 server->state = ps_disconnected_server;
879 do_disconnect( server );
880 reply->fd = flush_cached_fd( current->process, req->handle );
881 break;
883 case ps_wait_disconnect:
884 assert( !server->client );
885 assert( server->fd );
886 do_disconnect( server );
887 server->state = ps_wait_connect;
888 reply->fd = flush_cached_fd( current->process, req->handle );
889 break;
891 case ps_idle_server:
892 case ps_wait_open:
893 case ps_disconnected_server:
894 case ps_wait_connect:
895 set_error( STATUS_PIPE_DISCONNECTED );
896 break;
898 release_object( server );
901 DECL_HANDLER(get_named_pipe_info)
903 struct pipe_server *server;
905 server = get_pipe_server_obj( current->process, req->handle, 0 );
906 if (!server)
907 return;
909 reply->flags = server->pipe->flags;
910 reply->maxinstances = server->pipe->maxinstances;
911 reply->insize = server->pipe->insize;
912 reply->outsize = server->pipe->outsize;
914 release_object(server);