Re: Blocking read() from a USB->Serial adapter.
- From: Charles Sullivan <cwsulliv@xxxxxxxxxxxx>
- Date: Sat, 25 Nov 2006 04:18:01 GMT
On Sat, 25 Nov 2006 01:49:03 +0100, Bjoern Schliessmann wrote:
Charles Sullivan wrote:
A blocking read() of more than one character from an actual RS232
serial port returns when the number of characters specified has
been read.
No. Have a look at man 2 read. Note the word "attempts".
| READ(2) Linux Programmer?s Manual READ(2)
|
| NAME
| read - read from a file descriptor
|
| SYNOPSIS
| #include <unistd.h>
|
| ssize_t read(int fd, void *buf, size_t count);
|
| DESCRIPTION
| read() attempts to read up to count bytes from file
| descriptor fd into the buffer starting at buf.
|
| If count is zero, read() returns zero and has no other
| results. If count is greater than SSIZE_MAX, the result is
| unspecified.
|
| RETURN VALUE
| On success, the number of bytes read is returned [...]
However I've found that a blocking read() of more than one
character from a USB->Serial adapter reads only the first
character before returning and I have to loop to read all the
characters.
- You have to do this no matter which FD you read from. If you
don't, 100 times the reading may succeed and the 101. time it may
not. Funny bugs may arise.
I can understand the "attempts to read" for a non-blocking read -
returning fewer characters than specified if the characters
aren't immediately available to be read.
But I had the impression that a blocking read is supposed to block
forever or until it either reads the specified number of characters
or is interrupted. You're saying maybe it will and maybe it won't
and that's to be expected.
- Why is this a problem? Considering you use a serial interface with
blocking calls the overhead of a C loop shouldn't be a problem at
all.
Not a problem. I am just puzzled why reading from the adapter
differs from reading from an actual serial port.
BTW, the number of characters to be read is never more than 10.
Regards,
Charles Sullivan
.
- Follow-Ups:
- Re: Blocking read() from a USB->Serial adapter.
- From: "Nils O. Selåsdal"
- Re: Blocking read() from a USB->Serial adapter.
- From: Bjoern Schliessmann
- Re: Blocking read() from a USB->Serial adapter.
- From: Grant Edwards
- Re: Blocking read() from a USB->Serial adapter.
- References:
- Blocking read() from a USB->Serial adapter.
- From: Charles Sullivan
- Re: Blocking read() from a USB->Serial adapter.
- From: Bjoern Schliessmann
- Blocking read() from a USB->Serial adapter.
- Prev by Date: Re: C++: conditional static data member possible?
- Next by Date: Re: Blocking read() from a USB->Serial adapter.
- Previous by thread: Re: Blocking read() from a USB->Serial adapter.
- Next by thread: Re: Blocking read() from a USB->Serial adapter.
- Index(es):
Relevant Pages
|