summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/TCPLinkImpl.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2016-08-20 14:34:29 +0200
commit7175b9e435a54cff33914d21384625a445cc5cf0 (patch)
tree7feb44f1e8e4ed7ea4d5bf0ba1d173abd3417f34 /src/OSSupport/TCPLinkImpl.cpp
parentAdded cWorld:SetSpawn() API and Lua binding (#3316) (diff)
downloadcuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.gz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.bz2
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.lz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.xz
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.tar.zst
cuberite-7175b9e435a54cff33914d21384625a445cc5cf0.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/TCPLinkImpl.cpp28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/OSSupport/TCPLinkImpl.cpp b/src/OSSupport/TCPLinkImpl.cpp
index b15b6282f..0432ca973 100644
--- a/src/OSSupport/TCPLinkImpl.cpp
+++ b/src/OSSupport/TCPLinkImpl.cpp
@@ -88,8 +88,9 @@ cTCPLinkImplPtr cTCPLinkImpl::Connect(const AString & a_Host, UInt16 a_Port, cTC
// Success
return res;
}
+
// Failure
- cNetworkSingleton::Get().RemoveLink(res.get());
+ res->Close();
return nullptr;
}
@@ -99,8 +100,9 @@ cTCPLinkImplPtr cTCPLinkImpl::Connect(const AString & a_Host, UInt16 a_Port, cTC
// Success
return res;
}
+
// Failure
- cNetworkSingleton::Get().RemoveLink(res.get());
+ res->Close();
return nullptr;
}
@@ -214,6 +216,7 @@ void cTCPLinkImpl::EventCallback(bufferevent * a_BufferEvent, short a_What, void
{
ASSERT(a_Self != nullptr);
cTCPLinkImplPtr Self = static_cast<cTCPLinkImpl *>(a_Self)->m_Self;
+ ASSERT(Self != nullptr);
// If an error is reported, call the error callback:
if (a_What & BEV_EVENT_ERROR)
@@ -232,16 +235,9 @@ void cTCPLinkImpl::EventCallback(bufferevent * a_BufferEvent, short a_What, void
else
{
Self->m_Callbacks->OnError(err, evutil_socket_error_to_string(err));
- if (Self->m_Server == nullptr)
- {
- cNetworkSingleton::Get().RemoveLink(Self.get());
- }
- else
- {
- Self->m_Server->RemoveLink(Self.get());
- }
}
- Self->m_Self.reset();
+
+ Self->Close();
return;
}
@@ -263,15 +259,7 @@ void cTCPLinkImpl::EventCallback(bufferevent * a_BufferEvent, short a_What, void
if (a_What & BEV_EVENT_EOF)
{
Self->m_Callbacks->OnRemoteClosed();
- if (Self->m_Server != nullptr)
- {
- Self->m_Server->RemoveLink(Self.get());
- }
- else
- {
- cNetworkSingleton::Get().RemoveLink(Self.get());
- }
- Self->m_Self.reset();
+ Self->Close();
return;
}