2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
14 #ifdef HAVE_SYS_ERRNO_H
15 #include <sys/errno.h>
19 #include <sys/types.h>
29 enum side { READ_SIDE, WRITE_SIDE };
33 struct object obj; /* object header */
34 struct pipe *other; /* the pipe other end */
35 enum side side; /* which side of the pipe is this */
38 static void pipe_dump( struct object *obj, int verbose );
39 static int pipe_get_poll_events( struct object *obj );
40 static int pipe_get_fd( struct object *obj );
41 static int pipe_get_info( struct object *obj, struct get_file_info_request *req );
42 static void pipe_destroy( struct object *obj );
44 static const struct object_ops pipe_ops =
46 sizeof(struct pipe), /* size */
48 default_poll_add_queue, /* add_queue */
49 default_poll_remove_queue, /* remove_queue */
50 default_poll_signaled, /* signaled */
51 no_satisfied, /* satisfied */
52 pipe_get_poll_events, /* get_poll_events */
53 default_poll_event, /* poll_event */
54 pipe_get_fd, /* get_fd */
56 pipe_get_info, /* get_file_info */
57 pipe_destroy /* destroy */
61 static struct pipe *create_pipe_side( int fd, int side )
65 if ((pipe = alloc_object( &pipe_ops, fd )))
73 static int create_pipe( struct object *obj[2] )
75 struct pipe *read_pipe;
76 struct pipe *write_pipe;
84 if ((read_pipe = create_pipe_side( fd[0], READ_SIDE )))
86 if ((write_pipe = create_pipe_side( fd[1], WRITE_SIDE )))
88 write_pipe->other = read_pipe;
89 read_pipe->other = write_pipe;
90 obj[0] = &read_pipe->obj;
91 obj[1] = &write_pipe->obj;
94 release_object( read_pipe );
100 static void pipe_dump( struct object *obj, int verbose )
102 struct pipe *pipe = (struct pipe *)obj;
103 assert( obj->ops == &pipe_ops );
104 fprintf( stderr, "Pipe %s-side fd=%d\n",
105 (pipe->side == READ_SIDE) ? "read" : "write", pipe->obj.fd );
108 static int pipe_get_poll_events( struct object *obj )
110 struct pipe *pipe = (struct pipe *)obj;
111 assert( obj->ops == &pipe_ops );
112 return (pipe->side == READ_SIDE) ? POLLIN : POLLOUT;
115 static int pipe_get_fd( struct object *obj )
117 struct pipe *pipe = (struct pipe *)obj;
118 assert( obj->ops == &pipe_ops );
122 set_error( STATUS_PIPE_BROKEN );
128 static int pipe_get_info( struct object *obj, struct get_file_info_request *req )
130 req->type = FILE_TYPE_PIPE;
132 req->access_time = 0;
143 static void pipe_destroy( struct object *obj )
145 struct pipe *pipe = (struct pipe *)obj;
146 assert( obj->ops == &pipe_ops );
148 if (pipe->other) pipe->other->other = NULL;
151 /* create an anonymous pipe */
152 DECL_HANDLER(create_pipe)
154 struct object *obj[2];
155 int hread = -1, hwrite = -1;
157 if (create_pipe( obj ))
159 hread = alloc_handle( current->process, obj[0],
160 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
164 hwrite = alloc_handle( current->process, obj[1],
165 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
168 close_handle( current->process, hread, NULL );
170 release_object( obj[0] );
171 release_object( obj[1] );
173 req->handle_read = hread;
174 req->handle_write = hwrite;