我使用以下方法:
boost::asio::streambuf io_bufstream;
boost::asio::async_read_until(socket_, io_bufstream, "</message>",
strand_.wrap(
boost::bind(&Connection::handleRead, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));//warning: line 36
boost::array<char, 8192> buffer_
socket_.async_read_some(boost::asio::buffer(buffer_),
strand_.wrap(
boost::bind(&Connection::handleRead, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred))); // warning
我收到以下警告:
C:\dev\sapphire\boost_1_46_1\boost/asio/detail/reactive_socket_recv_op.hpp(58) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
以下是完整的输出:
C:\dev\sapphire\boost_1_46_1\boost/asio/detail/reactive_socket_recv_op.hpp(58) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
C:\dev\sapphire\boost_1_46_1\boost/asio/detail/reactive_socket_recv_op.hpp(48) : while compiling class template member function 'bool boost::asio::detail::reactive_socket_recv_op_base::do_perform(boost::asio::detail::reactor_op *)'
with
[
MutableBufferSequence=boost::asio::mutable_buffers_1
]
C:\dev\sapphire\boost_1_46_1\boost/asio/detail/reactive_socket_recv_op.hpp(71) : see reference to class template instantiation 'boost::asio::detail::reactive_socket_recv_op_base' being compiled
with
[
MutableBufferSequence=boost::asio::mutable_buffers_1
]
C:\dev\sapphire\boost_1_46_1\boost/asio/detail/reactive_socket_service_base.hpp(227) : see reference to class template instantiation 'boost::asio::detail::reactive_socket_recv_op' being compiled
with
[
MutableBufferSequence=boost::asio::mutable_buffers_1,
Handler=boost::asio::detail::wrapped_handler,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>>
]
C:\dev\sapphire\boost_1_46_1\boost/asio/stream_socket_service.hpp(263) : see reference to function template instantiation 'void boost::asio::detail::reactive_socket_service_base::async_receive(boost::asio::detail::reactive_socket_service_base::base_implementation_type &,const MutableBufferSequence &,boost::asio::socket_base::message_flags,Handler)' being compiled
with
[
MutableBufferSequence=boost::asio::mutable_buffers_1,
ReadHandler=boost::asio::detail::wrapped_handler,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>>,
Handler=boost::asio::detail::wrapped_handler,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>>
]
C:\dev\sapphire\boost_1_46_1\boost/asio/basic_stream_socket.hpp(708) : see reference to function template instantiation 'void boost::asio::stream_socket_service::async_receive(boost::asio::detail::reactive_socket_service::implementation_type &,const MutableBufferSequence &,boost::asio::socket_base::message_flags,ReadHandler)' being compiled
with
[
Protocol=boost::asio::ip::tcp,
MutableBufferSequence=boost::asio::mutable_buffers_1,
ReadHandler=boost::asio::detail::wrapped_handler,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>>
]
..\..\..\platform_epi\src\connection.cpp(36) : see reference to function template instantiation 'void boost::asio::basic_stream_socket::async_read_some>(const MutableBufferSequence &,ReadHandler)' being compiled
with
[
Protocol=boost::asio::ip::tcp,
Dispatcher=boost::asio::io_service::strand,
Handler=boost::_bi::bind_t,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>,
MutableBufferSequence=boost::asio::mutable_buffers_1,
ReadHandler=boost::asio::detail::wrapped_handler,boost::_bi::list3>,boost::arg<1>,boost::arg<2>>>>
]
据我所知,错误来自第36行,但我不明白发生了什么。我认为它与bytes_transferred有关,当它是int时用作bool。如果有人能澄清这个问题和/或如何解决它,那就太棒了!
谢谢!
答案 0 :(得分:3)
这是一个特定于Visual Studio的警告,它是从Boost的代码中发出的,而不是你的代码。在大多数情况下可以忽略它。如果要禁用它,请使用适当的编译指示。
#pragma warning(disable: 4800)
可能已在最新的Boost.ASIO版本中修复。我安装了1.47并且有问题的线路没有发出此警告。