[cs631apue] select(2)

Jan Schaumann jschauma at stevens.edu
Mon Oct 15 23:25:01 EDT 2012


Hello,

Here's the reason that the select(2) example didn't work as expected in
class:

The code in strchkread.c contained:

  if (select(sock + 1, &ready, 0, 0, NULL) < 0) {

This should have been:

  if (select(sock + 1, &ready, 0, 0, &to) < 0) {


That is, if no timeval is given as the last argument, select(2) will
block indefinitely until a condition occurs on the fd set.  With the
correct timeval specified, it will only block for the given amount of
time.

I've uploaded a corrected version to the course website.  Please make
sure to run it.

-Jan


More information about the cs631apue mailing list