问题 提升Asio message_flags


我最近开始与Boost Asio合作。我注意到了 接收TCP套接字的方法 接受一个 message_flags 作为参数。但是,我在message_flags中找到的文档只说它是一个整数而没有指定有效值。可以分配给message_flags的值是什么?它们是什么意思?


4477
2017-08-17 19:57


起源



答案:


我搜索了一会儿,最后试着查看Boost的源代码。我发现了这个 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;
#else
  BOOST_STATIC_CONSTANT(int,
      message_peek = boost::asio::detail::message_peek);
  BOOST_STATIC_CONSTANT(int,
      message_out_of_band = boost::asio::detail::message_out_of_band);
  BOOST_STATIC_CONSTANT(int,
      message_do_not_route = boost::asio::detail::message_do_not_route);
#endif

基于此,它看起来像 message_peekmessage_out_of_band,和 message_do_not_route 是可能的值。我打算尝试一下,看看能不能让他们上班。


12
2017-08-18 17:21





该参数被转发到系统调用。例如,在Windows中,它直接转发到WSASend。应在OS文档中检查param的含义: WSASend 对于Windows,否则 recvmsg


1
2017-10-07 13:57





我遇到了同样的问题,我的解决方案是使用不带message_flags参数的重载(http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_datagram_socket/send_to/overload1.html )。

缺点是如果你想要错误代码错误报告你不能使用它(重载使用异常,并没有采取ec param)


0
2018-02-05 14:46



传递0作为旗帜怎么样?它不会给你想要的行为吗? - russoue
我用了0,看起来很好 - S.N.


答案:


我搜索了一会儿,最后试着查看Boost的源代码。我发现了这个 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;
#else
  BOOST_STATIC_CONSTANT(int,
      message_peek = boost::asio::detail::message_peek);
  BOOST_STATIC_CONSTANT(int,
      message_out_of_band = boost::asio::detail::message_out_of_band);
  BOOST_STATIC_CONSTANT(int,
      message_do_not_route = boost::asio::detail::message_do_not_route);
#endif

基于此,它看起来像 message_peekmessage_out_of_band,和 message_do_not_route 是可能的值。我打算尝试一下,看看能不能让他们上班。


12
2017-08-18 17:21





该参数被转发到系统调用。例如,在Windows中,它直接转发到WSASend。应在OS文档中检查param的含义: WSASend 对于Windows,否则 recvmsg


1
2017-10-07 13:57





我遇到了同样的问题,我的解决方案是使用不带message_flags参数的重载(http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_datagram_socket/send_to/overload1.html )。

缺点是如果你想要错误代码错误报告你不能使用它(重载使用异常,并没有采取ec param)


0
2018-02-05 14:46



传递0作为旗帜怎么样?它不会给你想要的行为吗? - russoue
我用了0,看起来很好 - S.N.