Open yifu opened 9 years ago
Or deal with partial read. From the specification of read():
The value returned may be less than nbyte if the number of bytes left in the file is less than nbyte, if the read() request was interrupted by a signal, or if the file is a pipe or FIFO or special file and has fewer than nbyte bytes immediately available for reading.
A signal may be an hardware signal?
Or implement a SOCK_SEQPACKET, as from the the man unix
page it's preserves msg boundaries!
and (since Linux 2.6.4) SOCK_SEQPACKET, for a connection-oriented socket that preserves message boundaries and delivers messages in the order that they were sent.
Or use fdopen
to transform the file descriptor into a FILE handle, and use the fwrite()/fread() functions.
Cons: Actually it's buffered, event though it's optional, I don't think it's a good idea.
read()
man page:
MSG_WAITALL (since Linux 2.2) This flag requests that the operation block until the full request is sat‐ isfied. However, the call may still return less data than requested if a signal is caught, an error or disconnect occurs, or the next data to be received is of a different type than that returned.
Cons: I do not know the exact message size before calling recv(). I cannot use that option.
Under linux msgqueue descriptor are file descriptor:
http://man7.org/linux/man-pages/man7/mq_overview.7.html