summaryrefslogtreecommitdiff
path: root/WIN32-Code
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-05-27 15:35:00 +0000
committerNick Mathewson <nickm@torproject.org>2009-05-27 15:35:00 +0000
commitcdaca02c2909452de23244738630f408b8eee8e1 (patch)
tree2480a96e21339e0a491279413dbec82a447b7bcd /WIN32-Code
parent11a178f2bdd533d4f4cf7448653b0adc30c9779f (diff)
downloadlibevent-cdaca02c2909452de23244738630f408b8eee8e1.tar.gz
Activate fd events in a pseudorandom order on older backends.
New backends like poll and kqueue and so on add fds to the queue in the order that they are triggered. But the select backend currently activates low-numbered fds first, whereas the poll and win32 backends currently favor whatever fds have been on for the longest. This is no good for fairness. svn:r1318
Diffstat (limited to 'WIN32-Code')
-rw-r--r--WIN32-Code/win32.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/WIN32-Code/win32.c b/WIN32-Code/win32.c
index aa73192f..4c316c9a 100644
--- a/WIN32-Code/win32.c
+++ b/WIN32-Code/win32.c
@@ -282,8 +282,9 @@ win32_dispatch(struct event_base *base, struct timeval *tv)
{
struct win32op *win32op = base->evbase;
int res = 0;
- unsigned i;
+ unsigned j, i;
int fd_count;
+ SOCKET s;
fd_set_copy(win32op->readset_out, win32op->readset_in);
fd_set_copy(win32op->exset_out, win32op->readset_in);
@@ -314,19 +315,33 @@ win32_dispatch(struct event_base *base, struct timeval *tv)
evsig_process(base);
}
- for (i=0; i<win32op->readset_out->fd_count; ++i) {
- SOCKET s = win32op->readset_out->fd_array[i];
- evmap_io_active(base, s, EV_READ);
+ if (win32op->readset_out->fd_count) {
+ i = rand() % win32op->readset_out->fd_count;
+ for (j=0; j<win32op->readset_out->fd_count; ++j) {
+ if (++i >= win32op->readset_out->fd_count)
+ i = 0;
+ s = win32op->readset_out->fd_array[i];
+ evmap_io_active(base, s, EV_READ);
+ }
}
- for (i=0; i<win32op->exset_out->fd_count; ++i) {
- SOCKET s = win32op->exset_out->fd_array[i];
- evmap_io_active(base, s, EV_READ);
+ if (win32op->exset_out->fd_count) {
+ i = rand() % win32op->exset_out->fd_count;
+ for (j=0; j<win32op->exset_out->fd_count; ++j) {
+ if (++i >= win32op-exset_out->fd_count)
+ i = 0;
+ s = win32op->exset_out->fd_array[i];
+ evmap_io_active(base, s, EV_READ);
+ }
}
- for (i=0; i<win32op->writeset_out->fd_count; ++i) {
- SOCKET s = win32op->writeset_out->fd_array[i];
- evmap_io_active(base, s, EV_WRITE);
+ if (win32op->writeset_out->fd_count) {
+ i = rand() % win32op->writeset_out->fd_count;
+ for (j=0; j<win32op->writeset_out->fd_count; ++j) {
+ if (++i >= win32op-exset_out->fd_count)
+ i = 0;
+ SOCKET s = win32op->writeset_out->fd_array[i];
+ evmap_io_active(base, s, EV_WRITE);
+ }
}
-
return (0);
}