16

I recently began working with Boost Asio. I noticed that the receive method of a TCP socket accepts a message_flags as a parameter. However, the documentation I found for message_flags only says that it is an integer without specifying the valid values. What are the values that can be assigned to a message_flags and what do they mean?

Sam Miller
  • 23,808
  • 4
  • 67
  • 87
Brian
  • 1,201
  • 2
  • 14
  • 26

3 Answers3

19

I searched for a while and finally tried to look in Boost's source code. I found this in socket_base.hpp:

  /// Bitmask type for flags that can be passed to send and receive operations.
  typedef int message_flags;

  #if defined(GENERATING_DOCUMENTATION)
  /// Peek at incoming data without removing it from the input queue.
  static const int message_peek = implementation_defined;

  /// Process out-of-band data.
  static const int message_out_of_band = implementation_defined;

  /// Specify that the data should not be subject to routing.
  static const int message_do_not_route = implementation_defined;

  /// Specifies that the data marks the end of a record.
  static const int message_end_of_record = implementation_defined;
  #else
  BOOST_ASIO_STATIC_CONSTANT(int,
      message_peek = BOOST_ASIO_OS_DEF(MSG_PEEK));
  BOOST_ASIO_STATIC_CONSTANT(int,
      message_out_of_band = BOOST_ASIO_OS_DEF(MSG_OOB));
  BOOST_ASIO_STATIC_CONSTANT(int,
      message_do_not_route = BOOST_ASIO_OS_DEF(MSG_DONTROUTE));
  BOOST_ASIO_STATIC_CONSTANT(int,
      message_end_of_record = BOOST_ASIO_OS_DEF(MSG_EOR));
  #endif

Based on this, it looks like message_peek, message_out_of_band, and message_do_not_route are the possible values. I'm going to give these a try and see if I can get them to work.

Gluttton
  • 5,739
  • 3
  • 31
  • 58
Brian
  • 1,201
  • 2
  • 14
  • 26
4

This param is forwarded to system call. For instance in Windows it is forwarded directly to WSASend. The meaning of param should be checked in OS docs: WSASend for Windows otherwise recvmsg.

k4hvd1
  • 61
  • 4
1

I encountered the same problem and my solution was to use overload that doesnt take message_flags parameter (http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_datagram_socket/send_to/overload1.html ).

Downside is that if you want error code error reporting you cant use it(overload uses exception, and doesnt take ec param)

NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277