server: Move socket async activation to sock_poll_event.

This commit is contained in:
Mike Kaplinskiy 2010-05-15 01:18:20 -04:00 committed by Alexandre Julliard
parent 4aee4c7d1c
commit 42debac149
4 changed files with 29 additions and 22 deletions

View File

@ -3133,10 +3133,10 @@ static void test_events(int useMessages)
ok(ret == 2, "Failed to send buffer %d err %d\n", ret, GetLastError()); ok(ret == 2, "Failed to send buffer %d err %d\n", ret, GetLastError());
broken_seq[0] = read_read_seq; /* win9x */ broken_seq[0] = read_read_seq; /* win9x */
broken_seq[1] = NULL; broken_seq[1] = NULL;
if (useMessages) /* we like to erase pmask in server, so we have varying behavior here */ /* we like to erase pmask in server, so we have varying behavior here *
todo_wine ok_event_seq(src, hEvent, empty_seq, broken_seq, 0); * it is only fixed for now because we refuse to send notifications with
else * any kind of asyncs requests running */
ok_event_seq(src, hEvent, empty_seq, broken_seq, 0); ok_event_seq(src, hEvent, empty_seq, broken_seq, 0);
dwRet = WaitForSingleObject(ov.hEvent, 100); dwRet = WaitForSingleObject(ov.hEvent, 100);
ok(dwRet == WAIT_OBJECT_0, "Failed to wait for recv message: %d - %d\n", dwRet, GetLastError()); ok(dwRet == WAIT_OBJECT_0, "Failed to wait for recv message: %d - %d\n", dwRet, GetLastError());

View File

@ -276,6 +276,12 @@ void async_set_result( struct object *obj, unsigned int status, unsigned int tot
} }
} }
/* check if there are any queued async operations */
int async_queued( struct async_queue *queue )
{
return queue && list_head( &queue->queue );
}
/* check if an async operation is waiting to be alerted */ /* check if an async operation is waiting to be alerted */
int async_waiting( struct async_queue *queue ) int async_waiting( struct async_queue *queue )
{ {

View File

@ -146,6 +146,7 @@ extern struct async *create_async( struct thread *thread, struct async_queue *qu
extern void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status ); extern void async_set_timeout( struct async *async, timeout_t timeout, unsigned int status );
extern void async_set_result( struct object *obj, unsigned int status, extern void async_set_result( struct object *obj, unsigned int status,
unsigned int total, client_ptr_t apc ); unsigned int total, client_ptr_t apc );
extern int async_queued( struct async_queue *queue );
extern int async_waiting( struct async_queue *queue ); extern int async_waiting( struct async_queue *queue );
extern void async_terminate( struct async *async, unsigned int status ); extern void async_terminate( struct async *async, unsigned int status );
extern int async_wake_up_by( struct async_queue *queue, struct process *process, extern int async_wake_up_by( struct async_queue *queue, struct process *process,

View File

@ -255,28 +255,14 @@ static int sock_reselect( struct sock *sock )
} }
/* wake anybody waiting on the socket event or send the associated message */ /* wake anybody waiting on the socket event or send the associated message */
static void sock_wake_up( struct sock *sock, int pollev ) static void sock_wake_up( struct sock *sock )
{ {
unsigned int events = sock->pmask & sock->mask; unsigned int events = sock->pmask & sock->mask;
int i; int i;
int async_active = 0;
if ( pollev & (POLLIN|POLLPRI|POLLERR|POLLHUP) && async_waiting( sock->read_q ))
{
if (debug_level) fprintf( stderr, "activating read queue for socket %p\n", sock );
async_wake_up( sock->read_q, STATUS_ALERTED );
async_active = 1;
}
if ( pollev & (POLLOUT|POLLERR|POLLHUP) && async_waiting( sock->write_q ))
{
if (debug_level) fprintf( stderr, "activating write queue for socket %p\n", sock );
async_wake_up( sock->write_q, STATUS_ALERTED );
async_active = 1;
}
/* Do not signal events if there are still pending asynchronous IO requests */ /* Do not signal events if there are still pending asynchronous IO requests */
/* We need this to delay FD_CLOSE events until all pending overlapped requests are processed */ /* We need this to delay FD_CLOSE events until all pending overlapped requests are processed */
if ( !events || async_active ) return; if ( !events || async_queued( sock->read_q ) || async_queued( sock->write_q ) ) return;
if (sock->event) if (sock->event)
{ {
@ -437,7 +423,21 @@ static void sock_poll_event( struct fd *fd, int event )
} }
/* wake up anyone waiting for whatever just happened */ /* wake up anyone waiting for whatever just happened */
if ( sock->pmask & sock->mask || sock->flags & WSA_FLAG_OVERLAPPED ) sock_wake_up( sock, event ); sock_wake_up( sock );
if ( sock->flags & WSA_FLAG_OVERLAPPED )
{
if ( event & (POLLIN|POLLPRI|POLLERR|POLLHUP) && async_waiting( sock->read_q ))
{
if (debug_level) fprintf( stderr, "activating read queue for socket %p\n", sock );
async_wake_up( sock->read_q, STATUS_ALERTED );
}
if ( event & (POLLOUT|POLLERR|POLLHUP) && async_waiting( sock->write_q ))
{
if (debug_level) fprintf( stderr, "activating write queue for socket %p\n", sock );
async_wake_up( sock->write_q, STATUS_ALERTED );
}
}
/* if anyone is stupid enough to wait on the socket object itself, /* if anyone is stupid enough to wait on the socket object itself,
* maybe we should wake them up too, just in case? */ * maybe we should wake them up too, just in case? */
@ -876,7 +876,7 @@ DECL_HANDLER(set_socket_event)
it is possible that FD_CONNECT or FD_ACCEPT network events has happened it is possible that FD_CONNECT or FD_ACCEPT network events has happened
before a WSAEventSelect() was done on it. before a WSAEventSelect() was done on it.
(when dealing with Asynchronous socket) */ (when dealing with Asynchronous socket) */
if (sock->pmask & sock->mask) sock_wake_up( sock, pollev ); sock_wake_up( sock );
if (old_event) release_object( old_event ); /* we're through with it */ if (old_event) release_object( old_event ); /* we're through with it */
release_object( &sock->obj ); release_object( &sock->obj );