我最近开始使用Boost Asio。我注意到receive method of a TCP socket接受message_flags作为参数。但是,我找到的message_flags文档只说它是一个整数,没有指定有效值。可以分配给message_flags的值是什么?它们的含义是什么?
发布于 2011-08-19 01:21:16
我搜索了一段时间,最后尝试查看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是可能的值。我要试一试,看看能不能让它们工作。
发布于 2016-10-07 21:57:19
发布于 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参数)
https://stackoverflow.com/questions/7098660
复制相似问题