O_NDELAY problem

O_NDELAY problem

Post by Bill Dav » Sat, 15 Jan 1994 23:43:22

I am attempting to open a physical device non-blocking.

fd = open("/dev/ttya",O_RDWR|O_NDELAY,0666);

The /etc/ttytab definition for ttya is:

ttya    "/usr/etc/getty std.9600"       unknown         off local secure

Device permissions are:
crw-rw-rw-  1 root      12,   0 Jan 13 19:27 /dev/ttya

This is a Sun SPARC 10 running SunOS 4.1.3
using the "almost ANSI" acc compiler.

This works on one of our devices fine.
I have a new device on ttya which I am trying to
use.  I am not sure it handles all of the control signals
properly, but the non-blocking open should work anyway, right?

I also tried leaving out the mode:

fd = open("/dev/ttya",O_RDWR|O_NDELAY);

Unless the Sun acc compiler is doing something tricky,
I would assume  this makes the third parameter random.

Under what conditions would the open fail to immediately
return since it is set to no delay?  I need to open the
device non-blocking so that I can disable DCD and enable

I do not have access to Sun OS source code, so I cannot
check what conditions the driver may be looking for
with O_NDELAY.  I have also tried O_NONBLOCK
with the same effect.

Any ideas what might be wrong?

Bill Davis


1. O_NDELAY / c_cc[TIME] problem

I'm talking to a serial device (an infusion pump) out the serial port:

 if ((fd = open("/dev/ttyS0", O_RDWR)) == -1)
        printf("open error\n");

    if (ioctl(fd, TCGETA, &tbuf) == -1)
        printf("ioctl1 error\n");
    tbufsave = tbuf;

    tbuf.c_iflag &= ~(INLCR | ICRNL | IUCLC | ISTRIP | IXON | BRKINT);
    tbuf.c_oflag &= ~OPOST;
    tbuf.c_lflag &= ~(ICANON | ISIG | ECHO);
    tbuf.c_cc[4] = 0;           /* MIN */
    tbuf.c_cc[5] = 1;           /* TIME */

    if (ioctl(fd, TCSETAF, &tbuf) == -1)
        printf("ioctl2 error\n");

    i = read(fd, &c, 1);

The intention is to have the read return if there are no characters
available within 1 tenth of a second.

It doesn't return...it blocks, waiting for a character.

If I open the port O_RDWR | O_NDELAY, then it doesn't block.

Should I have to do this? (open with O_NDELAY)?
Does O_NDELAY do magic with some modem control lines?

Thanks for the help



Chris Wright                               Ph: 61 3 9550 1111
Deputy Director, ICU                       Fax: 61 3 9550 6111
Director, Medical Informatics              e-mail:

Monash Medical Centre, VIC Australia

2. ncurses

3. open("/dev/cua/d", O_RDWR|O_NDELAY) (sleeping...)

4. some massive linux c++ code

5. _REENTRANT & O_NDELAY description anywhere?

6. Splitting a variable number of fixed length fields


8. Mouse and VGA

9. write(), even with O_NDELAY still blocks!?!

10. How to set O_NDELAY for a socket in SVR4

11. Shared sockets & O_NDELAY


13. Any known BUG in --> fcntl( fd, F_SETFL, O_NDELAY );