to make "read()" no return until read all the bytes requiered

Hello,

I have one application that reads and writes from the serial port.

Sometimes the function read():
"read(fd,buffer,numbytes)" returns a number < numbytes. (Because there are not more data in the serial port buffer)
I mean. if numbytes is 32, sometimes read returns 12, and in the next read returns the 20 remaining.

I want to avoid that and I want that "read()" does not return until reads all the numbytes. I want that "read()" waits until read all the bytes in the third parameter.

Some ideas?

I have tried to "open()" with different configurations but all the time "read()" does not wait until reads everything.

Also I have thought about to change the mode from the default one "byte-stream" to " message-nondiscard" but when I try to use the functions:
ioctl(fd,I_SRDOPT,param)
ioctl(fd,I_GRDOPT,param)
both functions returns -1 with errno = EINVAL and I do not know if it is bercause I set badly the parameters or is because "Stream is linked under a multiplexing driver" (REALLY I DO NOT WHAT THIS MEANS).

Here I write how I use ioctl:

int a;
ioctl(fd,I_GRDOPT,&a); -> //fails -1 and errno = EINVAL

ioctlfd,I_SRDOPT,RMSGN) > //fails -1 and errno = EINVAL.

So if I am using correctly both functions, could somebody explain me the error:
"[EINVAL] fd refers to a Stream that is linked under a multiplexing driver. If a Stream is linked under a multiplexing driver, all ioctl(2s) commands other than I_UNLINK or I_PUNLINK will return [EINVAL]. "?

How can I do that "read()" waits until all the bytes are read as requiered?

Thank you.
Why don't you just write a wrapper function for read that doesn't return until all bytes are read?

Topic archived. No new replies allowed.