Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.

Commit c7bcb9f

Browse files
committedDec 6, 2018
Ensure a single io_strand for the whole API stack
1 parent 419a515 commit c7bcb9f

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed
 

‎libapicore/ApiServer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ void ApiServer::begin_accept()
292292
if (!isRunning())
293293
return;
294294

295-
auto session = std::make_shared<ApiConnection>(++lastSessionId, m_readonly, m_password);
295+
auto session = std::make_shared<ApiConnection>(m_io_strand, ++lastSessionId, m_readonly, m_password);
296296
m_acceptor.async_accept(
297297
session->socket(), m_io_strand.wrap(boost::bind(&ApiServer::handle_accept, this, session,
298298
boost::asio::placeholders::error)));
@@ -349,10 +349,11 @@ void ApiConnection::disconnect()
349349
}
350350
}
351351

352-
ApiConnection::ApiConnection(int id, bool readonly, string password)
352+
ApiConnection::ApiConnection(
353+
boost::asio::io_service::strand& _strand, int id, bool readonly, string password)
353354
: m_sessionId(id),
354355
m_socket(g_io_service),
355-
m_io_strand(g_io_service),
356+
m_io_strand(_strand),
356357
m_readonly(readonly),
357358
m_password(std::move(password))
358359
{

‎libapicore/ApiServer.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ApiConnection
2222
{
2323
public:
2424

25-
ApiConnection(int id, bool readonly, string password);
25+
ApiConnection(boost::asio::io_service::strand& _strand, int id, bool readonly, string password);
2626

2727
~ApiConnection() = default;
2828

@@ -57,7 +57,7 @@ class ApiConnection
5757
int m_sessionId;
5858

5959
tcp::socket m_socket;
60-
boost::asio::io_service::strand m_io_strand;
60+
boost::asio::io_service::strand& m_io_strand;
6161
boost::asio::streambuf m_sendBuffer;
6262
boost::asio::streambuf m_recvBuffer;
6363
Json::StreamWriterBuilder m_jSwBuilder;

0 commit comments

Comments
 (0)
This repository has been archived.