我最近开始使用Boost Asio。我注意到TCP套接字的receive方法接受一个message_flags作为参数。然而,我找到的message_flags文档只说明它是一个整数,没有指定可以分配的有效值。可以分配给message_flags的值是什么?它们代表什么意思?
我最近开始使用Boost Asio。我注意到TCP套接字的receive方法接受一个message_flags作为参数。然而,我找到的message_flags文档只说明它是一个整数,没有指定可以分配的有效值。可以分配给message_flags的值是什么?它们代表什么意思?
我搜索了一段时间,最后试图查看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
是可能的值。我会尝试使用它们,看看能否让它们起作用。这个参数将被转发到系统调用中。例如,在Windows中,它会直接转发到WSASend。param的含义应在操作系统文档中进行检查:Windows的WSASend,否则recvmsg。