tcp::sockets non-copyable, and threads
I'm trying to design a basic server, and I figured now would be a good time to get familiar with what Boost has to offer. However, I've already encountered a difficulty: boost::asio::ip::tcp::sockets are non-copyable. Therefore, I cannot simply acceptor.accept(socket), and then spawn a boost::thread on an object that uses that socket! If I pass a reference or pointer the socket must remain in scope, so it will need to by dynamically allocated....which doesn't seem right to me. I figure I'm probably missing something fundamental on the way boost is intended to work. Anyone care to enlighten me?
On Wed, 22 Oct 2008 17:12:09 -0400
Lindley M French
I'm trying to design a basic server, and I figured now would be a good time to get familiar with what Boost has to offer. However, I've already encountered a difficulty: boost::asio::ip::tcp::sockets are non-copyable.
Therefore, I cannot simply acceptor.accept(socket), and then spawn a boost::thread on an object that uses that socket! If I pass a reference or pointer the socket must remain in scope, so it will need to by dynamically allocated....which doesn't seem right to me.
I figure I'm probably missing something fundamental on the way boost is intended to work. Anyone care to enlighten me? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi, Use a boost::shared_ptr. The shared_ptr takes care of releasing the memory, so you don't have to worry about that. Sven
Take a look at the asio examples - you'll find there some use-cases
and patterns that would be useful for you.
http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/examples.html
2008/10/22 Lindley M French
I'm trying to design a basic server, and I figured now would be a good time to get familiar with what Boost has to offer. However, I've already encountered a difficulty: boost::asio::ip::tcp::sockets are non-copyable.
Therefore, I cannot simply acceptor.accept(socket), and then spawn a boost::thread on an object that uses that socket! If I pass a reference or pointer the socket must remain in scope, so it will need to by dynamically allocated....which doesn't seem right to me.
I figure I'm probably missing something fundamental on the way boost is intended to work. Anyone care to enlighten me?
participants (3)
-
Igor R
-
Lindley M French
-
Sven Gaerner