🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.pyramid
Article #120

Is poll() broken?

#120
From: Rick
Date: Mon, 27 Jun 1994 06:29
60 lines
2560 bytes
In the process of bringing expect up on a Pyramid (OSx256MN 5.1a-92a054
1001n MIS-12/07) it appears that poll() doesn't seem to work as
expected.  The relevant section of the manual and a test program
follow:

--------------

     If none of the defined events have occurred on any selected
     file descriptor, poll waits at least timeout msec for an
     event to occur on any of the selected file descriptors.  On
     a computer where millisecond timing accuracy is not
     available, timeout is rounded up to the nearest legal value
     available on that system.  If the value timeout is 0, poll
     returns immediately.  If the value of timeout is -1, poll
     blocks until a requested event occurs or until the call is
     interrupted.  Poll is not affected by the O_NDELAY flag.

--------------

#include <stdio.h>
#include <stropts.h>
#include <poll.h>

main()
{
	struct pollfd fds[5];
	unsigned long nfds;
	int timeout, cc;
	char	buf[80];

	fds[0].fd = 0;
	fds[0].events = POLLIN;
	nfds = 1;
	timeout = -1;
	printf("polling...\n"); fflush(stdout);
	cc = poll(fds, nfds, timeout);
	printf("poll returned %d\n", cc); fflush(stdout);
}

--------------

Compile (att universe) and run the test program.  According to the
manual page, if I type a line while the program is running, poll()
should return and the program should terminate.  No such luck.  It
appears that poll() only checks the file descriptors once, during entry
into the system call - if I do

	sleep 4 ; ./poll

and type a line before the sleep expires, then poll works as expected -
it detects the line waiting to be read, returns 1, the program exits,
and the shell reads the line I typed.  Typing a line after the poll()
call results in nada.

Any clues?  I'm currently working around it by sucking in select() from
libXll.a, but that's not the optimal solution.  Is there a fix for
this?

Thanks,
Rick.
Technical Details
Message-ID: <Cs1M0q.Cpz@qus102.qld.tne.oz.au>
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!swrinde!ihnp4.ucsd.edu!munnari.oz.au!bunyip.cc.uq.oz.au!qus102!pclink

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 102ad9,8507ff42aff9e0c1,start
X-Google-Attributes: gid102ad9,public
X-Google-Thread: 100d59,8507ff42aff9e0c1,start
X-Google-Attributes: gid100d59,public
X-Google-ArrivalTime: 1994-06-27 00:13:56 PST
Newsgroups: aus.pyramid,comp.sys.pyramid
Path: arc1-ca.pugleaf.net!bga.com!news.sprintlink.net!hookup!swrinde!ihnp4.ucsd.edu!munnari.oz.au!bunyip.cc.uq.oz.au!qus102!pclink
From: pclink@qus102.qld.tne.oz.au (Rick)
Subject: Is poll() broken?
Message-ID: <Cs1M0q.Cpz@qus102.qld.tne.oz.au>
Organization: Telecom Australia
Date: Mon, 27 Jun 1994 06:29:13 GMT
Lines: 60