Tag Archives: socket

Use recv() instead of read() for socket

When we use read() to read data from a socket like:

the read() may return ‘ret’ which is small than sizeof(struct msg) even the socket is not O_NONBLOCKING. The correct way is:

Then, recv() will wait util all sizeof(struct msg) be read out.