delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1999/03/09/10:08:11

Date: Tue, 9 Mar 1999 16:02:34 +0100
From: Frank Heckenbach <frank AT tim DOT gerwinski DOT de>
Message-Id: <2CE741E0.19990309160234.FOO-AB9.frank@goedel.fjf.gnu.de>
X-Mailer: smtphack 0.3.3 by Jan Andres
To: eliz AT is DOT elta DOT co DOT il, djgpp-workers AT delorie DOT com, peter AT gerwinski DOT de,
frank AT tim DOT gerwinski DOT de
Subject: Re: Patch for select()
X-Counter: 889 peter AT gerwinski DOT de
Reply-To: djgpp-workers AT delorie DOT com

> > while porting some GPC code to DJGPP, I found that select() has
> > different semantics regarding end of file under DJGPP than under
> > Un*x. DJGPP's select() returns `not ready' at the end of a regular
> > file (i.e., no character device under Dos), but select() under Un*x
> > returns `ready' in this situation (verified under Linux and
> > Solaris).
> 
> Could you please elaborate under what circumstances does this make a
> difference?

Whenever a disk file is at EOF, like the test program I included.
Unpatched select() returns `not ready', but the patch makes it say
`ready', like it does under Un*x.

> > +   /* If it's a disk file, always return 1, since according to Un*x
> > +      semantics, select() returns ``ready'' at EOF (and before EOF,
> > +      anyway). */
> 
> What does this change do with stale handles (e.g., open a file on a
> floppy, then remove the disk from the drive, and *then* call select)?

Says `ready' (just like a stale NFS handle, the closest thing I
could imagine under Un*x), and a following read() returns -1 -- e.g.
in the following version of the test program when you remove the
disk after it says `foo'.

#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcntl.h>

int main ()
{
  fd_set s;
  struct timeval t = { 0, 0 };
  int x, f = open ("foobar", O_RDWR | O_CREAT | O_APPEND, 0666);
  if (f < 0) abort ();
  lseek (f, 0, SEEK_END);
  printf ("foo\n");
  sleep (5);
  printf ("bar\n");
  FD_ZERO (&s);
  FD_SET (f, &s);
  printf ("%i\n", select (f + 1, &s, NULL, NULL, &t));
  printf ("%i\n", read (f, &x, sizeof (x)));
  return 0;
}

-- 
Frank Heckenbach, frank AT fjf DOT gnu DOT de
http://fjf.gnu.de/
PGP and GPG keys: http://fjf.gnu.de/plan

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019