Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!agate!agate.berkeley.edu!chan From: chan@icsid2.icsi (Pamela Chan) Newsgroups: comp.unix.programmer Subject: Question about SIGIO Message-ID: Date: 1 Jun 91 19:34:16 GMT Article-I.D.: icsid2.CHAN.91Jun1113416 Sender: root@agate.berkeley.edu (Charlie Root) Distribution: comp Organization: /n/icsid/db/u/chan/.organization Lines: 48 Not long ago someone suggested that in order to catch the SIGIO signal when doing non-blocking IO, one has to do a F_SETOWN to specify the process group to receive the signal. So here is the code I came up with: THE RECEIVING SIDE ------------------ fcntl(sock, F_SETOWN, getpid()); fcntl(sock, F_SETFL, FASYNC|FNDELAY); for(;;){ if (ret = read(sock, buf, 64)){ // read from socket if (ret != -1){ ret = write(1, buf, ret); // output to stdout }else{ sigpause(0); // block wait for SIGIO } }else{ quit(); } } THE SENDING SIDE ---------------- fcntl(sock, F_SETOWN, new_pid); fcntl(sock, F_SETFL, FNDELAY|FASYNC); for(;;){ if (ret1 = read(fd, buf, 1024)){ // reading from datafile ret = write(sock, buf, ret1); // output to socket if (ret