2 * Server-side pipe management
4 * Copyright (C) 1998 Alexandre Julliard
14 #ifdef HAVE_SYS_ERRNO_H
15 #include <sys/errno.h>
18 #include <sys/types.h>
28 enum side { READ_SIDE, WRITE_SIDE };
32 struct object obj; /* object header */
33 struct pipe *other; /* the pipe other end */
34 enum side side; /* which side of the pipe is this */
37 static void pipe_dump( struct object *obj, int verbose );
38 static int pipe_get_poll_events( struct object *obj );
39 static int pipe_get_fd( struct object *obj );
40 static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags );
41 static void pipe_destroy( struct object *obj );
43 static const struct object_ops pipe_ops =
45 sizeof(struct pipe), /* size */
47 default_poll_add_queue, /* add_queue */
48 default_poll_remove_queue, /* remove_queue */
49 default_poll_signaled, /* signaled */
50 no_satisfied, /* satisfied */
51 pipe_get_poll_events, /* get_poll_events */
52 default_poll_event, /* poll_event */
53 pipe_get_fd, /* get_fd */
55 pipe_get_info, /* get_file_info */
56 NULL, /* queue_async */
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_reply *reply, int *flags )
132 reply->type = FILE_TYPE_PIPE;
134 reply->access_time = 0;
135 reply->write_time = 0;
136 reply->size_high = 0;
139 reply->index_high = 0;
140 reply->index_low = 0;
144 return FD_TYPE_DEFAULT;
147 static void pipe_destroy( struct object *obj )
149 struct pipe *pipe = (struct pipe *)obj;
150 assert( obj->ops == &pipe_ops );
152 if (pipe->other) pipe->other->other = NULL;
155 /* create an anonymous pipe */
156 DECL_HANDLER(create_pipe)
158 struct object *obj[2];
159 handle_t hread = 0, hwrite = 0;
161 if (create_pipe( obj ))
163 hread = alloc_handle( current->process, obj[0],
164 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
168 hwrite = alloc_handle( current->process, obj[1],
169 STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
171 if (!hwrite) close_handle( current->process, hread, NULL );
173 release_object( obj[0] );
174 release_object( obj[1] );
176 reply->handle_read = hread;
177 reply->handle_write = hwrite;