Search code examples
linuxcallbackmessagepolling

does linux socket poll handle discrete messages?


I dropped in to ask whether if I send, say, two discrete messages with send (linux C/C++) and read it out in a poll(2/3) callback, can it happen that the two writes (packets) will be read out as one, or for each message there will be a separate poll event? Note, I use IOCTL to peek for the size of pending data to be read. So is it the size of always one message or may happen to be the size of more?

Edit: socket type is SOCK_STREAM.


Solution

  • In STREAM sockets (I guess you do not use a DGRAM socket?) the messages may be joined (there are no message boundaries in stream), or a single message may be separated into several parts.

    To make the communication reliable, prefix each packet with its length.