[Boost.Asio] asio objects: initializing after construction

Hi! Lets assume I have some kind of map : map<int, boost::asio::ip::tcp::acceptor> my_acceptors; AND map<int, boost::asio::ip::tcp::socket> my_sockets; I want to extend the maps with new objects, so what is the right way to (?): my_acceptors[someport_int].initialize(_my_ioservice,_my_endpoint); my_acceptors[another_int].initialize(_my_ioservice); I use such code, but not sure it is right: { // initialize new acceptor ip::tcp::endpoint _my_endpoint(ip::tcp::v4(),port); ip::tcp::acceptor _acc(_my_ioservice,_my_endpoint); my_acceptors[someport_int] = _acc; // initialize new socket ip::tcp::socket _thesock(_my_ioservice); my_sockets[another_int] = _thesock; // asycc_accept my_acceptors[someport_int].async_accept(my_sockets[new_neighbour_id],boost::bind(do_AsyncAcceptHandler,this,new_neighbour_id)); } Thanks!

std::map<key, value> expects value to be assignable, while most of asio objects are non-copyable. Consider using a container of [smart] pointers.
I want to extend the maps with new objects, so what is the right way to (?):
my_acceptors[someport_int].initialize(_my_ioservice,_my_endpoint); my_acceptors[another_int].initialize(_my_ioservice);

On Sat, 11 Oct 2008 12:11:42 +0200, Roman Shmelev <rshmelev@gmail.com> wrote:
Hi! Lets assume I have some kind of map :
map<int, boost::asio::ip::tcp::acceptor> my_acceptors; AND map<int, boost::asio::ip::tcp::socket> my_sockets;
I want to extend the maps with new objects, so what is the right way to (?):
my_acceptors[someport_int].initialize(_my_ioservice,_my_endpoint); my_acceptors[another_int].initialize(_my_ioservice);
I had a similar question as I wondered how to pass a reference to an io_service to an I/O object after is has been created (see http://article.gmane.org/gmane.comp.lib.boost.devel/180720). As far as I see there is no way to do this (no recommendation or guideline in Boost.Asio either as all I/O objects always seem to be initialized with an io_service). Boris

http://article.gmane.org/gmane.comp.lib.boost.devel/180720). As far as I see there is no way to do this + Consider using a container of [smart] pointers. = Thanks for reply! I decided to use simple pointers).. So sad there is no better and ergonomic solution.
participants (3)
-
Boris
-
Igor R
-
Roman Shmelev