This is in reference to a previous question of mine which was already answered:
My protocol actually sends how much data it is about send initially before it sends any other data. But yesterday, when testing out this code of mine using a browser, I had this one question:
A lot of people suggested that I check for message length but take the scenario of a browser. The browser's HTTP Request does not have a size when it is first sent to the server. Now, assuming that I used a 256 byte buffer, how am I supposed to manage the data structure of this client if I keep receiving partial headers between each multiplexing action? Keep using realloc as I keep getting more data and then when I encounter a termination sequence ('\r\n'), assume that all data has been received?
What I mean is, have something like this:
typedef struct {
int fd;
char *data;
} CLIENT;
And then keep using realloc on data? I was told to allocate a buffer size of the max protocol header but is that the only approach?