On Sun, 2 May 2010 12:01:59 -0700 "J.C. Roberts"
<[email protected]> wrote:

> The other problem is understanding what is happening. Unless you
> specifically configured the descriptor to return immediately, your 
> read(2) call will sleep until it gets the requested number of bytes
> from the descriptor, until an interval timer expires, or until an
> error occurs. Since the instrument is not sending you any data, it
> sleeps until you lose your patience and hit CTL-C to end the program.
> --This should not be a surprise. ;)


I should have referenced your code so the above makes sense.

>> int open_port(void)
>> {
>>   int fd;
>> 
>>   fd = open("/dev/ttyU0", O_RDWR | O_NOCTTY | O_NDELAY);
>>   if (fd < 0)
>>   {
>>     errx(1,"open_port: Unable to open /dev/ttyS0.");
>>   }
>>   else
>>   {
>>     fcntl(fd, F_SETFL, 0);
>>   }
>>   return (fd);
>> }

Setting O_NDELAY (or better said O_NONBLOCK) on open gets wiped out
when you run "fcntl(fd, F_SETFL, 0)"

I have no idea why you're doing that (probably just mistyped example
code), but if you insist, then you'd actually want:

        fcntl(fd, F_SETFL, FNDELAY);
or
        fcntl(fd, F_SETFL, FNONBLOCK);

Hence the reason why you're actually blocking on read.

-- 
The OpenBSD Journal - http://www.undeadly.org

Reply via email to