Secondary server listener is now closed (in editor it was still open)

This commit is contained in:
bernatx 2022-07-25 09:00:39 +02:00 committed by bernat
parent 3083c8e2ed
commit 3335c75c38
6 changed files with 35 additions and 12 deletions

View File

@ -24,10 +24,15 @@ namespace multigpu {
}
Listener::~Listener() {
Stop();
}
void Listener::Stop() {
_acceptor.cancel();
_acceptor.close();
// _acceptor.get_io_service().stop();
_io_context.stop();
_io_context.reset();
}
void Listener::OpenSession(
@ -40,14 +45,20 @@ namespace multigpu {
auto session = std::make_shared<Primary>(_io_context, timeout, *this);
auto self = shared_from_this();
_acceptor.async_accept(session->_socket, [=](error_code ec) {
if (!ec) {
session->Open(on_opened, on_closed, on_response);
} else {
log_error("tcp accept error:", ec.message());
}
auto handle_query = [on_opened, on_closed, on_response, session](const error_code &ec) {
if (!ec) {
session->Open(std::move(on_opened), std::move(on_closed), , std::move(on_response));
} else {
self->_acceptor.get_io_service().stop();
log_error("tcp accept secondary error:", ec.message());
}
};
self->OpenSession(timeout, on_opened, on_closed, on_response);
_acceptor.async_accept(session->_socket, [=](error_code ec) {
// Handle query and open a new session immediately.
boost::asio::post(_io_context, [=]() { handle_query(ec); });
OpenSession(timeout, on_opened, on_closed, on_response);
});
}

View File

@ -16,8 +16,13 @@ Router::Router(void) :
_next(0) { }
Router::~Router() {
Stop();
}
void Router::Stop() {
ClearSessions();
_listener->Stop();
_listener.reset();
_pool.Stop();
}

View File

@ -38,9 +38,10 @@ namespace multigpu {
Router(void);
explicit Router(uint16_t port);
~Router();
void Write(MultiGPUCommand id, Buffer &&buffer);
std::future<SessionInfo> WriteToNext(MultiGPUCommand id, Buffer &&buffer);
void Stop();
void SetCallbacks();
void AsyncRun(size_t worker_threads);

View File

@ -35,7 +35,7 @@ namespace tcp {
if (!ec) {
session->Open(std::move(on_opened), std::move(on_closed));
} else {
log_error("tcp accept error:", ec.message());
log_error("tcp accept stream error:", ec.message());
}
};

View File

@ -52,6 +52,7 @@ public:
bool AreClientsListening()
{
check(Stream.has_value());
return Stream ? Stream->AreClientsListening() : false;
}

View File

@ -2310,7 +2310,9 @@ void FCarlaServer::FPimpl::BindActions()
FCarlaServer::FCarlaServer() : Pimpl(nullptr) {}
FCarlaServer::~FCarlaServer() {}
FCarlaServer::~FCarlaServer() {
Stop();
}
FDataMultiStream FCarlaServer::Start(uint16_t RPCPort, uint16_t StreamingPort, uint16_t SecondaryPort)
{
@ -2395,8 +2397,11 @@ bool FCarlaServer::TickCueReceived()
void FCarlaServer::Stop()
{
check(Pimpl != nullptr);
Pimpl->Server.Stop();
if (Pimpl)
{
Pimpl->Server.Stop();
Pimpl->SecondaryServer->Stop();
}
}
FDataStream FCarlaServer::OpenStream() const