0
votes

In the following code:

   boost::signals2::signal<void(const boost::system::error_code&)> signal;
   socket.async_connect(endpoint, boost::ref(signal));

(Found at http://liveworkspace.org/code/e04910cbcc4cfd9e42e34d1af55c393e)

I get this error:

In file included from boost/asio/detail/wrapped_handler.hpp:18:0, from boost/asio/io_service.hpp:24, from boost/asio/basic_io_object.hpp:20, from boost/asio/basic_socket.hpp:19, from boost/asio/basic_datagram_socket.hpp:20, from boost/asio.hpp:20, from source.cpp:2: boost/asio/detail/bind_handler.hpp: In member function 'void boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code ::operator()()': boost/asio/handler_invoke_hook.hpp:64:3: instantiated from 'void boost::asio::asio_handler_invoke( boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code , ... )' boost/asio/detail/handler_invoke_helpers.hpp:39:3: instantiated from 'void boost_asio_handler_invoke_helpers::invoke( const boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code &, boost::reference_wrapper > & )' boost/asio/detail/bind_handler.hpp:73:3: instantiated from 'void boost::asio::detail ::asio_handler_invoke( const boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code &, boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code * )' boost/asio/detail/handler_invoke_helpers.hpp:39:3: instantiated from 'void boost_asio_handler_invoke_helpers::invoke( const boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code &, boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code & )' boost/asio/detail/completion_handler.hpp:63:7: instantiated from 'static void boost::asio::detail ::completion_handler< boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code

::do_complete( boost::asio::detail::boost::asio::detail::task_io_service *, boost::asio::detail::boost::asio::detail::task_io_service_operation *, boost::system::error_code, unsigned int )' boost/asio/detail/completion_handler.hpp:38:17: instantiated from 'boost::asio::detail ::completion_handler< boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code

::completion_handler( boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code

)' boost/asio/detail/impl/task_io_service.hpp:50:3: instantiated from 'void boost::asio::detail ::task_io_service::post( boost::asio::detail::binder1< boost::reference_wrapper >, boost::system::error_code

)' boost/asio/impl/io_service.hpp:80:3: instantiated from 'void boost::asio::io_service::post(Handler)' boost/asio/basic_socket.hpp:649:9: instantiated from 'void boost::asio::basic_socket< boost::asio::ip::tcp, boost::asio::stream_socket_service ::async_connect( boost::asio::basic_socket >::boost ::asio::ip::basic_endpoint &, boost::reference_wrapper> )' source.cpp:10:53: instantiated from here boost/asio/detail/bind_handler.hpp:40:5: error: no match for call to '( boost::reference_wrapper> ) (const boost::system::error_code &)'

2

2 Answers

2
votes

Looks like your signature is wrong? You need to specify a placeholder for the error_code

Try

boost::signals2::signal<void(const boost::system::error_code&)> signal;
socket.async_connect(endpoint, boost::bind(boost::ref(signal), _1));
1
votes

Ralf's answer is close, I think you need to bind the placeholder to the signal functor:

#include <boost/signals2.hpp>
#include <boost/asio.hpp>

using namespace boost::asio;

int 
main() 
{
   io_service ios;
   ip::tcp::socket socket(ios);
   const ip::tcp::endpoint endpoint(
           ip::address::from_string(""), 
           0
           );

   boost::signals2::signal<void(const boost::system::error_code&)> signal;
   socket.async_connect(
           endpoint, 
           boost::bind(
               boost::ref(signal), _1
               ) 
       );
}

example:

samm@macmini ~$ g++ -I /opt/local/include -L/opt/local/lib -Wl,-rpath,/opt/local/lib -lboost_system signal.cc 
samm@macmini ~$ echo $?
0
samm@macmini ~$