Mail Archives: djgpp-workers/1999/03/09/10:08:11
> > 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 -