summaryrefslogtreecommitdiffstats
path: root/src/OSSupport/ServerHandleImpl.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-01-23 23:01:18 +0100
committerMattes D <github@xoft.cz>2015-01-23 23:01:18 +0100
commit10cfa61fbc5d0720f4e4864f50f1298937327348 (patch)
treef0763471ac50f70ad7807309255154bdff806eb8 /src/OSSupport/ServerHandleImpl.cpp
parentcNetwork: Renamed callback to OnConnected() (diff)
downloadcuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar.gz
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar.bz2
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar.lz
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar.xz
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.tar.zst
cuberite-10cfa61fbc5d0720f4e4864f50f1298937327348.zip
Diffstat (limited to 'src/OSSupport/ServerHandleImpl.cpp')
-rw-r--r--src/OSSupport/ServerHandleImpl.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/OSSupport/ServerHandleImpl.cpp b/src/OSSupport/ServerHandleImpl.cpp
index 026c0fdc1..ba38dbf2e 100644
--- a/src/OSSupport/ServerHandleImpl.cpp
+++ b/src/OSSupport/ServerHandleImpl.cpp
@@ -80,6 +80,9 @@ void cServerHandleImpl::Close(void)
{
conn->Shutdown();
}
+
+ // Remove the ptr to self, so that the object may be freed:
+ m_SelfPtr.reset();
}
@@ -92,6 +95,7 @@ cServerHandleImplPtr cServerHandleImpl::Listen(
)
{
cServerHandleImplPtr res = cServerHandleImplPtr{new cServerHandleImpl(a_ListenCallbacks)};
+ res->m_SelfPtr = res;
if (res->Listen(a_Port))
{
cNetworkSingleton::Get().AddServer(res);
@@ -99,6 +103,7 @@ cServerHandleImplPtr cServerHandleImpl::Listen(
else
{
a_ListenCallbacks->OnError(res->m_ErrorCode, res->m_ErrorMsg);
+ res->m_SelfPtr.reset();
}
return res;
}
@@ -247,6 +252,7 @@ void cServerHandleImpl::Callback(evconnlistener * a_Listener, evutil_socket_t a_
// Cast to true self:
cServerHandleImpl * Self = reinterpret_cast<cServerHandleImpl *>(a_Self);
ASSERT(Self != nullptr);
+ ASSERT(Self->m_SelfPtr != nullptr);
// Get the textual IP address and port number out of a_Addr:
char IPAddress[128];
@@ -278,13 +284,13 @@ void cServerHandleImpl::Callback(evconnlistener * a_Listener, evutil_socket_t a_
}
// Create a new cTCPLink for the incoming connection:
- cTCPLinkImplPtr Link = std::make_shared<cTCPLinkImpl>(a_Socket, LinkCallbacks, Self, a_Addr, static_cast<socklen_t>(a_Len));
+ cTCPLinkImplPtr Link = std::make_shared<cTCPLinkImpl>(a_Socket, LinkCallbacks, Self->m_SelfPtr, a_Addr, static_cast<socklen_t>(a_Len));
{
cCSLock Lock(Self->m_CS);
Self->m_Connections.push_back(Link);
} // Lock(m_CS)
LinkCallbacks->OnLinkCreated(Link);
- Link->Enable();
+ Link->Enable(Link);
// Call the OnAccepted callback:
Self->m_ListenCallbacks->OnAccepted(*Link);