When we use read() to read data from a socket like:
ret = read(fd, buffer, sizeof(struct msg));
the read() may return ‘ret’ which is small than sizeof(struct msg) even the socket is not O_NONBLOCKING.
The correct way is:
ret = recv(fd, buffer, sizeof(struct msg), MSG_WAITALL);
Then, recv() will wait util all sizeof(struct msg) be read out.