1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

win32: IMHO slightly better select implementation

This commit is contained in:
Witold Filipczyk 2006-05-21 12:59:00 +02:00 committed by Witold Filipczyk
parent af0997c637
commit 5558284c08
2 changed files with 12 additions and 20 deletions

View File

@ -335,10 +335,5 @@ can_read(int fd)
int int
can_write(int fd) can_write(int fd)
{ {
#ifdef CONFIG_OS_WIN32
/* temporary hack. ELinks didn't start properly under Wine */
return 1;
#else
return can_read_or_write(fd, 1); return can_read_or_write(fd, 1);
#endif
} }

View File

@ -566,7 +566,7 @@ select_one_loop(int num_fds, struct fd_set *rd, struct fd_set *wr,
} else if (fd < SOCK_SHIFT) { } else if (fd < SOCK_SHIFT) {
rc += select_read(fd, rd); rc += select_read(fd, rd);
if (FD_ISSET(fd,wr)) if (wr && FD_ISSET(fd,wr))
rc++; /* assume always writable */ rc++; /* assume always writable */
} else { } else {
@ -614,7 +614,7 @@ select_one_loop(int num_fds, struct fd_set *rd, struct fd_set *wr,
int win32_select (int num_fds, struct fd_set *rd, struct fd_set *wr, int win32_select (int num_fds, struct fd_set *rd, struct fd_set *wr,
struct fd_set *ex, struct timeval *tv) struct fd_set *ex, struct timeval *tv)
{ {
struct fd_set tmp_rd, tmp_wr, tmp_ex; struct fd_set tmp_rd, tmp_ex;
struct timeval expiry, start_time; struct timeval expiry, start_time;
int fd, rc; int fd, rc;
BOOL expired = FALSE; BOOL expired = FALSE;
@ -627,7 +627,6 @@ int win32_select (int num_fds, struct fd_set *rd, struct fd_set *wr,
select_dump(num_fds, rd, wr, ex); select_dump(num_fds, rd, wr, ex);
FD_ZERO(&tmp_rd); FD_ZERO(&tmp_rd);
FD_ZERO(&tmp_wr);
FD_ZERO(&tmp_ex); FD_ZERO(&tmp_ex);
if (tv) { if (tv) {
@ -646,7 +645,7 @@ int win32_select (int num_fds, struct fd_set *rd, struct fd_set *wr,
errno = 0; errno = 0;
for (rc = 0; !expired; ) { for (rc = 0; !expired; ) {
rc += select_one_loop (num_fds, &tmp_rd, &tmp_wr, &tmp_ex); rc += select_one_loop (num_fds, &tmp_rd, wr, &tmp_ex);
if (tv) { if (tv) {
struct timeval now; struct timeval now;
@ -661,18 +660,16 @@ int win32_select (int num_fds, struct fd_set *rd, struct fd_set *wr,
if (rc) break; if (rc) break;
} }
/* Copy fd_sets to output */ rc = 0;
if (rd) FD_ZERO(rd);
if (wr) FD_ZERO(wr);
if (ex) FD_ZERO(ex);
for (fd = 0; fd < num_fds; fd++) { for (fd = 0; fd < num_fds; fd++) {
if (rd && FD_ISSET(fd,&tmp_rd)) if (rd && FD_ISSET(fd, rd) && !FD_ISSET(fd, &tmp_rd))
FD_SET (fd, rd); FD_CLR(fd, rd);
if (wr && FD_ISSET(fd,&tmp_wr)) else rc++;
FD_SET (fd, wr); if (wr && FD_ISSET(fd, wr)) rc++;
if (ex && FD_ISSET(fd,&tmp_ex)) /* wr always set */
FD_SET (fd, ex); if (ex && FD_ISSET(fd, ex) && !FD_ISSET(fd, &tmp_ex))
FD_CLR(fd, ex);
else rc++;
} }
TRACE("-> rc %d, err %d", rc, rc < 0 ? errno : 0); TRACE("-> rc %d, err %d", rc, rc < 0 ? errno : 0);