@@ -40,11 +40,13 @@ namespace SimpleWeb {
4040 // boost::asio::ssl::stream constructor needs move, until then we store socket as unique_ptr
4141 std::unique_ptr<socket_type> socket;
4242
43+ boost::asio::strand strand;
44+
4345 std::atomic<bool > closed;
4446
4547 std::unique_ptr<boost::asio::deadline_timer> timer_idle;
4648
47- Connection (socket_type* socket_ptr ): socket(socket_ptr ), closed(false ) {}
49+ Connection (socket_type *socket ): socket(socket), strand(socket-> get_io_service () ), closed(false ) {}
4850
4951 void read_remote_endpoint_data () {
5052 try {
@@ -179,7 +181,7 @@ namespace SimpleWeb {
179181 else
180182 stream.put (length);
181183
182- boost::asio::spawn (asio_strand , [this , connection, buffer, send_stream, callback](boost::asio::yield_context yield) {
184+ boost::asio::spawn (connection-> strand , [this , connection, buffer, send_stream, callback](boost::asio::yield_context yield) {
183185 // Need to copy the callback-function in case its destroyed
184186 boost::system::error_code ec;
185187 boost::asio::async_write (*connection->socket , *buffer, yield[ec]);
@@ -234,15 +236,15 @@ namespace SimpleWeb {
234236 boost::asio::io_service asio_io_service;
235237 boost::asio::ip::tcp::endpoint asio_endpoint;
236238 boost::asio::ip::tcp::acceptor asio_acceptor;
237- boost::asio::strand asio_strand;
239+
238240 size_t num_threads;
239241 std::vector<std::thread> threads;
240242
241243 size_t timeout_request;
242244 size_t timeout_idle;
243245
244246 SocketServerBase (unsigned short port, size_t num_threads, size_t timeout_request, size_t timeout_idle) :
245- asio_endpoint (boost::asio::ip::tcp::v4(), port), asio_acceptor(asio_io_service, asio_endpoint), asio_strand(asio_io_service),
247+ asio_endpoint(boost::asio::ip::tcp::v4(), port), asio_acceptor(asio_io_service, asio_endpoint),
246248 num_threads(num_threads), timeout_request(timeout_request), timeout_idle(timeout_idle) {}
247249
248250 virtual void accept ()=0;
0 commit comments