
Hi, --- christopher baus <christopher@baus.net> wrote:
I'm currently trying to port an app from libevent to asio to test out the library. I have a quick question. Why doesn't the basic_stream_socket::async_connect handler pass a pointer to the socket? Is it assumed that the handler is a stateful functor and keeps a pointer to the socket?
The intention is that you use boost::bind to create the appropriate function object: void connect_handler(const boost::asio::error& error, boost::asio::stream_socket* socket) { if (!error) { s->async_read_some(...); } } int main() { boost::asio::stream_socket* socket = ...; ... socket->async_connect(endpoint, boost::bind(connect_handler, _1, socket) ... // Or if you don't want to remember the index of the // arguments: // socket->async_connect(endpoint, // boost::bind(connect_handler, // boost::asio::placeholders::error, socket)); } Cheers, Chris