$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] Bug in boost.asio ssl::stream write_some read_some methods?
From: Michael Peltonen (michael.peltonen_at_[hidden])
Date: 2009-03-20 07:36:23
Hi,
When I compile my program that uses synchronous ssl::stream methods  
read_some and
write_some, the compiler complains about ambigious binds. I believe  
this is a bug in the
boost.asio library. My code compiled and run fine on boost_1_36_0 in  
windows environment,
but not with boost_1_37_0 or boost_1_38_0 on solaris SPARC 10  
environment? Boost compiles
fine without any errors on solaris, so I believe this is a new  
boost.asio bug that has
been introduced in the newest two releases. I tried to confirm this by  
building
boost_1_36_0 on my solaris machine, but could not get it to compile  
without errors.
The error message:
/usr/local/include/boost/asio/ssl/detail/openssl_stream_service.hpp:  
In member function
`size_t
boost::asio::ssl::detail::openssl_stream_service::read_some(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, Stream&, const Mutable_Buffers&, boost::system::error_code&) [with Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp>  
 >,
Mutable_Buffers
=
boost::asio::mutable_buffers_1]':
/usr/local/include/boost/asio/ssl/stream_service.hpp:149:    
instantiated from `size_t
boost::asio::ssl::stream_service::read_some(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, Stream&, const MutableBufferSequence&, boost::system::error_code&) [with Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp>  
 >,
MutableBufferSequence
=
boost::asio::mutable_buffers_1]'
/usr/local/include/boost/asio/ssl/stream.hpp:397:   instantiated from `size_t
boost::asio::ssl::stream<Stream, Service>::read_some(const  
MutableBufferSequence&,
boost::system::error_code&) [with MutableBufferSequence =  
boost::asio::mutable_buffers_1,
Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> >, Service =
boost::asio::ssl::stream_service]'
program.cpp:691:   instantiated from here
/usr/local/include/boost/asio/ssl/detail/openssl_stream_service.hpp:416:  
error: call of
overloaded `bind(int (*)(SSL*, void*, int), boost::arg<1>, void*,  
int)' is ambiguous
/usr/local/include/boost/bind.hpp:1298: note: candidates are:  
boost::_bi::bind_t<R, F,
typename boost::_bi::list_av_3<a1, A2, A3>::type> boost::bind(F, A1,  
A2, A3) [with R =
int, F = int (*)(SSL*, void*, int), A1 = boost::arg<1>, A2 = void*, A3 = int]
/usr/local/include/boost/bind/bind_cc.hpp:47: note:                  
boost::_bi::bind_t<R,
R (*)(B1, B2, B3), typename boost::_bi::list_av_3<a1, A2, A3>::type>  
boost::bind(R
(*)(B1, B2, B3), A1, A2, A3) [with R = int, B1 = SSL*, B2 = void*, B3  
= int, A1 =
boost::arg<1>, A2 = void*, A3 = int]
/usr/local/include/boost/asio/ssl/detail/openssl_stream_service.hpp:  
In member function
`size_t
boost::asio::ssl::detail::openssl_stream_service::write_some(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, Stream&, const Const_Buffers&, boost::system::error_code&) [with Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp>  
 >,
Const_Buffers
=
boost::asio::const_buffers_1]':
/usr/local/include/boost/asio/ssl/stream_service.hpp:132:    
instantiated from `size_t
boost::asio::ssl::stream_service::write_some(boost::asio::ssl::detail::openssl_stream_service::impl_struct*&, Stream&, const ConstBufferSequence&, boost::system::error_code&) [with Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp, boost::asio::stream_socket_service<boost::asio::ip::tcp>  
 >,
ConstBufferSequence
=
boost::asio::const_buffers_1]'
/usr/local/include/boost/asio/ssl/stream.hpp:320:   instantiated from `size_t
boost::asio::ssl::stream<Stream, Service>::write_some(const  
ConstBufferSequence&,
boost::system::error_code&) [with ConstBufferSequence =  
boost::asio::const_buffers_1,
Stream = boost::asio::basic_stream_socket<boost::asio::ip::tcp,
boost::asio::stream_socket_service<boost::asio::ip::tcp> >, Service =
boost::asio::ssl::stream_service]'
program.cpp:704:   instantiated from here
/usr/local/include/boost/asio/ssl/detail/openssl_stream_service.hpp:342:  
error: call of
overloaded `bind(int (*)(SSL*, const void*, int), boost::arg<1>, const  
void*, int)' is
ambiguous
/usr/local/include/boost/bind.hpp:1298: note: candidates are:  
boost::_bi::bind_t<R, F,
typename boost::_bi::list_av_3<a1, A2, A3>::type> boost::bind(F, A1,  
A2, A3) [with R =
int, F = int (*)(SSL*, const void*, int), A1 = boost::arg<1>, A2 =  
const void*, A3 = int]
/usr/local/include/boost/bind/bind_cc.hpp:47: note:                  
boost::_bi::bind_t<R,
R (*)(B1, B2, B3), typename boost::_bi::list_av_3<a1, A2, A3>::type>  
boost::bind(R
(*)(B1, B2, B3), A1, A2, A3) [with R = int, B1 = SSL*, B2 = const  
void*, B3 = int, A1 =
boost::arg<1>, A2 = const void*, A3 = int]
make: *** [program.o] Error 1
The code:
         boost::asio::io_service io_service;
         boost::asio::ip::tcp::acceptor acceptor(io_service,
boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 7722));
         boost::asio::ssl::context context(io_service,  
boost::asio::ssl::context::sslv23);
         context.set_options(
             boost::asio::ssl::context::default_workarounds
             | boost::asio::ssl::context::no_sslv2
             | boost::asio::ssl::context::single_dh_use);
         context.set_verify_mode(
             boost::asio::ssl::context::verify_peer
             | boost::asio::ssl::context::verify_fail_if_no_peer_cert);
         context.use_certificate_chain_file("server-public.pem");
         context.use_private_key_file("server-private.pem",
boost::asio::ssl::context::pem);
         context.use_tmp_dh_file("dh4096.pem");
         context.load_verify_file("client-public.pem");
         while(!exit)
         {
             for (;;)
             {
                 std::string message;
                 boost::array<char, 128> buf;
                 boost::system::error_code error;
                  
boost::asio::ssl::stream<boost::asio::ip::tcp::socket>  
socket(io_service,
context);
                 acceptor.accept(socket.lowest_layer());
                 socket.handshake(boost::asio::ssl::stream_base::server);
                 size_t len =  
socket.read_some(boost::asio::buffer(buf), error);
                 if (error == boost::asio::error::eof)
                     break; // Connection closed cleanly by peer.
                 else if (error)
                     throw boost::system::system_error(error); // Some  
other error.
                 message.assign(buf.data(), len);
                 if(message.compare("statistics") == 0)
                     message = statistics_reply();
                 else
                     message = error_reply();
                 boost::system::error_code ignored_error;
                 socket.write_some(boost::asio::buffer(message),  
ignored_error);
             }
         }
Regards,
-Michael