提交 85be87ac authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

ChannelSocket and PayloadChannelSocket: use closed flag as done in many other classes

上级 d6bb28ab
...@@ -80,6 +80,7 @@ namespace Channel ...@@ -80,6 +80,7 @@ namespace Channel
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
bool closed{ false };
ConsumerSocket consumerSocket; ConsumerSocket consumerSocket;
ProducerSocket producerSocket; ProducerSocket producerSocket;
uint8_t* writeBuffer; uint8_t* writeBuffer;
......
...@@ -89,6 +89,7 @@ namespace PayloadChannel ...@@ -89,6 +89,7 @@ namespace PayloadChannel
// Passed by argument. // Passed by argument.
Listener* listener{ nullptr }; Listener* listener{ nullptr };
// Others. // Others.
bool closed{ false };
ConsumerSocket consumerSocket; ConsumerSocket consumerSocket;
ProducerSocket producerSocket; ProducerSocket producerSocket;
PayloadChannel::Notification* ongoingNotification{ nullptr }; PayloadChannel::Notification* ongoingNotification{ nullptr };
......
...@@ -34,12 +34,20 @@ namespace Channel ...@@ -34,12 +34,20 @@ namespace Channel
MS_TRACE_STD(); MS_TRACE_STD();
std::free(this->writeBuffer); std::free(this->writeBuffer);
if (!this->closed)
Close();
} }
void ChannelSocket::Close() void ChannelSocket::Close()
{ {
MS_TRACE_STD(); MS_TRACE_STD();
if (this->closed)
return;
this->closed = true;
this->consumerSocket.Close(); this->consumerSocket.Close();
this->producerSocket.Close(); this->producerSocket.Close();
} }
...@@ -55,7 +63,7 @@ namespace Channel ...@@ -55,7 +63,7 @@ namespace Channel
{ {
MS_TRACE_STD(); MS_TRACE_STD();
if (this->producerSocket.IsClosed()) if (this->closed)
return; return;
std::string message = jsonMessage.dump(); std::string message = jsonMessage.dump();
...@@ -74,7 +82,7 @@ namespace Channel ...@@ -74,7 +82,7 @@ namespace Channel
{ {
MS_TRACE_STD(); MS_TRACE_STD();
if (this->producerSocket.IsClosed()) if (this->closed)
return; return;
if (messageLen > NsPayloadMaxLen) if (messageLen > NsPayloadMaxLen)
......
...@@ -36,12 +36,20 @@ namespace PayloadChannel ...@@ -36,12 +36,20 @@ namespace PayloadChannel
std::free(this->writeBuffer); std::free(this->writeBuffer);
delete this->ongoingNotification; delete this->ongoingNotification;
if (!this->closed)
Close();
} }
void PayloadChannelSocket::Close() void PayloadChannelSocket::Close()
{ {
MS_TRACE_STD(); MS_TRACE_STD();
if (this->closed)
return;
this->closed = true;
this->consumerSocket.Close(); this->consumerSocket.Close();
this->producerSocket.Close(); this->producerSocket.Close();
} }
...@@ -57,7 +65,7 @@ namespace PayloadChannel ...@@ -57,7 +65,7 @@ namespace PayloadChannel
{ {
MS_TRACE(); MS_TRACE();
if (this->producerSocket.IsClosed()) if (this->closed)
return; return;
std::string message = jsonMessage.dump(); std::string message = jsonMessage.dump();
...@@ -83,7 +91,7 @@ namespace PayloadChannel ...@@ -83,7 +91,7 @@ namespace PayloadChannel
{ {
MS_TRACE_STD(); MS_TRACE_STD();
if (this->consumerSocket.IsClosed()) if (this->closed)
return; return;
std::string message = jsonMessage.dump(); std::string message = jsonMessage.dump();
......
...@@ -40,10 +40,14 @@ extern "C" int run_worker( ...@@ -40,10 +40,14 @@ extern "C" int run_worker(
// Initialize libuv stuff (we need it for the Channel). // Initialize libuv stuff (we need it for the Channel).
DepLibUV::ClassInit(); DepLibUV::ClassInit();
// Channel socket. // Channel socket. If Worker instance runs properly, this socket is closed by
// it in its destructor. Otherwise it's closed here by also letting libuv
// deallocate its UV handles.
std::unique_ptr<Channel::ChannelSocket> channel{ nullptr }; std::unique_ptr<Channel::ChannelSocket> channel{ nullptr };
// PayloadChannel socket. // PayloadChannel socket. If Worker instance runs properly, this socket is
// closed by it in its destructor. Otherwise it's closed here by also letting
// libuv deallocate its UV handles.
std::unique_ptr<PayloadChannel::PayloadChannelSocket> payloadChannel{ nullptr }; std::unique_ptr<PayloadChannel::PayloadChannelSocket> payloadChannel{ nullptr };
try try
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论