I am trying to read data using the following code from a socket:
n = read(fd, buffer, 50000);
The question is: when the data from the web server is larger than the tcp package size, these data will be splited into multi packages. In this case, will read function just read one data package from fd, or it will read all the packages from fd?
Note that read function is called only once.
Because you are using TCP, your socket is of type
SOCK_STREAM. ASOCK_STREAMsocket is a byte stream and does not maintain packet boundaries, so the call toread()orrecv()will read data that came from multiple packets if multiple packets of data have been received and there is sufficient space in your buffer. It may also return data from a portion of a packet if your buffer if not large enough to hold all of the data. The nextread()will continue reading from the next byte.