*BSD News Article 41738


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!munnari.oz.au!news.hawaii.edu!ames!elroy.jpl.nasa.gov!lll-winken.llnl.gov!noc.near.net!shore.shore.net!rwwa.com!witr
From: witr@rwwa.com (Robert Withrow)
Newsgroups: comp.unix.bsd
Subject: Why select() returns ``exceptional'' for files?
Date: 20 Jan 1995 14:54:57 GMT
Organization: R.W. Withrow Associates
Lines: 41
Message-ID: <3fois1$5d5@shore.shore.net>
NNTP-Posting-Host: rwwa.com

The following program returns an ``exceptional'' condition
from select() for files on FreeBSD2.0 and Sunos (the two
unixoid oses I have access to...).  Why?

/* This is stest.c */

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

main()
{
  fd_set readset, exceptset;
  int fd;
  int mask;
  
  fd = open("./stest.c",O_RDONLY,0);
  if (fd >= 0) {
    int result; 
    int mask = 1 << fd;
    struct timeval timeout;
    
    FD_ZERO (&readset);
    FD_ZERO (&exceptset);
    FD_SET (fd, &readset);
    FD_SET (fd, &exceptset);
    timeout.tv_sec = timeout.tv_usec = 0;
    
    result = select (8, &readset, NULL, &exceptset, &timeout);
    printf("Poll got numfds=%d, readable=%d, exception=%d\n",
	   result,FD_ISSET(fd, &readset) != 0,FD_ISSET(fd, &exceptset) != 0);

  } else printf("Can't open file\n");
  exit(0);
}


-----------------------------------------------------------------------------
Robert Withrow, Tel: +1 617 598 4480, Fax: +1 617 598 4430 Net: witr@rwwa.COM
     R.W. Withrow Associates, 319 Lynnway Suite 201, Lynn MA 01901 USA