Boost logo

Boost Users :

Subject: [Boost-users] Callback that calls a callback using boost::bind
From: Christopher Pisz (cpisz_at_[hidden])
Date: 2011-10-01 19:22:20


I want to make a callback that also calls back.
I cannot get the code to compile.

I read on the boost documentation about apply()., but the example is
unclear and I am not sure if that is what I am looking for.

/// Smart Pointer
typedef boost::shared_ptr<TcpServerSideConnection> SmartPtr;

/// Callback function pointer type for TcpListener notification that
our execution of
/// TcpServerSideConnection::OnConnectionAccepted has completed
typedef boost::function<void(TcpServerSideConnection::SmartPtr
newConnection,
                                 const boost::system::error_code &
error)> ConnectionAcceptedListenerCallback;

/// Callback function pointer type for TcpServerSideConnection
notification of
/// a TcpListener::Listen IO completion
typedef boost::function<void(ConnectionAcceptedListenerCallback
listenerCallback,
                                 const boost::system::error_code &
error)> ConnectionAcceptedCallback;

TcpListener::SmartPtr me = boost::dynamic_pointer_cast<TcpListener,
TcpBaseSocket>(shared_from_this());

TcpServerSideConnection::ConnectionAcceptedListenerCallback
listenerCallback =
        boost::bind(&TcpListener::OnConnectionAccepted, me, _1, _2);

TcpServerSideConnection::ConnectionAcceptedCallback
acceptCompleteCallback =
        boost::bind(&TcpServerSideConnection::OnConnectionAccepted,
newConnection, listenerCallback, boost::asio::placeholders::error);

acceptor_.async_accept(newConnection->GetSocket(),
acceptCompleteCallback);

Gives me a compile error in bind.hpp with 100s of pages.

What am I doing wrong here?
Does anyone have an example of a callback that callsback using
boost::bind?


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net