* O_ASYNC question
@ 2002-06-25 16:30 Amos Waterland
2002-06-26 21:11 ` William Lee Irwin III
0 siblings, 1 reply; 6+ messages in thread
From: Amos Waterland @ 2002-06-25 16:30 UTC (permalink / raw)
To: linux-kernel
The man page for fcntl() says:
If you set the O_ASYNC status flag on a file descriptor (either by
providing this flag with the open(2) call, or by using the F_SETFL
command of fcntl), a SIGIO signal is sent whenever input or output
becomes possible on that file descriptor.
On a 2.4.18 kernel, this test program waits forever in sigwaitinfo():
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
const int BYTES = 5000000;
int i, fd;
char buff[BYTES];
char name[] = "/tmp/aio8.XXXXXX";
sigset_t sigset;
siginfo_t siginfo;
if ((fd = open(name, O_CREAT|O_WRONLY|O_NONBLOCK|O_ASYNC, 0600)) < 0 ||
unlink(name)) {
perror("creating temp file"); exit(1);
}
for (i = 0; i < BYTES; i++) buff[i] = 'Z';
if (sigemptyset(&sigset) || sigaddset(&sigset, SIGIO) ||
sigprocmask(SIG_BLOCK, &sigset, NULL)) {
perror("setting up signal mask"); exit(2);
}
if (write(fd, buff, BYTES) < 0) {
perror("writing to temp file"); exit(3);
}
printf("recv sig: %i\n", sigwaitinfo(&sigset, &siginfo));
return 0;
}
Shouldn't SIGIO be raised when the write() completes? (Is O_ASYNC only
valid for sockets, maybe?) Thanks in advance.
Amos Waterland
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: O_ASYNC question
2002-06-25 16:30 O_ASYNC question Amos Waterland
@ 2002-06-26 21:11 ` William Lee Irwin III
2002-06-26 21:37 ` Amos Waterland
0 siblings, 1 reply; 6+ messages in thread
From: William Lee Irwin III @ 2002-06-26 21:11 UTC (permalink / raw)
To: Amos Waterland; +Cc: linux-kernel
On Tue, Jun 25, 2002 at 11:30:52AM -0500, Amos Waterland wrote:
> The man page for fcntl() says:
> If you set the O_ASYNC status flag on a file descriptor (either by
> providing this flag with the open(2) call, or by using the F_SETFL
> command of fcntl), a SIGIO signal is sent whenever input or output
> becomes possible on that file descriptor.
Not done for files and you need fsetown() for sockets and tty's.
Cheers,
Bill
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: O_ASYNC question
2002-06-26 21:11 ` William Lee Irwin III
@ 2002-06-26 21:37 ` Amos Waterland
2002-06-27 0:56 ` William Lee Irwin III
2002-06-27 12:15 ` Jamie Lokier
0 siblings, 2 replies; 6+ messages in thread
From: Amos Waterland @ 2002-06-26 21:37 UTC (permalink / raw)
To: William Lee Irwin III, linux-kernel; +Cc: Tom Gall
On Wed, Jun 26, 2002 at 02:11:22PM -0700, William Lee Irwin III wrote:
> On Tue, Jun 25, 2002 at 11:30:52AM -0500, Amos Waterland wrote:
> > The man page for fcntl() says:
> > If you set the O_ASYNC status flag on a file descriptor (either by
> > providing this flag with the open(2) call, or by using the F_SETFL
> > command of fcntl), a SIGIO signal is sent whenever input or output
> > becomes possible on that file descriptor.
>
> Not done for files and you need fsetown() for sockets and tty's.
Thanks for the reply.
The reason that I was interested is that this behavior, if implemented
for all fd types, would be useful for a scalable user-space
implementation of POSIX aio.
When you say that it is 'not done for files', does that mean that it is
not done by design, and no plans exist to implement it for files
(perhaps because completion notification is fundamentally different than
readiness notification?), or that the work just has yet to be done?
Thanks.
Amos W.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: O_ASYNC question
2002-06-26 21:37 ` Amos Waterland
@ 2002-06-27 0:56 ` William Lee Irwin III
2002-06-27 12:15 ` Jamie Lokier
1 sibling, 0 replies; 6+ messages in thread
From: William Lee Irwin III @ 2002-06-27 0:56 UTC (permalink / raw)
To: Amos Waterland; +Cc: linux-kernel, Tom Gall, bcrl
On Wed, Jun 26, 2002 at 04:37:55PM -0500, Amos Waterland wrote:
> The reason that I was interested is that this behavior, if implemented
> for all fd types, would be useful for a scalable user-space
> implementation of POSIX aio.
Linux implements SIGIO for tty's and sockets only.
On Wed, Jun 26, 2002 at 04:37:55PM -0500, Amos Waterland wrote:
> When you say that it is 'not done for files', does that mean that it is
> not done by design, and no plans exist to implement it for files
> (perhaps because completion notification is fundamentally different than
> readiness notification?), or that the work just has yet to be done?
> Thanks.
It is not done by design. Future plans for async I/O implementations do
not appear to involve the SIGIO mechanism.
Cheers,
Bill
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: O_ASYNC question
2002-06-26 21:37 ` Amos Waterland
2002-06-27 0:56 ` William Lee Irwin III
@ 2002-06-27 12:15 ` Jamie Lokier
1 sibling, 0 replies; 6+ messages in thread
From: Jamie Lokier @ 2002-06-27 12:15 UTC (permalink / raw)
To: Amos Waterland; +Cc: William Lee Irwin III, linux-kernel, Tom Gall
Amos Waterland wrote:
> When you say that it is 'not done for files', does that mean that it is
> not done by design, and no plans exist to implement it for files
> (perhaps because completion notification is fundamentally different than
> readiness notification?), or that the work just has yet to be done?
> Thanks.
It isn't implemented for files, per POSIX I believe - in the same way
that select() will always return readable and writable on files.
I believe (i.e. I assume in my code ;-) that you should treat a SIGIO as
something which occurs when an fd transitions from "not readable" to
"readable", or from "not writable" to "writable". This applies even to
sockets: if you read only part of the readable data from a socket, then
you won't receive a SIGIO just because there is more unread data.
If the fd is permanently "readable" and "writable", such as with a file,
then there is no transition. Following this logic, you don't actually
need a special case for different kinds of fd -- you just need to check
their status with poll(), select(), or by trying a read/write operation
and checking for EAGAIN.
Please, someone point out if this logic does not hold, thanks :-)
-- Jamie
^ permalink raw reply [flat|nested] 6+ messages in thread
* O_ASYNC question
@ 2006-11-10 22:57 Mikulas Patocka
0 siblings, 0 replies; 6+ messages in thread
From: Mikulas Patocka @ 2006-11-10 22:57 UTC (permalink / raw)
To: linux-kernel
Hi
Does anyone know what should O_ASYNC do? The manual page says that it
sends SIGIO to the process when input or output is possible, however it is
very vaguely defined.
Should the signal be level-triggered (being sent constantly while IO is
possible) or edge-triggered (being sent only when state changes)?
Should the signal be sent on read or write availability or any of them or
the one selected with O_RDONLY/O_WRONLY/O_RDRW?
I did some test and it looks almost unusable, see this program, it behaves
very strangely:
1. when you press some key and not yet ENTER, SIGIO is sent although there
are no characters to read because ENTER was not pressed.
2. there is no way to stop the flood of SIGIOs, once triggered, they are
coming over and over again. When all terminal characters are read, SIGIOs
is still signaled, even when I drop and set O_ASYNC flag sith fcntl, it
doesn't help.
On the other hand, FreeBSD and Solaris don't send any signal.
Mikulas
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
int h;
void async(int s)
{
char c;
int x = 0;
printf("signal\n"); fflush(stdout);
while (read(h, &c, 1) == 1) x++;
printf("read: %d\n", x); fflush(stdout);
if (fcntl(h, F_SETFL, O_NONBLOCK) < 0) perror("fcntl"), exit(1);
if (fcntl(h, F_SETFL, O_ASYNC | O_NONBLOCK) < 0) perror("fcntl"), exit(1);
sleep(1);
}
int main(void)
{
h = open("/dev/tty", O_RDONLY | O_NONBLOCK);
if (h < 0) perror("open"), exit(1);
signal(SIGIO, async);
if (fcntl(h, F_SETFL, O_ASYNC | O_NONBLOCK) < 0) perror("fcntl"), exit(1);
while (1) sleep(1);
}
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-11-10 22:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-25 16:30 O_ASYNC question Amos Waterland
2002-06-26 21:11 ` William Lee Irwin III
2002-06-26 21:37 ` Amos Waterland
2002-06-27 0:56 ` William Lee Irwin III
2002-06-27 12:15 ` Jamie Lokier
-- strict thread matches above, loose matches on Subject: below --
2006-11-10 22:57 Mikulas Patocka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.