The use of the select statement in omapi/dispatch.c

dhcp at softsysgrp.com dhcp at softsysgrp.com
Fri Aug 23 00:00:41 UTC 2002


I see the error of my ways. I did read the man page but did not (obviously)
pick up on the difference between the value being 0 and the pointer being
NULL.

In any case my use of (struct timeval *)1000 was truly wrong and so I have
fixed my code accordingly.

Thanks for the education.


-----Original Message-----
From: dhcp-hackers-bounce at isc.org [mailto:dhcp-hackers-bounce at isc.org]On
Behalf Of dhcp-lists-in at interlinx.bc.ca
Sent: Thursday, August 22, 2002 7:49 PM
To: dhcp-hackers at isc.org
Subject: Re: The use of the select statement in omapi/dispatch.c

On Thu, Aug 22, 2002 at 07:37:17PM -0400, dhcp at softsysgrp.com wrote:
>
> I agree with everything you say below, I was just questioning the
> implementation. The select call does take a timeout pointer value, and
> (struct timeval *)0 is a pointer value that points to address 0 which I
> don't think is the same as a pointer to a variable that has been set to
> zero.

No they are different and have different meanings to select.  The
manpage for select() (on Linux at least) says:

  timeout is an upper bound on the amount of time elapsed  before
  select returns. It may be zero, causing select to return
  immediately. (This is useful for polling.) If timeout is NULL (no
  timeout), select can  block indefinitely.

As you can see, there is a difference in functionality whether the
values of "timeout" is a valid structure in memory with a value of
zero in it and the NULL pointer (pointing to address 0).  They do
different things.

Now to quote Ted:
> The select system call is supposed to take a timeout pointer value of zero
> to mean no timeout, not timeout immediately.   If your operating system
> does not support this, it's not compatible.   select is a bsd thing, and
> AFAIK is not included in POSIX, so this isn't a terrible faux pas, but the
> problem is with the operating system, not the code in dispatch.c.

It is the intention of the use of select() in this case to block until
there is an I/O condition on one of the "select"ed sockets.  It is not
supposed to return immediately as it would if the timeout value were
valid and had a zero in it.

b.

--
Brian J. Murrell

-- Attached file included as plaintext by Ecartis --

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9ZXhxl3EQlGLyuXARApyRAJ4nfqJXYZUIFmJB/34Wls+dXMBnRwCggFUF
LIVSB/KOWfbd+48YopFNALQ=
=DLGU
-----END PGP SIGNATURE-----

Content-Description: Signature-Type: text/plain

--
Brian J. Murrell



More information about the dhcp-hackers mailing list