From: "M. Tavasti" <tawz@nic.fi>
To: root@chaos.analogic.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: Select with device and stdin not working
Date: 26 Jul 2001 15:06:24 +0300 [thread overview]
Message-ID: <m2u1zznbcv.fsf@akvavitix.vuovasti.com> (raw)
In-Reply-To: <Pine.LNX.3.95.1010725114322.520A-100000@chaos.analogic.com>
In-Reply-To: "Richard B. Johnson"'s message of "Wed, 25 Jul 2001 11:45:19 -0400 (EDT)"
"Richard B. Johnson" <root@chaos.analogic.com> writes:
> > But now there is nothing coming from device, and typing + pressing
> > enter won't make select() return like it should.
>
> It works here...........
You're testing different thing. You're not reading anything, so at
least I get endlessly 'Input is available from /dev/random', and
whenever you type something, also in terminal there's data available.
If nobody reads data from /dev/random, of course there is data
availble.
I modified your program (see end), and results: on 2.2.19 and 2.2.16
everything works ok, in 2.4.5 not, terminal input (with return)
randomly makes select return. When looking from random.c, in 2.2.19
poll_wait is called once, like this:
poll_wait(file, &random_poll_wait, wait);
And in 2.4.5:
poll_wait(file, &random_read_wait, wait);
poll_wait(file, &random_write_wait, wait);
I think I got idea how to do it right, make one wait queue for poll,
which is woken up when read OR write queue is woken up.
So, now everybody just check your driver how does it do poll.
----
Here is modified test. Try this to get real results:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <errno.h>
#include <string.h>
static const char dev[]="/dev/random";
int main(int args, char *argv[])
{
int fd, retval;
fd_set rfds;
char buff[1024];
if((fd = open(dev, O_RDONLY)) < 0)
{
fprintf(stderr, "Can't open device, %s\n", dev);
exit(EXIT_FAILURE);
}
for(;;)
{
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
FD_SET(STDIN_FILENO, &rfds);
retval = select(fd+1, &rfds, NULL, NULL, NULL);
if(retval < 0)
fprintf(stderr, "Error was %s\n", strerror(errno));
printf("Return = %d\n", retval);
if(FD_ISSET(fd, &rfds)) {
printf("Input is available from %s\n", dev);
read(fd,buff,1024);
}
if(FD_ISSET(STDIN_FILENO, &rfds)) {
printf("Input is available from %s\n", "terminal");
read(STDIN_FILENO,buff,1024);
}
}
if(close(fd) < 0)
{
fprintf(stderr, "Can't close device, %s\n", dev);
exit(EXIT_FAILURE);
}
return 0;
}
--
M. Tavasti / tavastixx@iki.fi / +358-40-5078254
Poista sähköpostiosoitteesta molemmat x-kirjaimet
Remove x-letters from my e-mail address
next prev parent reply other threads:[~2001-07-26 12:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-25 12:17 M. Tavasti
2001-07-25 13:53 ` Ketil Froyn
2001-07-25 13:35 ` M. Tavasti
2001-07-25 14:54 ` Ketil Froyn
2001-07-25 15:02 ` Ben Greear
2001-07-25 15:07 ` Richard B. Johnson
2001-07-25 15:27 ` M. Tavasti
2001-07-25 15:45 ` Richard B. Johnson
2001-07-26 12:06 ` M. Tavasti [this message]
2001-07-26 13:20 ` M. Tavasti
2001-07-25 14:14 Stephen Landamore
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2u1zznbcv.fsf@akvavitix.vuovasti.com \
--to=tawz@nic.fi \
--cc=linux-kernel@vger.kernel.org \
--cc=root@chaos.analogic.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®