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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/port.h"
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_SOCKET_H
37 #include <sys/socket.h>
46 #define WIN32_NO_STATUS
62 ps_disconnected_server,
70 struct object obj; /* object header */
71 struct fd *fd; /* pipe file descriptor */
72 struct fd *ioctl_fd; /* file descriptor for ioctls when not connected */
73 struct list entry; /* entry in named pipe servers list */
74 enum pipe_state state; /* server state */
75 struct pipe_client *client; /* client that this server is connected to */
76 struct named_pipe *pipe;
77 struct timeout_user *flush_poll;
79 unsigned int options; /* pipe options */
84 struct object obj; /* object header */
85 struct fd *fd; /* pipe file descriptor */
86 struct pipe_server *server; /* server that this client is connected to */
87 unsigned int flags; /* file flags */
92 struct object obj; /* object header */
94 unsigned int maxinstances;
97 unsigned int instances;
99 struct list servers; /* list of servers using this pipe */
100 struct async_queue *waiters; /* list of clients waiting to connect */
103 struct named_pipe_device
105 struct object obj; /* object header */
106 struct fd *fd; /* pseudo-fd for ioctls */
107 struct namespace *pipes; /* named pipe namespace */
110 static void named_pipe_dump( struct object *obj, int verbose );
111 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access );
112 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
113 unsigned int sharing, unsigned int options );
114 static void named_pipe_destroy( struct object *obj );
116 static const struct object_ops named_pipe_ops =
118 sizeof(struct named_pipe), /* size */
119 named_pipe_dump, /* dump */
120 no_add_queue, /* add_queue */
121 NULL, /* remove_queue */
123 NULL, /* satisfied */
124 no_signal, /* signal */
125 no_get_fd, /* get_fd */
126 named_pipe_map_access, /* map_access */
127 no_lookup_name, /* lookup_name */
128 named_pipe_open_file, /* open_file */
129 no_close_handle, /* close_handle */
130 named_pipe_destroy /* destroy */
133 /* server end functions */
134 static void pipe_server_dump( struct object *obj, int verbose );
135 static struct fd *pipe_server_get_fd( struct object *obj );
136 static void pipe_server_destroy( struct object *obj);
137 static void pipe_server_flush( struct fd *fd, struct event **event );
138 static enum server_fd_type pipe_server_get_fd_type( struct fd *fd );
139 static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async,
140 const void *data, data_size_t size );
142 static const struct object_ops pipe_server_ops =
144 sizeof(struct pipe_server), /* size */
145 pipe_server_dump, /* dump */
146 add_queue, /* add_queue */
147 remove_queue, /* remove_queue */
148 default_fd_signaled, /* signaled */
149 no_satisfied, /* satisfied */
150 no_signal, /* signal */
151 pipe_server_get_fd, /* get_fd */
152 default_fd_map_access, /* map_access */
153 no_lookup_name, /* lookup_name */
154 no_open_file, /* open_file */
155 fd_close_handle, /* close_handle */
156 pipe_server_destroy /* destroy */
159 static const struct fd_ops pipe_server_fd_ops =
161 default_fd_get_poll_events, /* get_poll_events */
162 default_poll_event, /* poll_event */
163 pipe_server_flush, /* flush */
164 pipe_server_get_fd_type, /* get_fd_type */
165 pipe_server_ioctl, /* ioctl */
166 default_fd_queue_async, /* queue_async */
167 default_fd_reselect_async, /* reselect_async */
168 default_fd_cancel_async, /* cancel_async */
171 /* client end functions */
172 static void pipe_client_dump( struct object *obj, int verbose );
173 static struct fd *pipe_client_get_fd( struct object *obj );
174 static void pipe_client_destroy( struct object *obj );
175 static void pipe_client_flush( struct fd *fd, struct event **event );
176 static enum server_fd_type pipe_client_get_fd_type( struct fd *fd );
178 static const struct object_ops pipe_client_ops =
180 sizeof(struct pipe_client), /* size */
181 pipe_client_dump, /* dump */
182 add_queue, /* add_queue */
183 remove_queue, /* remove_queue */
184 default_fd_signaled, /* signaled */
185 no_satisfied, /* satisfied */
186 no_signal, /* signal */
187 pipe_client_get_fd, /* get_fd */
188 default_fd_map_access, /* map_access */
189 no_lookup_name, /* lookup_name */
190 no_open_file, /* open_file */
191 fd_close_handle, /* close_handle */
192 pipe_client_destroy /* destroy */
195 static const struct fd_ops pipe_client_fd_ops =
197 default_fd_get_poll_events, /* get_poll_events */
198 default_poll_event, /* poll_event */
199 pipe_client_flush, /* flush */
200 pipe_client_get_fd_type, /* get_fd_type */
201 default_fd_ioctl, /* ioctl */
202 default_fd_queue_async, /* queue_async */
203 default_fd_reselect_async, /* reselect_async */
204 default_fd_cancel_async /* cancel_async */
207 static void named_pipe_device_dump( struct object *obj, int verbose );
208 static struct fd *named_pipe_device_get_fd( struct object *obj );
209 static struct object *named_pipe_device_lookup_name( struct object *obj,
210 struct unicode_str *name, unsigned int attr );
211 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
212 unsigned int sharing, unsigned int options );
213 static void named_pipe_device_destroy( struct object *obj );
214 static enum server_fd_type named_pipe_device_get_fd_type( struct fd *fd );
215 static obj_handle_t named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async_data,
216 const void *data, data_size_t size );
218 static const struct object_ops named_pipe_device_ops =
220 sizeof(struct named_pipe_device), /* size */
221 named_pipe_device_dump, /* dump */
222 no_add_queue, /* add_queue */
223 NULL, /* remove_queue */
225 no_satisfied, /* satisfied */
226 no_signal, /* signal */
227 named_pipe_device_get_fd, /* get_fd */
228 no_map_access, /* map_access */
229 named_pipe_device_lookup_name, /* lookup_name */
230 named_pipe_device_open_file, /* open_file */
231 fd_close_handle, /* close_handle */
232 named_pipe_device_destroy /* destroy */
235 static const struct fd_ops named_pipe_device_fd_ops =
237 default_fd_get_poll_events, /* get_poll_events */
238 default_poll_event, /* poll_event */
239 no_flush, /* flush */
240 named_pipe_device_get_fd_type, /* get_fd_type */
241 named_pipe_device_ioctl, /* ioctl */
242 default_fd_queue_async, /* queue_async */
243 default_fd_reselect_async, /* reselect_async */
244 default_fd_cancel_async /* cancel_async */
247 static void named_pipe_dump( struct object *obj, int verbose )
249 struct named_pipe *pipe = (struct named_pipe *) obj;
250 assert( obj->ops == &named_pipe_ops );
251 fprintf( stderr, "Named pipe " );
252 dump_object_name( &pipe->obj );
253 fprintf( stderr, "\n" );
256 static unsigned int named_pipe_map_access( struct object *obj, unsigned int access )
258 if (access & GENERIC_READ) access |= STANDARD_RIGHTS_READ;
259 if (access & GENERIC_WRITE) access |= STANDARD_RIGHTS_WRITE | FILE_CREATE_PIPE_INSTANCE;
260 if (access & GENERIC_EXECUTE) access |= STANDARD_RIGHTS_EXECUTE;
261 if (access & GENERIC_ALL) access |= STANDARD_RIGHTS_ALL;
262 return access & ~(GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | GENERIC_ALL);
265 static void pipe_server_dump( struct object *obj, int verbose )
267 struct pipe_server *server = (struct pipe_server *) obj;
268 assert( obj->ops == &pipe_server_ops );
269 fprintf( stderr, "Named pipe server pipe=%p state=%d\n", server->pipe, server->state );
272 static void pipe_client_dump( struct object *obj, int verbose )
274 struct pipe_client *client = (struct pipe_client *) obj;
275 assert( obj->ops == &pipe_client_ops );
276 fprintf( stderr, "Named pipe client server=%p\n", client->server );
279 static void named_pipe_destroy( struct object *obj)
281 struct named_pipe *pipe = (struct named_pipe *) obj;
283 assert( list_empty( &pipe->servers ) );
284 assert( !pipe->instances );
285 free_async_queue( pipe->waiters );
288 static struct fd *pipe_client_get_fd( struct object *obj )
290 struct pipe_client *client = (struct pipe_client *) obj;
292 return (struct fd *) grab_object( client->fd );
293 set_error( STATUS_PIPE_DISCONNECTED );
297 static void set_server_state( struct pipe_server *server, enum pipe_state state )
299 server->state = state;
303 case ps_connected_server:
304 case ps_wait_disconnect:
305 assert( server->fd );
309 assert( !server->fd );
310 set_no_fd_status( server->ioctl_fd, STATUS_PIPE_LISTENING );
312 case ps_disconnected_server:
313 case ps_wait_connect:
314 assert( !server->fd );
315 set_no_fd_status( server->ioctl_fd, STATUS_PIPE_DISCONNECTED );
320 static struct fd *pipe_server_get_fd( struct object *obj )
322 struct pipe_server *server = (struct pipe_server *) obj;
324 return (struct fd *)grab_object( server->fd ? server->fd : server->ioctl_fd );
328 static void notify_empty( struct pipe_server *server )
330 if (!server->flush_poll)
332 assert( server->state == ps_connected_server );
333 assert( server->event );
334 remove_timeout_user( server->flush_poll );
335 server->flush_poll = NULL;
336 set_event( server->event );
337 release_object( server->event );
338 server->event = NULL;
341 static void do_disconnect( struct pipe_server *server )
343 /* we may only have a server fd, if the client disconnected */
346 assert( server->client->server == server );
347 assert( server->client->fd );
348 release_object( server->client->fd );
349 server->client->fd = NULL;
351 assert( server->fd );
352 shutdown( get_unix_fd( server->fd ), SHUT_RDWR );
353 release_object( server->fd );
357 static void pipe_server_destroy( struct object *obj)
359 struct pipe_server *server = (struct pipe_server *)obj;
361 assert( obj->ops == &pipe_server_ops );
365 notify_empty( server );
366 do_disconnect( server );
371 server->client->server = NULL;
372 server->client = NULL;
375 assert( server->pipe->instances );
376 server->pipe->instances--;
378 if (server->ioctl_fd) release_object( server->ioctl_fd );
379 list_remove( &server->entry );
380 release_object( server->pipe );
383 static void pipe_client_destroy( struct object *obj)
385 struct pipe_client *client = (struct pipe_client *)obj;
386 struct pipe_server *server = client->server;
388 assert( obj->ops == &pipe_client_ops );
392 notify_empty( server );
394 switch(server->state)
396 case ps_connected_server:
397 /* Don't destroy the server's fd here as we can't
398 do a successful flush without it. */
399 set_server_state( server, ps_wait_disconnect );
401 case ps_disconnected_server:
402 set_server_state( server, ps_wait_connect );
406 case ps_wait_disconnect:
407 case ps_wait_connect:
410 assert( server->client );
411 server->client = NULL;
412 client->server = NULL;
414 if (client->fd) release_object( client->fd );
417 static void named_pipe_device_dump( struct object *obj, int verbose )
419 assert( obj->ops == &named_pipe_device_ops );
420 fprintf( stderr, "Named pipe device\n" );
423 static struct fd *named_pipe_device_get_fd( struct object *obj )
425 struct named_pipe_device *device = (struct named_pipe_device *)obj;
426 return (struct fd *)grab_object( device->fd );
429 static struct object *named_pipe_device_lookup_name( struct object *obj, struct unicode_str *name,
432 struct named_pipe_device *device = (struct named_pipe_device*)obj;
433 struct object *found;
435 assert( obj->ops == &named_pipe_device_ops );
436 assert( device->pipes );
438 if ((found = find_object( device->pipes, name, attr | OBJ_CASE_INSENSITIVE )))
444 static struct object *named_pipe_device_open_file( struct object *obj, unsigned int access,
445 unsigned int sharing, unsigned int options )
447 return grab_object( obj );
450 static void named_pipe_device_destroy( struct object *obj )
452 struct named_pipe_device *device = (struct named_pipe_device*)obj;
453 assert( obj->ops == &named_pipe_device_ops );
454 if (device->fd) release_object( device->fd );
455 free( device->pipes );
458 static enum server_fd_type named_pipe_device_get_fd_type( struct fd *fd )
460 return FD_TYPE_DEVICE;
463 void create_named_pipe_device( struct directory *root, const struct unicode_str *name )
465 struct named_pipe_device *dev;
467 if ((dev = create_named_object_dir( root, name, 0, &named_pipe_device_ops )) &&
468 get_error() != STATUS_OBJECT_NAME_EXISTS)
471 if (!(dev->fd = alloc_pseudo_fd( &named_pipe_device_fd_ops, &dev->obj, 0 )) ||
472 !(dev->pipes = create_namespace( 7 )))
474 release_object( dev );
478 if (dev) make_object_static( &dev->obj );
481 static int pipe_data_remaining( struct pipe_server *server )
486 assert( server->client );
488 fd = get_unix_fd( server->client->fd );
495 if (0 > poll( &pfd, 1, 0 ))
498 return pfd.revents&POLLIN;
501 static void check_flushed( void *arg )
503 struct pipe_server *server = (struct pipe_server*) arg;
505 assert( server->event );
506 if (pipe_data_remaining( server ))
508 server->flush_poll = add_timeout_user( -TICKS_PER_SEC / 10, check_flushed, server );
512 /* notify_empty( server ); */
513 server->flush_poll = NULL;
514 set_event( server->event );
515 release_object( server->event );
516 server->event = NULL;
520 static void pipe_server_flush( struct fd *fd, struct event **event )
522 struct pipe_server *server = get_fd_user( fd );
524 if (!server || server->state != ps_connected_server) return;
526 /* FIXME: if multiple threads flush the same pipe,
527 maybe should create a list of processes to notify */
528 if (server->flush_poll) return;
530 if (pipe_data_remaining( server ))
532 /* this kind of sux -
533 there's no unix way to be alerted when a pipe becomes empty */
534 server->event = create_event( NULL, NULL, 0, 0, 0 );
535 if (!server->event) return;
536 server->flush_poll = add_timeout_user( -TICKS_PER_SEC / 10, check_flushed, server );
537 *event = server->event;
541 static void pipe_client_flush( struct fd *fd, struct event **event )
543 /* FIXME: what do we have to do for this? */
546 static inline int is_overlapped( unsigned int options )
548 return !(options & (FILE_SYNCHRONOUS_IO_ALERT | FILE_SYNCHRONOUS_IO_NONALERT));
551 static enum server_fd_type pipe_server_get_fd_type( struct fd *fd )
556 static enum server_fd_type pipe_client_get_fd_type( struct fd *fd )
561 static obj_handle_t alloc_wait_event( struct process *process )
563 obj_handle_t handle = 0;
564 struct event *event = create_event( NULL, NULL, 0, 1, 0 );
568 handle = alloc_handle( process, event, EVENT_ALL_ACCESS, 0 );
569 release_object( event );
574 static obj_handle_t pipe_server_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async_data,
575 const void *data, data_size_t size )
577 struct pipe_server *server = get_fd_user( fd );
579 obj_handle_t wait_handle = 0;
583 case FSCTL_PIPE_LISTEN:
584 switch(server->state)
587 case ps_wait_connect:
588 if (!async_data->event && !async_data->apc)
590 async_data_t new_data = *async_data;
591 if (!(wait_handle = alloc_wait_event( current->process ))) break;
592 new_data.event = wait_handle;
593 if (!(async = fd_queue_async( server->ioctl_fd, &new_data, ASYNC_TYPE_WAIT, 0 )))
595 close_handle( current->process, wait_handle );
599 else async = fd_queue_async( server->ioctl_fd, async_data, ASYNC_TYPE_WAIT, 0 );
603 set_server_state( server, ps_wait_open );
604 if (server->pipe->waiters) async_wake_up( server->pipe->waiters, STATUS_SUCCESS );
605 release_object( async );
606 set_error( STATUS_PENDING );
610 case ps_connected_server:
611 set_error( STATUS_PIPE_CONNECTED );
613 case ps_disconnected_server:
614 set_error( STATUS_PIPE_BUSY );
616 case ps_wait_disconnect:
617 set_error( STATUS_NO_DATA_DETECTED );
620 set_error( STATUS_INVALID_HANDLE );
625 case FSCTL_PIPE_DISCONNECT:
626 switch(server->state)
628 case ps_connected_server:
629 assert( server->client );
630 assert( server->client->fd );
632 notify_empty( server );
634 /* dump the client and server fds, but keep the pointers
635 around - client loses all waiting data */
636 do_disconnect( server );
637 set_server_state( server, ps_disconnected_server );
639 case ps_wait_disconnect:
640 assert( !server->client );
641 do_disconnect( server );
642 set_server_state( server, ps_wait_connect );
646 set_error( STATUS_PIPE_LISTENING );
648 case ps_disconnected_server:
649 case ps_wait_connect:
650 set_error( STATUS_PIPE_DISCONNECTED );
656 return default_fd_ioctl( fd, code, async_data, data, size );
660 static struct named_pipe *create_named_pipe( struct directory *root, const struct unicode_str *name,
664 struct named_pipe *pipe = NULL;
665 struct unicode_str new_name;
667 if (!name || !name->len) return alloc_object( &named_pipe_ops );
669 if (!(obj = find_object_dir( root, name, attr, &new_name )))
671 set_error( STATUS_OBJECT_NAME_INVALID );
676 if (attr & OBJ_OPENIF && obj->ops == &named_pipe_ops)
677 set_error( STATUS_OBJECT_NAME_EXISTS );
680 release_object( obj );
682 if (attr & OBJ_OPENIF)
683 set_error( STATUS_OBJECT_TYPE_MISMATCH );
685 set_error( STATUS_OBJECT_NAME_COLLISION );
687 return (struct named_pipe *)obj;
690 if (obj->ops != &named_pipe_device_ops)
691 set_error( STATUS_OBJECT_NAME_INVALID );
694 struct named_pipe_device *dev = (struct named_pipe_device *)obj;
695 if ((pipe = create_object( dev->pipes, &named_pipe_ops, &new_name, NULL )))
699 release_object( obj );
703 static struct pipe_server *get_pipe_server_obj( struct process *process,
704 obj_handle_t handle, unsigned int access )
707 obj = get_handle_obj( process, handle, access, &pipe_server_ops );
708 return (struct pipe_server *) obj;
711 static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned int options )
713 struct pipe_server *server;
715 server = alloc_object( &pipe_server_ops );
721 server->client = NULL;
722 server->flush_poll = NULL;
723 server->options = options;
725 list_add_head( &pipe->servers, &server->entry );
727 if (!(server->ioctl_fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->obj, options )))
729 release_object( server );
732 set_server_state( server, ps_idle_server );
736 static struct pipe_client *create_pipe_client( unsigned int flags )
738 struct pipe_client *client;
740 client = alloc_object( &pipe_client_ops );
745 client->server = NULL;
746 client->flags = flags;
751 static struct pipe_server *find_available_server( struct named_pipe *pipe )
753 struct pipe_server *server;
755 LIST_FOR_EACH_ENTRY( server, &pipe->servers, struct pipe_server, entry )
757 if (server->state == ps_idle_server || server->state == ps_wait_open)
758 return (struct pipe_server *)grab_object( server );
763 static struct object *named_pipe_open_file( struct object *obj, unsigned int access,
764 unsigned int sharing, unsigned int options )
766 struct named_pipe *pipe = (struct named_pipe *)obj;
767 struct pipe_server *server;
768 struct pipe_client *client;
771 if (!(server = find_available_server( pipe )))
773 set_error( STATUS_PIPE_NOT_AVAILABLE );
777 if ((client = create_pipe_client( options )))
779 if (!socketpair( PF_UNIX, SOCK_STREAM, 0, fds ))
781 assert( !server->fd );
783 /* for performance reasons, only set nonblocking mode when using
784 * overlapped I/O. Otherwise, we will be doing too much busy
786 if (is_overlapped( options )) fcntl( fds[1], F_SETFL, O_NONBLOCK );
787 if (is_overlapped( server->options )) fcntl( fds[0], F_SETFL, O_NONBLOCK );
791 setsockopt( fds[0], SOL_SOCKET, SO_RCVBUF, &pipe->insize, sizeof(pipe->insize) );
792 setsockopt( fds[1], SOL_SOCKET, SO_RCVBUF, &pipe->insize, sizeof(pipe->insize) );
796 setsockopt( fds[0], SOL_SOCKET, SO_SNDBUF, &pipe->outsize, sizeof(pipe->outsize) );
797 setsockopt( fds[1], SOL_SOCKET, SO_SNDBUF, &pipe->outsize, sizeof(pipe->outsize) );
800 client->fd = create_anonymous_fd( &pipe_client_fd_ops, fds[1], &client->obj, options );
801 server->fd = create_anonymous_fd( &pipe_server_fd_ops, fds[0], &server->obj, server->options );
802 if (client->fd && server->fd)
804 if (server->state == ps_wait_open)
805 fd_async_wake_up( server->ioctl_fd, ASYNC_TYPE_WAIT, STATUS_SUCCESS );
806 set_server_state( server, ps_connected_server );
807 server->client = client;
808 client->server = server;
812 release_object( client );
819 release_object( client );
823 release_object( server );
827 static obj_handle_t named_pipe_device_ioctl( struct fd *fd, ioctl_code_t code, const async_data_t *async_data,
828 const void *data, data_size_t size )
830 struct named_pipe_device *device = get_fd_user( fd );
834 case FSCTL_PIPE_WAIT:
836 const FILE_PIPE_WAIT_FOR_BUFFER *buffer = data;
837 obj_handle_t wait_handle = 0;
838 struct named_pipe *pipe;
839 struct pipe_server *server;
840 struct unicode_str name;
842 if (size < sizeof(*buffer) ||
843 size < FIELD_OFFSET(FILE_PIPE_WAIT_FOR_BUFFER, Name[buffer->NameLength/sizeof(WCHAR)]))
845 set_error( STATUS_INVALID_PARAMETER );
848 name.str = buffer->Name;
849 name.len = (buffer->NameLength / sizeof(WCHAR)) * sizeof(WCHAR);
850 if (!(pipe = (struct named_pipe *)find_object( device->pipes, &name, OBJ_CASE_INSENSITIVE )))
852 set_error( STATUS_PIPE_NOT_AVAILABLE );
855 if (!(server = find_available_server( pipe )))
859 if (!pipe->waiters && !(pipe->waiters = create_async_queue( NULL ))) goto done;
861 if (!async_data->event && !async_data->apc)
863 async_data_t new_data = *async_data;
864 if (!(wait_handle = alloc_wait_event( current->process ))) goto done;
865 new_data.event = wait_handle;
866 if (!(async = create_async( current, pipe->waiters, &new_data )))
868 close_handle( current->process, wait_handle );
872 else async = create_async( current, pipe->waiters, async_data );
876 timeout_t when = buffer->TimeoutSpecified ? buffer->Timeout.QuadPart : pipe->timeout;
877 async_set_timeout( async, when, STATUS_IO_TIMEOUT );
878 release_object( async );
879 set_error( STATUS_PENDING );
882 else release_object( server );
885 release_object( pipe );
890 return default_fd_ioctl( fd, code, async_data, data, size );
895 DECL_HANDLER(create_named_pipe)
897 struct named_pipe *pipe;
898 struct pipe_server *server;
899 struct unicode_str name;
900 struct directory *root = NULL;
903 get_req_unicode_str( &name );
904 if (req->rootdir && !(root = get_directory_obj( current->process, req->rootdir, 0 )))
907 pipe = create_named_pipe( root, &name, req->attributes | OBJ_OPENIF );
909 if (root) release_object( root );
912 if (get_error() != STATUS_OBJECT_NAME_EXISTS)
914 /* initialize it if it didn't already exist */
916 pipe->waiters = NULL;
917 list_init( &pipe->servers );
918 pipe->insize = req->insize;
919 pipe->outsize = req->outsize;
920 pipe->maxinstances = req->maxinstances;
921 pipe->timeout = req->timeout;
922 pipe->flags = req->flags;
926 if (pipe->maxinstances <= pipe->instances)
928 set_error( STATUS_INSTANCE_NOT_AVAILABLE );
929 release_object( pipe );
932 if ((pipe->maxinstances != req->maxinstances) ||
933 (pipe->timeout != req->timeout) ||
934 (pipe->flags != req->flags))
936 set_error( STATUS_ACCESS_DENIED );
937 release_object( pipe );
940 clear_error(); /* clear the name collision */
943 server = create_pipe_server( pipe, req->options );
946 reply->handle = alloc_handle( current->process, server, req->access, req->attributes );
947 server->pipe->instances++;
948 release_object( server );
951 release_object( pipe );
954 DECL_HANDLER(get_named_pipe_info)
956 struct pipe_server *server;
957 struct pipe_client *client = NULL;
959 server = get_pipe_server_obj( current->process, req->handle, FILE_READ_ATTRIBUTES );
963 client = (struct pipe_client *)get_handle_obj( current->process, req->handle,
964 FILE_READ_ATTRIBUTES, &pipe_client_ops );
966 server = client->server;
969 reply->flags = server->pipe->flags;
970 reply->maxinstances = server->pipe->maxinstances;
971 reply->instances = server->pipe->instances;
972 reply->insize = server->pipe->insize;
973 reply->outsize = server->pipe->outsize;
976 release_object(client);
979 reply->flags |= NAMED_PIPE_SERVER_END;
980 release_object(server);