Here's my scenario. I have a TCP client that is talking to the server. Both the server and the client are running on local machine (Windows).
The dialog goes something like:
- Client sends data to the server (Request)
- Client does shutdown for send on the socket
- Client blocks via a read call for response
- Server receives the data, processes, and sends back a response (one shot, not broken into chunks)
- Server does shutdown for send on the socket
- Client receives the response, and continues processing.
At step 3, I am using recv() call to block and read data from the socket. At this point, I would like to peek to see how many bytes of data is available, so that I can allocate so much memory. By design, it is known that the server has sent all the data, and there is no more data for this request to be sent. (See step 5 above).
I have tried recv() with MSG_PEEK option, but that does not seem to give the total number of bytes available.
Is there a way to retrieve it?
Thanks in advance.