summaryrefslogtreecommitdiffstats
path: root/src/OSSupport
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-12-06 18:41:48 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-12-06 18:41:48 +0100
commit3acdf25b058bceef3005eead6e909c27c7a9e4a8 (patch)
tree38c40774061bd44b3452091092a018c53459907b /src/OSSupport
parentTools: Removed unused Timer.* file from CMakeLists.txt. (diff)
parentMerge pull request #1647 from mc-server/SocketThreadsFix (diff)
downloadcuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar.gz
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar.bz2
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar.lz
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar.xz
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.tar.zst
cuberite-3acdf25b058bceef3005eead6e909c27c7a9e4a8.zip
Diffstat (limited to 'src/OSSupport')
-rw-r--r--src/OSSupport/Socket.h2
-rw-r--r--src/OSSupport/SocketThreads.cpp14
2 files changed, 12 insertions, 4 deletions
diff --git a/src/OSSupport/Socket.h b/src/OSSupport/Socket.h
index e4ec895cb..9ec8c1111 100644
--- a/src/OSSupport/Socket.h
+++ b/src/OSSupport/Socket.h
@@ -74,7 +74,7 @@ public:
inline static bool IsSocketError(int a_ReturnedValue)
{
#ifdef _WIN32
- return (a_ReturnedValue == SOCKET_ERROR || a_ReturnedValue == 0);
+ return ((a_ReturnedValue == SOCKET_ERROR) || (a_ReturnedValue == 0));
#else
return (a_ReturnedValue <= 0);
#endif
diff --git a/src/OSSupport/SocketThreads.cpp b/src/OSSupport/SocketThreads.cpp
index 7a3ef4274..153d6ed1d 100644
--- a/src/OSSupport/SocketThreads.cpp
+++ b/src/OSSupport/SocketThreads.cpp
@@ -86,7 +86,8 @@ void cSocketThreads::RemoveClient(const cCallback * a_Client)
}
} // for itr - m_Threads[]
- ASSERT(!"Removing an unknown client");
+ // This client wasn't found.
+ // It's not an error, because it may have been removed by a different thread in the meantime.
}
@@ -491,10 +492,17 @@ void cSocketThreads::cSocketThread::ReadFromSockets(fd_set * a_Read)
{
case sSlot::ssNormal:
{
- // Notify the callback that the remote has closed the socket; keep the slot
- m_Slots[i].m_Client->SocketClosed();
+ // Close the socket on our side:
m_Slots[i].m_State = sSlot::ssRemoteClosed;
m_Slots[i].m_Socket.CloseSocket();
+
+ // Notify the callback that the remote has closed the socket, *after* removing the socket:
+ cCallback * client = m_Slots[i].m_Client;
+ m_Slots[i] = m_Slots[--m_NumSlots];
+ if (client != nullptr)
+ {
+ client->SocketClosed();
+ }
break;
}
case sSlot::ssWritingRestOut: