bug-wget
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-wget] need some advice for 0 timeout code


From: Giuseppe Scrivano
Subject: Re: [Bug-wget] need some advice for 0 timeout code
Date: Mon, 14 May 2012 22:34:02 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Hi Tim,

Tim Ruehsen <address@hidden> writes:

> There are three obvious ways to fix the issue once and for all:
> a)
> when given the timeout value 0, use INFINITY and special handle this value in 
> select_fd() to call select with timeout NULL.
> - INFINITY is defined in math.h which needs to be included in connect.c and 
> init.c.
> - cmd_time() maybe needs a clone to set a 0 value to INFINITY.
> - checks like if (timeout) have to be changed into if (timeout!=INFINITY).
>
> b)
> when given the timeout value 0, use a very high timeout value like 100 years 
> (maybe larger to handle future extrasolar communication ;-).
> - since the code for timeout!=0 is very well tested since it is the normal 
> case, we won't *need* any further changes.
> - we could optionally get rid of the if (timeout) ... extra code in connect.c 
> and gnutls (but get some extra calls to select()).
>
> c) just fix gnutls.c.
> - similar to a), but limited to gnutls.c and connect.c.
> - gnutls seem to need NONBLOCKING sockets, so we would call select() / 
> select_fd() anyways. Again unneccessary extra code to maintain...

I would rather explictly handle the timeout == 0 case.  It has the
advantage to "describe" what the program is doing and avoid some magic
numbers (like 100 years or 10 centuries).

I find it slightly clearer to read code like this:

  if (timeout)
    result = select (maxfd + 1, &rds, NULL, NULL, &tm);
  else /* No timeout was specified.  */
    result = select (maxfd + 1, &rds, NULL, NULL, NULL);

than:

  if (timeout)
    tm.tv_sec = 100 * 365 * 24 * 60 * 60; /* Around 100 years.  */

  result = select (maxfd + 1, &rds, NULL, NULL, &tm);


That is just my personal taste though on a particular point, please let
me know if you disagree on it.

Thanks,
Giuseppe



reply via email to

[Prev in Thread] Current Thread [Next in Thread]