AK_
AK_

Reputation: 2069

Windows socket recv flags

I'm reading socket recv() documentation from msdn, and it is not clear to me what these flags do exactly:

int recv(
  _In_  SOCKET s,
  _Out_ char   *buf,
  _In_  int    len,
  _In_  int    flags //these
);

I peeked into winsock2.h and found the values of some flags like: MSG_OOB and MSG_PEEK, but MSG_WAITALL is not defined there.

Can you please explain to me what each flag does and what is the value of it (int) ?

Edit: It seems that I was not clear in my question, but I did read the documentation section about the flag and I still do not understand the behavior of recv() with each flag, hence I'm asking for an explanation of each flag with an example if possible.

Upvotes: 1

Views: 6544

Answers (1)

Mike Weir
Mike Weir

Reputation: 3189

Check this MSDN article out on recv():

https://msdn.microsoft.com/en-us/library/windows/desktop/ms740121(v=vs.85).aspx

I've honestly not used any of these flags in all the networking work I've done, except for MSG_PEEK - I can't see why it'd come up in most situations these days.

You can look at the WinSock2.h header file and deduce the values from there:

#define MSG_OOB         0x1             /* process out-of-band data */
#define MSG_PEEK        0x2             /* peek at incoming message */
#define MSG_DONTROUTE   0x4             /* send without using routing tables */ 
#define MSG_WAITALL     0x8             /* do not complete until packet is */ 

Upvotes: 3

Related Questions