title: How do I tell how much data the socket recv() function received when it returns value of 0?
body: <p>This may seem like a silly question, but it has been driving me nuts.  I am working on a network programming assignment, and one part of the code that I wrote is calling the socket recv() function with a buffer, length of the buffer, and zero specified for the flags.  The recv() call returns a value of zero, and the man page says a return value of zero indicates the 'stream socket peer has performed an orderly shutdown.'</p>
  
  <p>The problem is that the recv() call did actually receive data, and did update my buffer.  I know because I can print it out using printf, and the data that I expected to receive during that recv() call shows up in the printf output.  The problem, though is that since recv() returned zero I don't really know how much data was actually put into my buffer.  I do a memset on the buffer with 0 to zero it out before I use it, so I guess I could do a strlen() call on the buffer afterward, but this seems like a hack.  Is this what I'm suppose to do?</p>
  
  <p>One other thing is that the socket is still open because I then loop over the socket in a while loop shortly after the first recv() call and continue receiving more data.  The size of the buffer I am using is a char buffer[4096] array.  Any insight would be greatly appreciated.</p>