diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-02 17:13:49 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-02-02 17:13:49 +0100 |
commit | dca87cd2145d51ffca4212c2ab47a44c20c2ad26 (patch) | |
tree | 459c94748d4cb94bfa0ad948eb1d8783b9a747b5 /source | |
parent | WebServer: socket fix (force-terminated socket would cause the server to loop indefinitely) (diff) | |
download | cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar.gz cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar.bz2 cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar.lz cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar.xz cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.tar.zst cuberite-dca87cd2145d51ffca4212c2ab47a44c20c2ad26.zip |
Diffstat (limited to '')
-rw-r--r-- | source/cBlockingTCPLink.cpp | 2 | ||||
-rw-r--r-- | source/cSocket.cpp | 30 | ||||
-rw-r--r-- | source/cSocket.h | 4 |
3 files changed, 30 insertions, 6 deletions
diff --git a/source/cBlockingTCPLink.cpp b/source/cBlockingTCPLink.cpp index 9705f3a84..1145e0e56 100644 --- a/source/cBlockingTCPLink.cpp +++ b/source/cBlockingTCPLink.cpp @@ -35,7 +35,7 @@ cBlockingTCPLink::~cBlockingTCPLink() void cBlockingTCPLink::CloseSocket()
{
- if (m_Socket.IsValid())
+ if (!m_Socket.IsValid())
{
m_Socket.CloseSocket();
}
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;
}
diff --git a/source/cSocket.h b/source/cSocket.h index 395815389..5f373edac 100644 --- a/source/cSocket.h +++ b/source/cSocket.h @@ -10,7 +10,7 @@ class cSocket typedef SOCKET xSocket;
#else
typedef int xSocket;
- static const int INVALID_SOCKET = 0;
+ static const int INVALID_SOCKET = -1;
#endif
public:
@@ -18,7 +18,7 @@ public: cSocket(xSocket a_Socket);
~cSocket();
- bool IsValid(void) const {return (m_Socket != INVALID_SOCKET); }
+ bool IsValid(void) const;
void CloseSocket();
operator const xSocket() const;
|