Boost logo

Boost Users :

Subject: [Boost-users] asio: tcp::iostream::async_connect with specific io_service instance
From: Walther Zwart (walther.zwart_at_[hidden])
Date: 2010-06-22 17:12:43


I have a question about boost asio iostreams. I'm trying to create a server
and
client with tcp::iostreams that use async_connect and async_accept and use a
specific
tcp::io_service instance. My code currently looks somewhat like this.

Server:
------------
io_service my_service;
tcp::endpoint my_endpoint;
...
...
tcp::acceptor my_acceptor(my_service, my_endpoint);
tcp::iostream my_stream;
my_acceptor.async_accept(my_stream.rdbuf(),
                         boost::bind(connectedHandler,
placeholders::error));
------------
This works the way I want to. Another thread calls run on the io_service and
thus makes sure the accept is handled.

Client:
------------
io_service my_service;
tcp::endpoint my_endpoint;
...
...
tcp::iostream my_stream;
my_stream.rdbuf()->async_connect(my_endpoint,
                                 boost::bind(connectedHandler,
placeholders::error));
------------
This doesn't work with my io_service. I don't see a way to tell the
tcp::iostream or the underlying basic_socket_streambuf which io_service to
use.
This means I have to call run on a new io_service every time I connect to a
socket somewhere, right? Is there a way to do an async_connect with your own
service?

regards,
Walther



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