For streaming protocols such as TCP, you can pretty much set your buffer to any size. That said, common values that are powers of 2 such as 4096 or 8192 are recommended.
If there is more data then what your buffer, it will simply be saved in the kernel for your next call to recv
.
Yes, you can keep growing your buffer. You can do a recv into the middle of the buffer starting at offset idx
, you would do:
recv(socket, recv_buffer + idx, recv_buffer_size - idx, 0);