提交 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
// Passed by argument.
Listener* listener{ nullptr };
// Others.
bool closed{ false };
ConsumerSocket consumerSocket;
ProducerSocket producerSocket;
uint8_t* writeBuffer;
......
......@@ -89,6 +89,7 @@ namespace PayloadChannel
// Passed by argument.
Listener* listener{ nullptr };
// Others.
bool closed{ false };
ConsumerSocket consumerSocket;
ProducerSocket producerSocket;
PayloadChannel::Notification* ongoingNotification{ nullptr };
......
......@@ -34,12 +34,20 @@ namespace Channel
MS_TRACE_STD();
std::free(this->writeBuffer);
if (!this->closed)
Close();
}
void ChannelSocket::Close()
{
MS_TRACE_STD();
if (this->closed)
return;
this->closed = true;
this->consumerSocket.Close();
this->producerSocket.Close();
}
......@@ -55,7 +63,7 @@ namespace Channel
{
MS_TRACE_STD();
if (this->producerSocket.IsClosed())
if (this->closed)
return;
std::string message = jsonMessage.dump();
......@@ -74,7 +82,7 @@ namespace Channel
{
MS_TRACE_STD();
if (this->producerSocket.IsClosed())
if (this->closed)
return;
if (messageLen > NsPayloadMaxLen)
......
......@@ -36,12 +36,20 @@ namespace PayloadChannel
std::free(this->writeBuffer);
delete this->ongoingNotification;
if (!this->closed)
Close();
}
void PayloadChannelSocket::Close()
{
MS_TRACE_STD();
if (this->closed)
return;
this->closed = true;
this->consumerSocket.Close();
this->producerSocket.Close();
}
......@@ -57,7 +65,7 @@ namespace PayloadChannel
{
MS_TRACE();
if (this->producerSocket.IsClosed())
if (this->closed)
return;
std::string message = jsonMessage.dump();
......@@ -83,7 +91,7 @@ namespace PayloadChannel
{
MS_TRACE_STD();
if (this->consumerSocket.IsClosed())
if (this->closed)
return;
std::string message = jsonMessage.dump();
......
......@@ -40,10 +40,14 @@ extern "C" int run_worker(
// Initialize libuv stuff (we need it for the Channel).
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 };
// 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 };
try
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论