From dca87cd2145d51ffca4212c2ab47a44c20c2ad26 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 2 Feb 2012 16:13:49 +0000 Subject: Socket-related assert fixes git-svn-id: http://mc-server.googlecode.com/svn/trunk@227 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cSocket.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source/cSocket.cpp') diff --git a/source/cSocket.cpp b/source/cSocket.cpp index 0945d170e..e90569f11 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -52,16 +52,40 @@ cSocket::xSocket cSocket::GetSocket() const +bool cSocket::IsValid(void) const +{ + #ifdef _WIN32 + return (m_Socket != INVALID_SOCKET); + #else // _WIN32 + return (m_Socket >= 0); + #endif // else _WIN32 +} + + + + + void cSocket::CloseSocket() { -#ifdef _WIN32 + #ifdef _WIN32 + closesocket(m_Socket); -#else + + #else // _WIN32 + if( shutdown(m_Socket, SHUT_RDWR) != 0 )//SD_BOTH); + { LOGWARN("Error on shutting down socket (%s)", m_IPString.c_str() ); + } if( close(m_Socket) != 0 ) + { LOGWARN("Error closing socket (%s)", m_IPString.c_str() ); -#endif + } + + #endif // else _WIN32 + + // Invalidate the socket so that this object can be re-used for another connection + m_Socket = INVALID_SOCKET; } -- cgit v1.2.3