1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Generalized the third argument to select_fd.

This commit is contained in:
hniksic 2003-11-02 15:17:59 -08:00
parent c12e07faa6
commit 6d3df65e88
4 changed files with 33 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2003-11-03 Hrvoje Niksic <hniksic@xemacs.org>
* connect.c (select_fd): Generalize the third argument into WAIT,
so that the caller can request waiting for both read and write.
Updated callers.
2003-11-02 Hrvoje Niksic <hniksic@xemacs.org>
* html-url.c (cleanup_html_url): Destroy the hash tables, don't

View File

@ -464,29 +464,34 @@ bindport (const ip_address *bind_address, int *port, int *local_sock)
}
#ifdef HAVE_SELECT
/* Wait for file descriptor FD to be available, timing out after
MAXTIME seconds. "Available" means readable if writep is 0,
writeable otherwise.
/* Wait for file descriptor FD to be readable or writable or both,
timing out after MAXTIME seconds. Returns 1 if FD is available, 0
for timeout and -1 for error. The argument WHAT can be a
combination of WAIT_READ and WAIT_WRITE.
Returns 1 if FD is available, 0 for timeout and -1 for error. */
This is a mere convenience wrapper around the select call, and
should be taken as such. */
int
select_fd (int fd, double maxtime, int writep)
select_fd (int fd, double maxtime, int wait)
{
fd_set fds;
fd_set *rd = NULL, *wrt = NULL;
fd_set fdset;
fd_set *rd = NULL, *wr = NULL;
struct timeval tmout;
int result;
FD_ZERO (&fds);
FD_SET (fd, &fds);
*(writep ? &wrt : &rd) = &fds;
FD_ZERO (&fdset);
FD_SET (fd, &fdset);
if (wait & WAIT_READ)
rd = &fdset;
if (wait & WAIT_WRITE)
wr = &fdset;
tmout.tv_sec = (long)maxtime;
tmout.tv_usec = 1000000L * (maxtime - (long)maxtime);
do
result = select (fd + 1, rd, wrt, NULL, &tmout);
result = select (fd + 1, rd, wr, NULL, &tmout);
while (result < 0 && errno == EINTR);
/* When we've timed out, set errno to ETIMEDOUT for the convenience
@ -512,7 +517,7 @@ acceptport (int local_sock, int *sock)
#ifdef HAVE_SELECT
if (opt.connect_timeout)
if (select_fd (local_sock, opt.connect_timeout, 0) <= 0)
if (select_fd (local_sock, opt.connect_timeout, WAIT_READ) <= 0)
return ACCEPTERR;
#endif
if ((*sock = accept (local_sock, sa, &addrlen)) < 0)
@ -576,7 +581,7 @@ iread (int fd, char *buf, int len)
#ifdef HAVE_SELECT
if (opt.read_timeout)
if (select_fd (fd, opt.read_timeout, 0) <= 0)
if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
return -1;
#endif
do
@ -604,7 +609,7 @@ iwrite (int fd, char *buf, int len)
{
#ifdef HAVE_SELECT
if (opt.read_timeout)
if (select_fd (fd, opt.read_timeout, 1) <= 0)
if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0)
return -1;
#endif
do

View File

@ -37,6 +37,12 @@ enum {
E_HOST = -100
};
/* Flags for select_fd's WAIT argument. */
enum {
WAIT_READ = 1,
WAIT_WRITE = 2
};
/* bindport flags */
#define BIND_ON_IPV4_ONLY LH_IPV4_ONLY
#define BIND_ON_IPV6_ONLY LH_IPV6_ONLY

View File

@ -318,7 +318,7 @@ ssl_iread (SSL *con, char *buf, int len)
BIO_get_fd (con->rbio, &fd);
#ifdef HAVE_SELECT
if (opt.read_timeout && !SSL_pending (con))
if (select_fd (fd, opt.read_timeout, 0) <= 0)
if (select_fd (fd, opt.read_timeout, WAIT_READ) <= 0)
return -1;
#endif
do
@ -344,7 +344,7 @@ ssl_iwrite (SSL *con, char *buf, int len)
{
#ifdef HAVE_SELECT
if (opt.read_timeout)
if (select_fd (fd, opt.read_timeout, 1) <= 0)
if (select_fd (fd, opt.read_timeout, WAIT_WRITE) <= 0)
return -1;
#endif
do