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
61 ps_disconnected_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
;
77 struct list wait_q
; /* only a single one can be queued */
78 unsigned int options
; /* pipe options */
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 */
91 struct object obj
; /* object header */
93 unsigned int maxinstances
;
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 unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
);
111 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
112 unsigned int sharing
, unsigned int options
);
113 static void named_pipe_destroy( struct object
*obj
);
115 static const struct object_ops named_pipe_ops
=
117 sizeof(struct named_pipe
), /* size */
118 named_pipe_dump
, /* dump */
119 no_add_queue
, /* add_queue */
120 NULL
, /* remove_queue */
122 NULL
, /* satisfied */
123 no_signal
, /* signal */
124 no_get_fd
, /* get_fd */
125 named_pipe_map_access
, /* map_access */
126 no_lookup_name
, /* lookup_name */
127 named_pipe_open_file
, /* open_file */
128 no_close_handle
, /* close_handle */
129 named_pipe_destroy
/* destroy */
132 /* functions common to server and client */
133 static unsigned int pipe_map_access( struct object
*obj
, unsigned int access
);
135 /* server end functions */
136 static void pipe_server_dump( struct object
*obj
, int verbose
);
137 static struct fd
*pipe_server_get_fd( struct object
*obj
);
138 static void pipe_server_destroy( struct object
*obj
);
139 static int pipe_server_flush( struct fd
*fd
, struct event
**event
);
140 static enum server_fd_type
pipe_server_get_info( struct fd
*fd
, int *flags
);
142 static const struct object_ops pipe_server_ops
=
144 sizeof(struct pipe_server
), /* size */
145 pipe_server_dump
, /* dump */
146 default_fd_add_queue
, /* add_queue */
147 default_fd_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 pipe_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_info
, /* get_file_info */
165 default_fd_queue_async
, /* queue_async */
166 default_fd_cancel_async
, /* cancel_async */
169 /* client end functions */
170 static void pipe_client_dump( struct object
*obj
, int verbose
);
171 static struct fd
*pipe_client_get_fd( struct object
*obj
);
172 static void pipe_client_destroy( struct object
*obj
);
173 static int pipe_client_flush( struct fd
*fd
, struct event
**event
);
174 static enum server_fd_type
pipe_client_get_info( struct fd
*fd
, int *flags
);
176 static const struct object_ops pipe_client_ops
=
178 sizeof(struct pipe_client
), /* size */
179 pipe_client_dump
, /* dump */
180 default_fd_add_queue
, /* add_queue */
181 default_fd_remove_queue
, /* remove_queue */
182 default_fd_signaled
, /* signaled */
183 no_satisfied
, /* satisfied */
184 no_signal
, /* signal */
185 pipe_client_get_fd
, /* get_fd */
186 pipe_map_access
, /* map_access */
187 no_lookup_name
, /* lookup_name */
188 no_open_file
, /* open_file */
189 fd_close_handle
, /* close_handle */
190 pipe_client_destroy
/* destroy */
193 static const struct fd_ops pipe_client_fd_ops
=
195 default_fd_get_poll_events
, /* get_poll_events */
196 default_poll_event
, /* poll_event */
197 pipe_client_flush
, /* flush */
198 pipe_client_get_info
, /* get_file_info */
199 default_fd_queue_async
, /* queue_async */
200 default_fd_cancel_async
/* cancel_async */
203 static void named_pipe_device_dump( struct object
*obj
, int verbose
);
204 static struct fd
*named_pipe_device_get_fd( struct object
*obj
);
205 static struct object
*named_pipe_device_lookup_name( struct object
*obj
,
206 struct unicode_str
*name
, unsigned int attr
);
207 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
208 unsigned int sharing
, unsigned int options
);
209 static void named_pipe_device_destroy( struct object
*obj
);
210 static enum server_fd_type
named_pipe_device_get_file_info( struct fd
*fd
, int *flags
);
212 static const struct object_ops named_pipe_device_ops
=
214 sizeof(struct named_pipe_device
), /* size */
215 named_pipe_device_dump
, /* dump */
216 no_add_queue
, /* add_queue */
217 NULL
, /* remove_queue */
219 no_satisfied
, /* satisfied */
220 no_signal
, /* signal */
221 named_pipe_device_get_fd
, /* get_fd */
222 pipe_map_access
, /* map_access */
223 named_pipe_device_lookup_name
, /* lookup_name */
224 named_pipe_device_open_file
, /* open_file */
225 fd_close_handle
, /* close_handle */
226 named_pipe_device_destroy
/* destroy */
229 static const struct fd_ops named_pipe_device_fd_ops
=
231 default_fd_get_poll_events
, /* get_poll_events */
232 default_poll_event
, /* poll_event */
233 no_flush
, /* flush */
234 named_pipe_device_get_file_info
, /* get_file_info */
235 default_fd_queue_async
, /* queue_async */
236 default_fd_cancel_async
/* cancel_async */
239 static void named_pipe_dump( struct object
*obj
, int verbose
)
241 struct named_pipe
*pipe
= (struct named_pipe
*) obj
;
242 assert( obj
->ops
== &named_pipe_ops
);
243 fprintf( stderr
, "Named pipe " );
244 dump_object_name( &pipe
->obj
);
245 fprintf( stderr
, "\n" );
248 static unsigned int named_pipe_map_access( struct object
*obj
, unsigned int access
)
250 if (access
& GENERIC_READ
) access
|= STANDARD_RIGHTS_READ
;
251 if (access
& GENERIC_WRITE
) access
|= STANDARD_RIGHTS_WRITE
| FILE_CREATE_PIPE_INSTANCE
;
252 if (access
& GENERIC_EXECUTE
) access
|= STANDARD_RIGHTS_EXECUTE
;
253 if (access
& GENERIC_ALL
) access
|= STANDARD_RIGHTS_ALL
;
254 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
257 static void pipe_server_dump( struct object
*obj
, int verbose
)
259 struct pipe_server
*server
= (struct pipe_server
*) obj
;
260 assert( obj
->ops
== &pipe_server_ops
);
261 fprintf( stderr
, "Named pipe server pipe=%p state=%d\n", server
->pipe
, server
->state
);
264 static void pipe_client_dump( struct object
*obj
, int verbose
)
266 struct pipe_client
*client
= (struct pipe_client
*) obj
;
267 assert( obj
->ops
== &pipe_client_ops
);
268 fprintf( stderr
, "Named pipe client server=%p\n", client
->server
);
271 static void named_pipe_destroy( struct object
*obj
)
273 struct named_pipe
*pipe
= (struct named_pipe
*) obj
;
275 assert( list_empty( &pipe
->servers
) );
276 assert( !pipe
->instances
);
277 async_terminate_queue( &pipe
->waiters
, STATUS_HANDLES_CLOSED
);
280 static struct fd
*pipe_client_get_fd( struct object
*obj
)
282 struct pipe_client
*client
= (struct pipe_client
*) obj
;
284 return (struct fd
*) grab_object( client
->fd
);
285 set_error( STATUS_PIPE_DISCONNECTED
);
289 static struct fd
*pipe_server_get_fd( struct object
*obj
)
291 struct pipe_server
*server
= (struct pipe_server
*) obj
;
293 switch(server
->state
)
295 case ps_connected_server
:
296 case ps_wait_disconnect
:
297 assert( server
->fd
);
298 return (struct fd
*) grab_object( server
->fd
);
302 set_error( STATUS_PIPE_LISTENING
);
305 case ps_disconnected_server
:
306 case ps_wait_connect
:
307 set_error( STATUS_PIPE_DISCONNECTED
);
314 static void notify_empty( struct pipe_server
*server
)
316 if (!server
->flush_poll
)
318 assert( server
->state
== ps_connected_server
);
319 assert( server
->event
);
320 remove_timeout_user( server
->flush_poll
);
321 server
->flush_poll
= NULL
;
322 set_event( server
->event
);
323 release_object( server
->event
);
324 server
->event
= NULL
;
327 static void do_disconnect( struct pipe_server
*server
)
329 /* we may only have a server fd, if the client disconnected */
332 assert( server
->client
->server
== server
);
333 assert( server
->client
->fd
);
334 release_object( server
->client
->fd
);
335 server
->client
->fd
= NULL
;
337 assert( server
->fd
);
338 release_object( server
->fd
);
342 static unsigned int pipe_map_access( struct object
*obj
, unsigned int access
)
344 if (access
& GENERIC_READ
) access
|= FILE_GENERIC_READ
;
345 if (access
& GENERIC_WRITE
) access
|= FILE_GENERIC_WRITE
;
346 if (access
& GENERIC_EXECUTE
) access
|= FILE_GENERIC_EXECUTE
;
347 if (access
& GENERIC_ALL
) access
|= FILE_ALL_ACCESS
;
348 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
351 static void pipe_server_destroy( struct object
*obj
)
353 struct pipe_server
*server
= (struct pipe_server
*)obj
;
355 assert( obj
->ops
== &pipe_server_ops
);
359 notify_empty( server
);
360 do_disconnect( server
);
365 server
->client
->server
= NULL
;
366 server
->client
= NULL
;
369 async_terminate_head( &server
->wait_q
, STATUS_HANDLES_CLOSED
);
371 assert( server
->pipe
->instances
);
372 server
->pipe
->instances
--;
374 list_remove( &server
->entry
);
375 release_object( server
->pipe
);
378 static void pipe_client_destroy( struct object
*obj
)
380 struct pipe_client
*client
= (struct pipe_client
*)obj
;
381 struct pipe_server
*server
= client
->server
;
383 assert( obj
->ops
== &pipe_client_ops
);
387 notify_empty( server
);
389 switch(server
->state
)
391 case ps_connected_server
:
392 /* Don't destroy the server's fd here as we can't
393 do a successful flush without it. */
394 server
->state
= ps_wait_disconnect
;
395 release_object( client
->fd
);
398 case ps_disconnected_server
:
399 server
->state
= ps_wait_connect
;
403 case ps_wait_disconnect
:
404 case ps_wait_connect
:
407 assert( server
->client
);
408 server
->client
= NULL
;
409 client
->server
= NULL
;
411 assert( !client
->fd
);
414 static void named_pipe_device_dump( struct object
*obj
, int verbose
)
416 assert( obj
->ops
== &named_pipe_device_ops
);
417 fprintf( stderr
, "Named pipe device\n" );
420 static struct fd
*named_pipe_device_get_fd( struct object
*obj
)
422 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
423 return (struct fd
*)grab_object( device
->fd
);
426 static struct object
*named_pipe_device_lookup_name( struct object
*obj
, struct unicode_str
*name
,
429 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
430 struct object
*found
;
432 assert( obj
->ops
== &named_pipe_device_ops
);
433 assert( device
->pipes
);
435 if ((found
= find_object( device
->pipes
, name
, attr
| OBJ_CASE_INSENSITIVE
)))
441 static struct object
*named_pipe_device_open_file( struct object
*obj
, unsigned int access
,
442 unsigned int sharing
, unsigned int options
)
444 return grab_object( obj
);
447 static void named_pipe_device_destroy( struct object
*obj
)
449 struct named_pipe_device
*device
= (struct named_pipe_device
*)obj
;
450 assert( obj
->ops
== &named_pipe_device_ops
);
451 if (device
->fd
) release_object( device
->fd
);
452 free( device
->pipes
);
455 static enum server_fd_type
named_pipe_device_get_file_info( struct fd
*fd
, int *flags
)
458 return FD_TYPE_DEVICE
;
461 void create_named_pipe_device( struct directory
*root
, const struct unicode_str
*name
)
463 struct named_pipe_device
*dev
;
465 if ((dev
= create_named_object_dir( root
, name
, 0, &named_pipe_device_ops
)) &&
466 get_error() != STATUS_OBJECT_NAME_EXISTS
)
469 if (!(dev
->fd
= alloc_pseudo_fd( &named_pipe_device_fd_ops
, &dev
->obj
)) ||
470 !(dev
->pipes
= create_namespace( 7 )))
472 release_object( dev
);
476 if (dev
) make_object_static( &dev
->obj
);
479 static int pipe_data_remaining( struct pipe_server
*server
)
484 assert( server
->client
);
486 fd
= get_unix_fd( server
->client
->fd
);
493 if (0 > poll( &pfd
, 1, 0 ))
496 return pfd
.revents
&POLLIN
;
499 static void check_flushed( void *arg
)
501 struct pipe_server
*server
= (struct pipe_server
*) arg
;
503 assert( server
->event
);
504 if (pipe_data_remaining( server
))
506 struct timeval tv
= current_time
;
507 add_timeout( &tv
, 100 );
508 server
->flush_poll
= add_timeout_user( &tv
, 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 int pipe_server_flush( struct fd
*fd
, struct event
**event
)
522 struct pipe_server
*server
= get_fd_user( fd
);
527 if (server
->state
!= ps_connected_server
)
530 /* FIXME: if multiple threads flush the same pipe,
531 maybe should create a list of processes to notify */
532 if (server
->flush_poll
)
535 if (pipe_data_remaining( server
))
537 struct timeval tv
= current_time
;
539 /* this kind of sux -
540 there's no unix way to be alerted when a pipe becomes empty */
541 server
->event
= create_event( NULL
, NULL
, 0, 0, 0 );
544 add_timeout( &tv
, 100 );
545 server
->flush_poll
= add_timeout_user( &tv
, check_flushed
, server
);
546 *event
= server
->event
;
552 static int pipe_client_flush( struct fd
*fd
, struct event
**event
)
554 /* FIXME: what do we have to do for this? */
558 static inline int is_overlapped( unsigned int options
)
560 return !(options
& (FILE_SYNCHRONOUS_IO_ALERT
| FILE_SYNCHRONOUS_IO_NONALERT
));
563 static enum server_fd_type
pipe_server_get_info( struct fd
*fd
, int *flags
)
565 struct pipe_server
*server
= get_fd_user( fd
);
567 *flags
= FD_FLAG_AVAILABLE
;
568 if (is_overlapped( server
->options
)) *flags
|= FD_FLAG_OVERLAPPED
;
572 static enum server_fd_type
pipe_client_get_info( struct fd
*fd
, int *flags
)
574 struct pipe_client
*client
= get_fd_user( fd
);
576 *flags
= FD_FLAG_AVAILABLE
;
577 if (is_overlapped( client
->flags
)) *flags
|= FD_FLAG_OVERLAPPED
;
581 static struct named_pipe
*create_named_pipe( struct directory
*root
, const struct unicode_str
*name
,
585 struct named_pipe
*pipe
= NULL
;
586 struct unicode_str new_name
;
588 if (!name
|| !name
->len
) return alloc_object( &named_pipe_ops
);
590 if (!(obj
= find_object_dir( root
, name
, attr
, &new_name
)))
592 set_error( STATUS_OBJECT_NAME_INVALID
);
597 if (attr
& OBJ_OPENIF
&& obj
->ops
== &named_pipe_ops
)
598 set_error( STATUS_OBJECT_NAME_EXISTS
);
601 release_object( obj
);
603 if (attr
& OBJ_OPENIF
)
604 set_error( STATUS_OBJECT_TYPE_MISMATCH
);
606 set_error( STATUS_OBJECT_NAME_COLLISION
);
608 return (struct named_pipe
*)obj
;
611 if (obj
->ops
!= &named_pipe_device_ops
)
612 set_error( STATUS_OBJECT_NAME_INVALID
);
615 struct named_pipe_device
*dev
= (struct named_pipe_device
*)obj
;
616 if ((pipe
= create_object( dev
->pipes
, &named_pipe_ops
, &new_name
, NULL
)))
620 release_object( obj
);
624 static struct pipe_server
*get_pipe_server_obj( struct process
*process
,
625 obj_handle_t handle
, unsigned int access
)
628 obj
= get_handle_obj( process
, handle
, access
, &pipe_server_ops
);
629 return (struct pipe_server
*) obj
;
632 static struct pipe_server
*create_pipe_server( struct named_pipe
*pipe
, unsigned int options
)
634 struct pipe_server
*server
;
636 server
= alloc_object( &pipe_server_ops
);
642 server
->state
= ps_idle_server
;
643 server
->client
= NULL
;
644 server
->flush_poll
= NULL
;
645 server
->options
= options
;
646 list_init( &server
->wait_q
);
648 list_add_head( &pipe
->servers
, &server
->entry
);
654 static struct pipe_client
*create_pipe_client( unsigned int flags
)
656 struct pipe_client
*client
;
658 client
= alloc_object( &pipe_client_ops
);
663 client
->server
= NULL
;
664 client
->flags
= flags
;
669 static struct pipe_server
*find_available_server( struct named_pipe
*pipe
)
671 struct pipe_server
*server
;
673 LIST_FOR_EACH_ENTRY( server
, &pipe
->servers
, struct pipe_server
, entry
)
675 if (server
->state
== ps_idle_server
|| server
->state
== ps_wait_open
)
676 return (struct pipe_server
*)grab_object( server
);
681 static struct object
*named_pipe_open_file( struct object
*obj
, unsigned int access
,
682 unsigned int sharing
, unsigned int options
)
684 struct named_pipe
*pipe
= (struct named_pipe
*)obj
;
685 struct pipe_server
*server
;
686 struct pipe_client
*client
;
689 if (!(server
= find_available_server( pipe
)))
691 set_error( STATUS_PIPE_NOT_AVAILABLE
);
695 if ((client
= create_pipe_client( options
)))
697 if (!socketpair( PF_UNIX
, SOCK_STREAM
, 0, fds
))
701 assert( !client
->fd
);
702 assert( !server
->fd
);
704 /* for performance reasons, only set nonblocking mode when using
705 * overlapped I/O. Otherwise, we will be doing too much busy
707 if (is_overlapped( options
))
708 res
= fcntl( fds
[1], F_SETFL
, O_NONBLOCK
);
709 if ((res
!= -1) && is_overlapped( server
->options
))
710 res
= fcntl( fds
[0], F_SETFL
, O_NONBLOCK
);
714 setsockopt( fds
[0], SOL_SOCKET
, SO_RCVBUF
, &pipe
->insize
, sizeof(pipe
->insize
) );
715 setsockopt( fds
[1], SOL_SOCKET
, SO_RCVBUF
, &pipe
->insize
, sizeof(pipe
->insize
) );
719 setsockopt( fds
[0], SOL_SOCKET
, SO_SNDBUF
, &pipe
->outsize
, sizeof(pipe
->outsize
) );
720 setsockopt( fds
[1], SOL_SOCKET
, SO_SNDBUF
, &pipe
->outsize
, sizeof(pipe
->outsize
) );
723 client
->fd
= create_anonymous_fd( &pipe_client_fd_ops
,
724 fds
[1], &client
->obj
);
725 server
->fd
= create_anonymous_fd( &pipe_server_fd_ops
,
726 fds
[0], &server
->obj
);
727 if (client
->fd
&& server
->fd
&& res
!= 1)
729 if (server
->state
== ps_wait_open
)
730 async_terminate_head( &server
->wait_q
, STATUS_SUCCESS
);
731 assert( list_empty( &server
->wait_q
) );
732 server
->state
= ps_connected_server
;
733 server
->client
= client
;
734 client
->server
= server
;
740 release_object( server
);
744 DECL_HANDLER(create_named_pipe
)
746 struct named_pipe
*pipe
;
747 struct pipe_server
*server
;
748 struct unicode_str name
;
749 struct directory
*root
= NULL
;
752 get_req_unicode_str( &name
);
753 if (req
->rootdir
&& !(root
= get_directory_obj( current
->process
, req
->rootdir
, 0 )))
756 pipe
= create_named_pipe( root
, &name
, req
->attributes
| OBJ_OPENIF
);
758 if (root
) release_object( root
);
761 if (get_error() != STATUS_OBJECT_NAME_EXISTS
)
763 /* initialize it if it didn't already exist */
765 list_init( &pipe
->servers
);
766 list_init( &pipe
->waiters
);
767 pipe
->insize
= req
->insize
;
768 pipe
->outsize
= req
->outsize
;
769 pipe
->maxinstances
= req
->maxinstances
;
770 pipe
->timeout
= req
->timeout
;
771 pipe
->flags
= req
->flags
;
775 if (pipe
->maxinstances
<= pipe
->instances
)
777 set_error( STATUS_INSTANCE_NOT_AVAILABLE
);
778 release_object( pipe
);
781 if ((pipe
->maxinstances
!= req
->maxinstances
) ||
782 (pipe
->timeout
!= req
->timeout
) ||
783 (pipe
->flags
!= req
->flags
))
785 set_error( STATUS_ACCESS_DENIED
);
786 release_object( pipe
);
789 clear_error(); /* clear the name collision */
792 server
= create_pipe_server( pipe
, req
->options
);
795 reply
->handle
= alloc_handle( current
->process
, server
, req
->access
, req
->attributes
);
796 server
->pipe
->instances
++;
797 release_object( server
);
800 release_object( pipe
);
803 DECL_HANDLER(connect_named_pipe
)
805 struct pipe_server
*server
;
807 server
= get_pipe_server_obj(current
->process
, req
->handle
, 0);
811 switch(server
->state
)
814 case ps_wait_connect
:
815 assert( !server
->fd
);
816 server
->state
= ps_wait_open
;
817 create_async( current
, NULL
, &server
->wait_q
, &req
->async
);
818 async_terminate_queue( &server
->pipe
->waiters
, STATUS_SUCCESS
);
819 set_error( STATUS_PENDING
);
821 case ps_connected_server
:
822 assert( server
->fd
);
823 set_error( STATUS_PIPE_CONNECTED
);
825 case ps_disconnected_server
:
826 set_error( STATUS_PIPE_BUSY
);
828 case ps_wait_disconnect
:
829 set_error( STATUS_NO_DATA_DETECTED
);
832 set_error( STATUS_INVALID_HANDLE
);
836 release_object(server
);
839 DECL_HANDLER(wait_named_pipe
)
841 struct named_pipe_device
*device
;
842 struct named_pipe
*pipe
;
843 struct pipe_server
*server
;
844 struct unicode_str name
;
846 device
= (struct named_pipe_device
*)get_handle_obj( current
->process
, req
->handle
,
847 FILE_READ_ATTRIBUTES
, &named_pipe_device_ops
);
850 get_req_unicode_str( &name
);
851 pipe
= (struct named_pipe
*)find_object( device
->pipes
, &name
, OBJ_CASE_INSENSITIVE
);
852 release_object( device
);
855 set_error( STATUS_PIPE_NOT_AVAILABLE
);
858 server
= find_available_server( pipe
);
861 if (req
->timeout
== NMPWAIT_WAIT_FOREVER
)
863 if (create_async( current
, NULL
, &pipe
->waiters
, &req
->async
))
864 set_error( STATUS_PENDING
);
868 struct timeval when
= current_time
;
869 if (req
->timeout
== NMPWAIT_USE_DEFAULT_WAIT
) add_timeout( &when
, pipe
->timeout
);
870 else add_timeout( &when
, req
->timeout
);
871 if (create_async( current
, &when
, &pipe
->waiters
, &req
->async
))
872 set_error( STATUS_PENDING
);
875 else release_object( server
);
877 release_object( pipe
);
880 DECL_HANDLER(disconnect_named_pipe
)
882 struct pipe_server
*server
;
884 server
= get_pipe_server_obj( current
->process
, req
->handle
, 0 );
887 switch(server
->state
)
889 case ps_connected_server
:
890 assert( server
->fd
);
891 assert( server
->client
);
892 assert( server
->client
->fd
);
894 notify_empty( server
);
896 /* Dump the client and server fds, but keep the pointers
897 around - client loses all waiting data */
898 server
->state
= ps_disconnected_server
;
899 do_disconnect( server
);
902 case ps_wait_disconnect
:
903 assert( !server
->client
);
904 assert( server
->fd
);
905 do_disconnect( server
);
906 server
->state
= ps_wait_connect
;
911 case ps_disconnected_server
:
912 case ps_wait_connect
:
913 set_error( STATUS_PIPE_DISCONNECTED
);
916 release_object( server
);
919 DECL_HANDLER(get_named_pipe_info
)
921 struct pipe_server
*server
;
922 struct pipe_client
*client
= NULL
;
924 server
= get_pipe_server_obj( current
->process
, req
->handle
, FILE_READ_ATTRIBUTES
);
928 client
= (struct pipe_client
*)get_handle_obj( current
->process
, req
->handle
,
929 FILE_READ_ATTRIBUTES
, &pipe_client_ops
);
931 server
= client
->server
;
934 reply
->flags
= server
->pipe
->flags
;
935 reply
->maxinstances
= server
->pipe
->maxinstances
;
936 reply
->instances
= server
->pipe
->instances
;
937 reply
->insize
= server
->pipe
->insize
;
938 reply
->outsize
= server
->pipe
->outsize
;
941 release_object(client
);
944 reply
->flags
|= NAMED_PIPE_SERVER_END
;
945 release_object(server
);