I wrote a blocking loop to read unsolicited messages. I can't have an end char to detect the end of the message, but I am pretty happy with the timeout. VMIN=1
VTIME=5
Here when the recieved bytes are fewer than the buffer size, I presume the end of the messagge.
This code works, but will fail if the message is exactly 33 chars long. Any idea?
int l = 0;
string o = "";
char buf[33];
while(1) {
if (l && l < 33) {
// Messagge end, do something
}
l = read(fd, buf, 33);
o.append(buf, 0, l);
}