尝试使用boost::asio::write()写入boost::asio::ip::udp::socket对象。 虽然我正忙着重新阅读文档,看看我是否在某个地方出错了,有人可以确认一下是否支持这个吗? 我现在想的是boost::asio::write()只支持tcp::socket对象,而不支持udp::socket 。
这是我尝试编译时得到的:
/usr/include/boost/asio/impl/write.ipp: In function ‘size_t boost::asio::write(SyncWriteStream&, const ConstBufferSequence&, [...cut...] test/test.cpp:76: instantiated from here /usr/include/boost/asio/impl/write.ipp:44: error: ‘class boost::asio::basic_datagram_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >’ has no member named ‘write_some’我想我在文档中读到这个时决定尝试使用boost::asio::write() :
发送操作可能不会将所有数据发送到对等方。 如果需要确保在阻塞操作完成之前写入所有数据,请考虑使用write函数
...但是回过头来看,我看到文本只在boost::asio::ip::tcp::socket::send() ,而不在UDP版本中。 资源。
Trying to use boost::asio::write() to write to a boost::asio::ip::udp::socket object. While I'm busy re-reading the docs to see if I've gone wrong somewhere, can someone confirm if maybe this is not supported? I'm now thinking boost::asio::write() only supports tcp::socket objects, not udp::socket.
This is what I get when I try to compile:
/usr/include/boost/asio/impl/write.ipp: In function ‘size_t boost::asio::write(SyncWriteStream&, const ConstBufferSequence&, [...cut...] test/test.cpp:76: instantiated from here /usr/include/boost/asio/impl/write.ipp:44: error: ‘class boost::asio::basic_datagram_socket<boost::asio::ip::udp, boost::asio::datagram_socket_service<boost::asio::ip::udp> >’ has no member named ‘write_some’I think I decided to try boost::asio::write() when I read this in the docs:
The send operation may not transmit all of the data to the peer. Consider using the write function if you need to ensure that all data is written before the blocking operation completes.`
...but in going back, I see that text is only in boost::asio::ip::tcp::socket::send() and not in the UDP version. Source.
最满意答案
假设您需要同步行为,则需要使用boost::asio::ip::udp::socket类的send或send_to成员方法。 boost::asio::write free函数使用SyncWriteStream类型要求,UDP套接字不符合要求。
Assuming you want synchronous behavior, you need to use the send or send_to member methods of the boost::asio::ip::udp::socket class. The boost::asio::write free function uses the SyncWriteStream type requirement, which a UDP socket does not meet.
更多推荐
发布评论