Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Moved boost::asio::strand.
Browse files Browse the repository at this point in the history
  • Loading branch information
eidheim committed Sep 4, 2015
1 parent ddad7c9 commit 1289415
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions server_ws.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ namespace SimpleWeb {
//boost::asio::ssl::stream constructor needs move, until then we store socket as unique_ptr
std::unique_ptr<socket_type> socket;

boost::asio::strand strand;

std::atomic<bool> closed;

std::unique_ptr<boost::asio::deadline_timer> timer_idle;

Connection(socket_type* socket_ptr): socket(socket_ptr), closed(false) {}
Connection(socket_type *socket): socket(socket), strand(socket->get_io_service()), closed(false) {}

void read_remote_endpoint_data() {
try {
Expand Down Expand Up @@ -179,7 +181,7 @@ namespace SimpleWeb {
else
stream.put(length);

boost::asio::spawn(asio_strand, [this, connection, buffer, send_stream, callback](boost::asio::yield_context yield) {
boost::asio::spawn(connection->strand, [this, connection, buffer, send_stream, callback](boost::asio::yield_context yield) {
//Need to copy the callback-function in case its destroyed
boost::system::error_code ec;
boost::asio::async_write(*connection->socket, *buffer, yield[ec]);
Expand Down Expand Up @@ -234,15 +236,15 @@ namespace SimpleWeb {
boost::asio::io_service asio_io_service;
boost::asio::ip::tcp::endpoint asio_endpoint;
boost::asio::ip::tcp::acceptor asio_acceptor;
boost::asio::strand asio_strand;

size_t num_threads;
std::vector<std::thread> threads;

size_t timeout_request;
size_t timeout_idle;

SocketServerBase(unsigned short port, size_t num_threads, size_t timeout_request, size_t timeout_idle) :
asio_endpoint(boost::asio::ip::tcp::v4(), port), asio_acceptor(asio_io_service, asio_endpoint), asio_strand(asio_io_service),
asio_endpoint(boost::asio::ip::tcp::v4(), port), asio_acceptor(asio_io_service, asio_endpoint),
num_threads(num_threads), timeout_request(timeout_request), timeout_idle(timeout_idle) {}

virtual void accept()=0;
Expand Down

0 comments on commit 1289415

Please sign in to comment.