Archived

This topic is now archived and is closed to further replies.

daerid

MSG_PEEK not working as advertised (WinSock)

Recommended Posts

The documentation (MSDN) says that this:
SOCKET s;
// connect ...
char buffer[32];
int len = recv(s,buffer,32,MSG_PEEK);
 
Copies the data into the buffer, but doesn''t remove it from the pending queue of incoming data, and then returns the amount of data in the queue:
quote:
MSDN: MSG_PEEK: Peeks at the incoming data. The data is copied into the buffer but is not removed from the input queue. The function then returns the number of bytes currently pending to receive.
However, whenever I try to do this, and call recv with a value I know is less than the amount of incoming bytes, recv always returns the value I pass it.
  

// Say there''s 60 incoming bytes

char recvbuf[32]; // only space for 32

int len = recv(s,recvbuf,32,MSG_PEEK);
// len should now equal 60, right?

// then why does it ALWAYS RETURN 32?!?!?

  
Am I just on crack? Is there something I''m not getting? Or is MSDN just blatantly wrong? And! If so, how do I go about finding the amount of data pending without going Asynchronous?

Share this post


Link to post
Share on other sites