【发布时间】:2011-08-17 19:57:58
【问题描述】:
我最近开始使用 Boost Asio。我注意到receive method of a TCP socket 接受message_flags 作为参数。但是,我为 message_flags 找到的文档只说它是一个整数,而没有指定有效值。可以分配给 message_flags 的值是什么?它们的含义是什么?
【问题讨论】:
标签: boost tcp boost-asio
我最近开始使用 Boost Asio。我注意到receive method of a TCP socket 接受message_flags 作为参数。但是,我为 message_flags 找到的文档只说它是一个整数,而没有指定有效值。可以分配给 message_flags 的值是什么?它们的含义是什么?
【问题讨论】:
标签: boost tcp boost-asio
我搜索了一段时间,最后尝试查看 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;
/// 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_peek、message_out_of_band 和message_do_not_route 是可能的值。我要试一试,看看能不能让它们发挥作用。
【讨论】:
我遇到了同样的问题,我的解决方案是使用不带 message_flags 参数的重载(http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/reference/basic_datagram_socket/send_to/overload1.html)。
缺点是如果你想要错误代码错误报告你不能使用它(重载使用异常,并且不接受 ec 参数)
【讨论】: