mirror of
git://source.winehq.org/git/wine.git
synced 2024-11-02 10:40:39 +00:00
Moved timeout processing to a separate function.
This commit is contained in:
parent
67c8cb28f9
commit
4949a717c4
1 changed files with 50 additions and 44 deletions
32
server/fd.c
32
server/fd.c
|
@ -288,19 +288,14 @@ static void remove_poll_user( struct fd *fd, int user )
|
|||
active_users--;
|
||||
}
|
||||
|
||||
|
||||
/* server main poll() loop */
|
||||
void main_loop(void)
|
||||
/* process pending timeouts and return the time until the next timeout, in milliseconds */
|
||||
static int get_next_timeout(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
while (active_users)
|
||||
{
|
||||
long diff = -1;
|
||||
if (!list_empty( &timeout_list ))
|
||||
{
|
||||
struct list expired_list, *ptr;
|
||||
struct timeval now;
|
||||
|
||||
gettimeofday( &now, NULL );
|
||||
|
||||
/* first remove all expired timers from the list */
|
||||
|
@ -328,21 +323,32 @@ void main_loop(void)
|
|||
free( timeout );
|
||||
}
|
||||
|
||||
if (!active_users) break; /* last user removed by a timeout */
|
||||
|
||||
if ((ptr = list_head( &timeout_list )) != NULL)
|
||||
{
|
||||
struct timeout_user *timeout = LIST_ENTRY( ptr, struct timeout_user, entry );
|
||||
diff = (timeout->when.tv_sec - now.tv_sec) * 1000
|
||||
int diff = (timeout->when.tv_sec - now.tv_sec) * 1000
|
||||
+ (timeout->when.tv_usec - now.tv_usec) / 1000;
|
||||
if (diff < 0) diff = 0;
|
||||
return diff;
|
||||
}
|
||||
}
|
||||
return -1; /* no pending timeouts */
|
||||
}
|
||||
|
||||
ret = poll( pollfd, nb_users, diff );
|
||||
/* server main poll() loop */
|
||||
void main_loop(void)
|
||||
{
|
||||
int i, ret, timeout;
|
||||
|
||||
while (active_users)
|
||||
{
|
||||
timeout = get_next_timeout();
|
||||
|
||||
if (!active_users) break; /* last user removed by a timeout */
|
||||
|
||||
ret = poll( pollfd, nb_users, timeout );
|
||||
if (ret > 0)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nb_users; i++)
|
||||
{
|
||||
if (pollfd[i].revents)
|
||||
|
|
Loading…
Reference in a new issue