Преглед на файлове

Added destructor code to avoid throwing exceptions while cleaning up any sockets. Destructors should not throw exceptions and socket handles should always be closed even if no connections were made.

git-svn-id: https://svn.microneil.com/svn/CodeDweller/trunk@23 d34b734f-a00e-4b39-a726-e4eeb87269ab
wx
madscientist преди 12 години
родител
ревизия
27a67ba88f
променени са 1 файла, в които са добавени 7 реда и са изтрити 5 реда
  1. 7
    5
      networking.inline.hpp

+ 7
- 5
networking.inline.hpp Целия файл

@@ -216,7 +216,9 @@ inline Socket::Socket() :
}

inline Socket::~Socket() { // When shutting down, be sure
if(isOpen()) close(); // any open socket is closed.
if(INVALID_SOCKET != Handle) { // any open socket is closed without
Network.closeSocket(Handle); // throwing any exceptions.
}
}

inline void Socket::close() { // When we close,
@@ -283,7 +285,7 @@ inline TCPClient::TCPClient(TCPListener& L, hSocket H, SocketAddress& A) :
}

inline TCPClient::~TCPClient() { // When destroying a TCPClient
if(isOpen()) close(); // Close when being destroyed.
try{ if(isOpen()) close(); } catch(...) {} // silently close any open connections.
}

inline void TCPClient::open() { // We provide open() as unsupported.
@@ -337,7 +339,7 @@ inline const char* TCPClient::getRemotePort(char* str) {
//// class TCPHost /////////////////////////////////////////////////////////////

inline TCPHost::~TCPHost() { // When destroying a TCPHost
if(isOpen()) close(); // Close when being destroyed.
try{ if(isOpen()) close(); } catch(...) {} // silently close any open connection.
}

inline bool TCPHost::ReadBufferIsEmpty() { // True if the ReadBuffer is empty.
@@ -368,6 +370,6 @@ inline bool TCPHost::isNonBlocking() {

//// class TCPListener /////////////////////////////////////////////////////////

inline TCPListener::~TCPListener() { // Close when deleting.
close();
inline TCPListener::~TCPListener() { // When destroying a TCPListener
try{ close(); } catch(...) {} // silently close if not already done.
}

Loading…
Отказ
Запис