problems with async. I/O on streams
Arman Bostani
arman at oahu.cs.ucla.edu
Mon Sep 18 16:25:13 AEST 1989
Pardon me if this question has been asked already ...
I have been trying to get asynchronous I/O with streams working on
sys-V to no avail. I have written a small program doing async. I/O
with streams that works perfectly fine on a Sun-3 running 4.0.3. The
program works by performing an I_SETSIG ioctl operation on stdin.
When I have tried it on a couple of boxes running sys-V rel. 3.2,
however, the ioctl returns an EINVAL (invalid argument) error.
The streamio(7) manual has a little blurb about the fact that one will
recieve an EINVAL if the file descriptor "is linked below a multiplexer".
Has anyone seen this problem before?
Is it possible at all to do async. I/O on ttys?
If so, how does one go about it?
I have included the text of a small program which runs into the
problem mentioned above.
Thanx for the help,
arman.
---------------------------------
#include <fcntl.h>
#include <signal.h>
#include <stropts.h>
#include <stdio.h>
#if defined(FNDELAY)
# define NODELAY FNDELAY
#elif defined(O_NDELAY)
# define NODELAY O_NDELAY
#else
CROAK
#endif
#ifndef SIGPOLL
# define SIGPOLL SIGIO
#endif
static int flags;
/*
* Called when we get a SIGPOLL. We read available input and spit it
* out in hex.
*/
handler()
{
int c;
fprintf(stderr, "got signal ...\n");
while((c = getchar()) != EOF) {
fprintf(stderr, "char == 0x%x\n", c);
}
}
bye()
{
fcntl(0, F_SETFL, flags &= ~NODELAY); /* reset to blocking I/O */
exit(0);
}
main()
{
/* asynchronous I/O interrpt handler */
signal(SIGPOLL, handler);
/* reset to blocking mode and exit on intr, quit */
signal(SIGINT, bye);
signal(SIGQUIT, bye);
/*
* put stdin in non-blocking mode.
*/
flags = fcntl(0, F_GETFL);
fcntl(0, F_SETFL, flags |= NODELAY);
/*
* request SIGPOLL when input is available
*/
if (ioctl( 0, I_SETSIG, S_INPUT ) < 0) {
perror("ioctl");
exit(1);
}
printf("type some chars followed by a carriage return to test.\n");
printf("type interrupt key to exit.\n");
/* loop forever, waiting for SIGPOLLs */
for (;;) ;
}
-- Arman Bostani // UCLA Computer Science Department
-- arman at CS.UCLA.EDU // ...!(ucbvax,rutgers)!ucla-cs!arman
More information about the Comp.unix.wizards
mailing list