首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >提升Asio message_flags

提升Asio message_flags
EN

Stack Overflow用户
提问于 2011-08-18 03:57:58
回答 3查看 7.8K关注 0票数 16

我最近开始使用Boost Asio。我注意到receive method of a TCP socket接受message_flags作为参数。但是,我找到的message_flags文档只说它是一个整数,没有指定有效值。可以分配给message_flags的值是什么?它们的含义是什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-08-19 01:21:16

我搜索了一段时间,最后尝试查看Boost的源代码。我在socket_base.hpp里找到了这个

代码语言:javascript
复制
  /// 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

基于此,看起来message_peekmessage_out_of_bandmessage_do_not_route是可能的值。我要试一试,看看能不能让它们工作。

票数 19
EN

Stack Overflow用户

发布于 2016-10-07 21:57:19

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

票数 4
EN

Stack Overflow用户

发布于 2014-02-05 22:46:20

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

缺点是,如果你想要错误代码错误报告,你不能使用它(重载使用异常,不带ec参数)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7098660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档