1998-12-30 13:06:45 +01:00
|
|
|
/*
|
|
|
|
* Server-side pipe management
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1998-12-30 13:06:45 +01:00
|
|
|
*/
|
|
|
|
|
1999-10-25 00:13:47 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <fcntl.h>
|
1999-01-03 12:55:56 +01:00
|
|
|
#include <string.h>
|
1998-12-30 13:06:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1999-02-09 16:49:39 +01:00
|
|
|
#include "winbase.h"
|
1999-05-15 12:48:19 +02:00
|
|
|
|
2003-01-30 01:26:44 +01:00
|
|
|
#include "file.h"
|
1999-05-15 12:48:19 +02:00
|
|
|
#include "handle.h"
|
|
|
|
#include "thread.h"
|
1999-06-22 19:26:53 +02:00
|
|
|
#include "request.h"
|
1998-12-30 13:06:45 +01:00
|
|
|
|
|
|
|
enum side { READ_SIDE, WRITE_SIDE };
|
|
|
|
|
|
|
|
struct pipe
|
|
|
|
{
|
1999-05-16 18:59:38 +02:00
|
|
|
struct object obj; /* object header */
|
|
|
|
struct pipe *other; /* the pipe other end */
|
|
|
|
enum side side; /* which side of the pipe is this */
|
1998-12-30 13:06:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void pipe_dump( struct object *obj, int verbose );
|
2000-01-01 01:56:27 +01:00
|
|
|
static int pipe_get_poll_events( struct object *obj );
|
2003-01-30 01:26:44 +01:00
|
|
|
static struct fd *pipe_get_fd( struct object *obj );
|
2002-01-09 21:30:51 +01:00
|
|
|
static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags );
|
1998-12-30 13:06:45 +01:00
|
|
|
static void pipe_destroy( struct object *obj );
|
|
|
|
|
|
|
|
static const struct object_ops pipe_ops =
|
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
sizeof(struct pipe), /* size */
|
|
|
|
pipe_dump, /* dump */
|
2003-01-30 01:26:44 +01:00
|
|
|
default_fd_add_queue, /* add_queue */
|
|
|
|
default_fd_remove_queue, /* remove_queue */
|
|
|
|
default_fd_signaled, /* signaled */
|
2000-01-01 01:56:27 +01:00
|
|
|
no_satisfied, /* satisfied */
|
2003-01-30 01:26:44 +01:00
|
|
|
pipe_get_fd, /* get_fd */
|
|
|
|
pipe_get_info, /* get_file_info */
|
|
|
|
pipe_destroy /* destroy */
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct fd_ops pipe_fd_ops =
|
|
|
|
{
|
2000-01-01 01:56:27 +01:00
|
|
|
pipe_get_poll_events, /* get_poll_events */
|
|
|
|
default_poll_event, /* poll_event */
|
|
|
|
no_flush, /* flush */
|
|
|
|
pipe_get_info, /* get_file_info */
|
2003-01-30 01:26:44 +01:00
|
|
|
no_queue_async /* queue_async */
|
1998-12-30 13:06:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-06-22 19:26:53 +02:00
|
|
|
static struct pipe *create_pipe_side( int fd, int side )
|
|
|
|
{
|
|
|
|
struct pipe *pipe;
|
|
|
|
|
2003-01-30 01:26:44 +01:00
|
|
|
if ((pipe = alloc_fd_object( &pipe_ops, &pipe_fd_ops, fd )))
|
1999-06-22 19:26:53 +02:00
|
|
|
{
|
1999-12-13 01:16:44 +01:00
|
|
|
pipe->other = NULL;
|
|
|
|
pipe->side = side;
|
1999-06-22 19:26:53 +02:00
|
|
|
}
|
|
|
|
return pipe;
|
|
|
|
}
|
|
|
|
|
1999-05-15 12:48:19 +02:00
|
|
|
static int create_pipe( struct object *obj[2] )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
struct pipe *read_pipe;
|
|
|
|
struct pipe *write_pipe;
|
1998-12-30 13:06:45 +01:00
|
|
|
int fd[2];
|
|
|
|
|
|
|
|
if (pipe( fd ) == -1)
|
|
|
|
{
|
|
|
|
file_set_error();
|
|
|
|
return 0;
|
|
|
|
}
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((read_pipe = create_pipe_side( fd[0], READ_SIDE )))
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
1999-06-22 19:26:53 +02:00
|
|
|
if ((write_pipe = create_pipe_side( fd[1], WRITE_SIDE )))
|
|
|
|
{
|
|
|
|
write_pipe->other = read_pipe;
|
|
|
|
read_pipe->other = write_pipe;
|
|
|
|
obj[0] = &read_pipe->obj;
|
|
|
|
obj[1] = &write_pipe->obj;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
release_object( read_pipe );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
2000-01-01 01:56:27 +01:00
|
|
|
else close( fd[1] );
|
1999-06-22 19:26:53 +02:00
|
|
|
return 0;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pipe_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct pipe *pipe = (struct pipe *)obj;
|
|
|
|
assert( obj->ops == &pipe_ops );
|
1999-01-03 12:55:56 +01:00
|
|
|
fprintf( stderr, "Pipe %s-side fd=%d\n",
|
2000-01-01 01:56:27 +01:00
|
|
|
(pipe->side == READ_SIDE) ? "read" : "write", pipe->obj.fd );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2000-01-01 01:56:27 +01:00
|
|
|
static int pipe_get_poll_events( struct object *obj )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
|
|
|
struct pipe *pipe = (struct pipe *)obj;
|
|
|
|
assert( obj->ops == &pipe_ops );
|
2000-01-01 01:56:27 +01:00
|
|
|
return (pipe->side == READ_SIDE) ? POLLIN : POLLOUT;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2003-01-30 01:26:44 +01:00
|
|
|
static struct fd *pipe_get_fd( struct object *obj )
|
1998-12-30 13:06:45 +01:00
|
|
|
{
|
|
|
|
struct pipe *pipe = (struct pipe *)obj;
|
|
|
|
assert( obj->ops == &pipe_ops );
|
|
|
|
|
|
|
|
if (!pipe->other)
|
|
|
|
{
|
2000-01-24 22:58:06 +01:00
|
|
|
set_error( STATUS_PIPE_BROKEN );
|
2003-01-30 01:26:44 +01:00
|
|
|
return NULL;
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
2003-01-30 01:26:44 +01:00
|
|
|
return (struct fd *)grab_object( pipe->obj.fd_obj );
|
1998-12-30 13:06:45 +01:00
|
|
|
}
|
|
|
|
|
2002-01-09 21:30:51 +01:00
|
|
|
static int pipe_get_info( struct object *obj, struct get_file_info_reply *reply, int *flags )
|
1999-01-03 12:55:56 +01:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
if (reply)
|
2001-10-04 18:18:15 +02:00
|
|
|
{
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->type = FILE_TYPE_PIPE;
|
|
|
|
reply->attr = 0;
|
|
|
|
reply->access_time = 0;
|
|
|
|
reply->write_time = 0;
|
|
|
|
reply->size_high = 0;
|
|
|
|
reply->size_low = 0;
|
|
|
|
reply->links = 0;
|
|
|
|
reply->index_high = 0;
|
|
|
|
reply->index_low = 0;
|
|
|
|
reply->serial = 0;
|
2001-10-04 18:18:15 +02:00
|
|
|
}
|
2002-01-09 21:30:51 +01:00
|
|
|
*flags = 0;
|
2001-10-04 18:18:15 +02:00
|
|
|
return FD_TYPE_DEFAULT;
|
1999-01-03 12:55:56 +01:00
|
|
|
}
|
|
|
|
|
1998-12-30 13:06:45 +01:00
|
|
|
static void pipe_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct pipe *pipe = (struct pipe *)obj;
|
|
|
|
assert( obj->ops == &pipe_ops );
|
|
|
|
|
|
|
|
if (pipe->other) pipe->other->other = NULL;
|
|
|
|
}
|
1999-05-15 12:48:19 +02:00
|
|
|
|
|
|
|
/* create an anonymous pipe */
|
|
|
|
DECL_HANDLER(create_pipe)
|
|
|
|
{
|
|
|
|
struct object *obj[2];
|
2002-05-30 22:12:58 +02:00
|
|
|
obj_handle_t hread = 0, hwrite = 0;
|
1999-06-26 10:43:26 +02:00
|
|
|
|
1999-05-15 12:48:19 +02:00
|
|
|
if (create_pipe( obj ))
|
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
hread = alloc_handle( current->process, obj[0],
|
|
|
|
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_READ,
|
|
|
|
req->inherit );
|
2001-01-05 05:08:07 +01:00
|
|
|
if (hread)
|
1999-05-15 12:48:19 +02:00
|
|
|
{
|
1999-06-26 10:43:26 +02:00
|
|
|
hwrite = alloc_handle( current->process, obj[1],
|
|
|
|
STANDARD_RIGHTS_REQUIRED|SYNCHRONIZE|GENERIC_WRITE,
|
|
|
|
req->inherit );
|
2001-01-05 05:08:07 +01:00
|
|
|
if (!hwrite) close_handle( current->process, hread, NULL );
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|
|
|
|
release_object( obj[0] );
|
|
|
|
release_object( obj[1] );
|
|
|
|
}
|
2001-11-30 19:46:42 +01:00
|
|
|
reply->handle_read = hread;
|
|
|
|
reply->handle_write = hwrite;
|
1999-05-15 12:48:19 +02:00
|
|
|
}
|