All of lore.kernel.org
 help / color / mirror / Atom feed
* 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
* 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.