server: Make the create_async function take an absolute timeout.

This commit is contained in:
Alexandre Julliard 2006-07-26 11:47:42 +02:00
parent a624977f21
commit 40723f795b
5 changed files with 28 additions and 27 deletions

View File

@ -1116,8 +1116,8 @@ static void async_callback(void *private)
}
/* create an async on a given queue of a fd */
struct async *create_async(struct thread *thread, int* timeout, struct list *queue,
void *io_apc, void *io_user, void* io_sb)
struct async *create_async( struct thread *thread, const struct timeval *timeout,
struct list *queue, void *io_apc, void *io_user, void* io_sb )
{
struct async *async = mem_alloc( sizeof(struct async) );
@ -1130,14 +1130,7 @@ struct async *create_async(struct thread *thread, int* timeout, struct list *que
list_add_tail( queue, &async->entry );
if (timeout)
{
struct timeval when;
gettimeofday( &when, NULL );
add_timeout( &when, *timeout );
async->timeout = add_timeout_user( &when, async_callback, async );
}
if (timeout) async->timeout = add_timeout_user( timeout, async_callback, async );
else async->timeout = NULL;
return async;
@ -1583,7 +1576,8 @@ void default_poll_event( struct fd *fd, int event )
wake_up( fd->user, 0 );
}
void fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count, int *timeout )
void fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type, int count,
const struct timeval *timeout )
{
struct list *queue;
int events;

View File

@ -66,7 +66,8 @@ 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 fd_queue_async_timeout( struct fd *fd, void *apc, void *user, void *io_sb, int type,
int count, const struct timeval *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 );
@ -117,7 +118,7 @@ extern int is_serial_fd( struct fd *fd );
extern struct object *create_serial( struct fd *fd, unsigned int options );
/* async I/O functions */
extern struct async *create_async( struct thread *thread, int* timeout,
extern struct async *create_async( struct thread *thread, const struct timeval *timeout,
struct list *queue, void *, void *, void *);
extern void async_terminate_head( struct list *queue, int status );

View File

@ -249,7 +249,6 @@ 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 *timeout = NULL;
assert(mailslot->obj.ops == &mailslot_ops);
@ -266,9 +265,14 @@ static void mailslot_queue_async( struct fd *fd, void *apc, void *user,
return;
}
if (mailslot->read_timeout != -1) timeout = &mailslot->read_timeout;
fd_queue_async_timeout( fd, apc, user, iosb, type, count, timeout );
if (mailslot->read_timeout != -1)
{
struct timeval when;
gettimeofday( &when, NULL );
add_timeout( &when, mailslot->read_timeout );
fd_queue_async_timeout( fd, apc, user, iosb, type, count, &when );
}
else fd_queue_async_timeout( fd, apc, user, iosb, type, count, NULL );
}
static void mailslot_device_dump( struct object *obj, int verbose )

View File

@ -868,18 +868,18 @@ DECL_HANDLER(wait_named_pipe)
}
else
{
int timeout;
if (req->timeout == NMPWAIT_USE_DEFAULT_WAIT)
timeout = pipe->timeout;
else
timeout = req->timeout;
if (req->timeout == NMPWAIT_WAIT_FOREVER)
create_async( current, NULL, &pipe->waiters,
req->func, req->event, NULL );
else
create_async( current, &timeout, &pipe->waiters,
req->func, req->event, NULL );
{
struct timeval when;
gettimeofday( &when, NULL );
if (req->timeout == NMPWAIT_USE_DEFAULT_WAIT) add_timeout( &when, pipe->timeout );
else add_timeout( &when, req->timeout );
create_async( current, &when, &pipe->waiters, req->func, req->event, NULL );
}
}
release_object( pipe );

View File

@ -246,6 +246,7 @@ static void serial_queue_async( struct fd *fd, void *apc, void *user, void *iosb
{
struct serial *serial = get_fd_user( fd );
struct list *queue;
struct timeval when;
int timeout;
int events;
@ -270,8 +271,9 @@ static void serial_queue_async( struct fd *fd, void *apc, void *user, void *iosb
return;
}
if (!create_async( current, &timeout, queue, apc, user, iosb ))
return;
gettimeofday( &when, NULL );
add_timeout( &when, timeout );
if (!create_async( current, &when, queue, apc, user, iosb )) return;
/* Check if the new pending request can be served immediately */
events = check_fd_events( fd, serial_get_poll_events( fd ) );