Commit 37773dda authored by Robert Shearman's avatar Robert Shearman Committed by Alexandre Julliard

Make mailslots use as much of the default async fd implementation as

possible.
parent 9ad56286
......@@ -1409,12 +1409,12 @@ void default_poll_event( struct fd *fd, int event )
wake_up( fd->user, 0 );
}
void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count )
void fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count, int *timeout )
{
struct list *queue;
int events;
if (!(fd->fd_ops->get_file_info( fd ) & FD_FLAG_OVERLAPPED))
if (!(fd->fd_ops->get_file_info( fd ) & (FD_FLAG_OVERLAPPED|FD_FLAG_TIMEOUT)))
{
set_error( STATUS_INVALID_HANDLE );
return;
......@@ -1433,7 +1433,7 @@ void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb,
return;
}
if (!create_async( current, NULL, queue, apc, user, io_sb ))
if (!create_async( current, timeout, queue, apc, user, io_sb ))
return;
/* Check if the new pending request can be served immediately */
......@@ -1443,6 +1443,11 @@ void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb,
set_fd_events( fd, fd->fd_ops->get_poll_events( fd ) );
}
void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count )
{
fd_queue_async_timeout( fd, apc, user, io_sb, type, count, NULL );
}
void default_fd_cancel_async( struct fd *fd )
{
async_terminate_queue( &fd->read_q, STATUS_CANCELLED );
......
......@@ -65,6 +65,7 @@ extern void default_fd_remove_queue( struct object *obj, struct wait_queue_entry
extern int default_fd_signaled( struct object *obj, struct thread *thread );
extern int default_fd_get_poll_events( struct fd *fd );
extern void default_poll_event( struct fd *fd, int event );
extern void fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count, int *timeout );
extern void default_fd_queue_async( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count );
extern void default_fd_cancel_async( struct fd *fd );
extern int no_flush( struct fd *fd, struct event **event );
......
......@@ -57,7 +57,6 @@ struct mailslot
unsigned int max_msgsize;
unsigned int read_timeout;
struct list writers;
struct list read_q;
};
/* mailslot functions */
......@@ -79,20 +78,17 @@ static const struct object_ops mailslot_ops =
mailslot_destroy /* destroy */
};
static int mailslot_get_poll_events( struct fd * );
static void mailslot_poll_event( struct fd *, int );
static int mailslot_get_info( struct fd * );
static void mailslot_queue_async( struct fd *, void*, void*, void*, int, int );
static void mailslot_cancel_async( struct fd * );
static const struct fd_ops mailslot_fd_ops =
{
mailslot_get_poll_events, /* get_poll_events */
mailslot_poll_event, /* poll_event */
no_flush, /* flush */
mailslot_get_info, /* get_file_info */
mailslot_queue_async, /* queue_async */
mailslot_cancel_async /* cancel_async */
default_fd_get_poll_events, /* get_poll_events */
default_poll_event, /* poll_event */
no_flush, /* flush */
mailslot_get_info, /* get_file_info */
mailslot_queue_async, /* queue_async */
default_fd_cancel_async /* cancel_async */
};
struct mail_writer
......@@ -141,8 +137,6 @@ static void mailslot_destroy( struct object *obj)
assert( mailslot->fd );
assert( mailslot->write_fd );
async_terminate_queue( &mailslot->read_q, STATUS_CANCELLED );
release_object( mailslot->fd );
release_object( mailslot->write_fd );
}
......@@ -191,33 +185,11 @@ static struct fd *mailslot_get_fd( struct object *obj )
return (struct fd *)grab_object( mailslot->fd );
}
static int mailslot_get_poll_events( struct fd *fd )
{
struct mailslot *mailslot = get_fd_user( fd );
int events = 0;
assert( mailslot->obj.ops == &mailslot_ops );
if (!list_empty( &mailslot->read_q ))
events |= POLLIN;
return events;
}
static void mailslot_poll_event( struct fd *fd, int event )
{
struct mailslot *mailslot = get_fd_user( fd );
if (!list_empty( &mailslot->read_q ) && (POLLIN & event))
async_terminate_head( &mailslot->read_q, STATUS_ALERTED );
set_fd_events( fd, mailslot_get_poll_events(fd) );
}
static void mailslot_queue_async( struct fd *fd, void *apc, void *user,
void *iosb, int type, int count )
{
struct mailslot *mailslot = get_fd_user( fd );
int events, *ptimeout = NULL;
int *timeout = NULL;
assert(mailslot->obj.ops == &mailslot_ops);
......@@ -235,28 +207,9 @@ static void mailslot_queue_async( struct fd *fd, void *apc, void *user,
}
if (mailslot->read_timeout != MAILSLOT_WAIT_FOREVER)
ptimeout = &mailslot->read_timeout;
if (!create_async( current, ptimeout, &mailslot->read_q, apc, user, iosb ))
return;
/* Check if the new pending request can be served immediately */
events = check_fd_events( fd, mailslot_get_poll_events( fd ) );
if (events)
{
mailslot_poll_event( fd, events );
return;
}
timeout = &mailslot->read_timeout;
set_fd_events( fd, mailslot_get_poll_events( fd ));
}
static void mailslot_cancel_async( struct fd *fd )
{
struct mailslot *mailslot = get_fd_user( fd );
assert(mailslot->obj.ops == &mailslot_ops);
async_terminate_queue( &mailslot->read_q, STATUS_CANCELLED );
fd_queue_async_timeout( fd, apc, user, iosb, type, count, timeout );
}
static struct mailslot *create_mailslot( const WCHAR *name, size_t len, int max_msgsize,
......@@ -288,7 +241,6 @@ static struct mailslot *create_mailslot( const WCHAR *name, size_t len, int max_
mailslot->max_msgsize = max_msgsize;
mailslot->read_timeout = read_timeout;
list_init( &mailslot->writers );
list_init( &mailslot->read_q );
if (!socketpair( PF_UNIX, SOCK_DGRAM, 0, fds ))
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment