//then it starts over again and continues until I've received all.
Most of the times this works and I receive all data, but sometimes I get error(code: 10014) from recv() which indicates bad pointer or that buflen is to small.
I know for sure that "new_memory" and "buflen" has the right size for the remaining request (after they're updated), so it's not about that.
How about something that makes the pointer invalid or something that happens dynamically, that doesn't work well when it continues to recv?
I have the information about the remaining request within the first recv. After I've interpret the first recv I can set the value of "full request length".
//then I do the things below (only if it's the initial request)
"get_request_info()" should be included to the top of that block, The function finds the value of full request length etc.
Why does memcpy only copy recv_length bytes? Shouldn't it copy total_recv_length or buflen bytes?
No. Because this happens only after the first recv(initial request as I mentioned in my post), at that point I haven't received anything else than "recv_length"(initial request)
So the recv() parameter where buflen goes in has nothing to do with the total capacity of the array(recvbuf)? It wants to know how much is left/available?
> recvbuf[total_recv_length] = '\0';
Also, this is a buffer overflow if recv() actually fills the buffer.