1
0

Socket-related assert fixes

git-svn-id: http://mc-server.googlecode.com/svn/trunk@227 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-02-02 16:13:49 +00:00
parent d43a81bae0
commit dca87cd214
3 changed files with 30 additions and 6 deletions

View File

@ -35,7 +35,7 @@ cBlockingTCPLink::~cBlockingTCPLink()
void cBlockingTCPLink::CloseSocket() void cBlockingTCPLink::CloseSocket()
{ {
if (m_Socket.IsValid()) if (!m_Socket.IsValid())
{ {
m_Socket.CloseSocket(); m_Socket.CloseSocket();
} }

View File

@ -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() void cSocket::CloseSocket()
{ {
#ifdef _WIN32 #ifdef _WIN32
closesocket(m_Socket); closesocket(m_Socket);
#else
#else // _WIN32
if( shutdown(m_Socket, SHUT_RDWR) != 0 )//SD_BOTH); if( shutdown(m_Socket, SHUT_RDWR) != 0 )//SD_BOTH);
{
LOGWARN("Error on shutting down socket (%s)", m_IPString.c_str() ); LOGWARN("Error on shutting down socket (%s)", m_IPString.c_str() );
}
if( close(m_Socket) != 0 ) if( close(m_Socket) != 0 )
{
LOGWARN("Error closing socket (%s)", m_IPString.c_str() ); 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;
} }

View File

@ -10,7 +10,7 @@ class cSocket
typedef SOCKET xSocket; typedef SOCKET xSocket;
#else #else
typedef int xSocket; typedef int xSocket;
static const int INVALID_SOCKET = 0; static const int INVALID_SOCKET = -1;
#endif #endif
public: public:
@ -18,7 +18,7 @@ public:
cSocket(xSocket a_Socket); cSocket(xSocket a_Socket);
~cSocket(); ~cSocket();
bool IsValid(void) const {return (m_Socket != INVALID_SOCKET); } bool IsValid(void) const;
void CloseSocket(); void CloseSocket();
operator const xSocket() const; operator const xSocket() const;