diff options
author | George Hazan <ghazan@miranda.im> | 2017-01-24 17:53:15 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2017-01-24 17:53:15 +0300 |
commit | 9b01c1c027483714bf0ec11af8f74a929e98d67f (patch) | |
tree | 5c303e0be81c9e31aabeb0e37b37a979db88ffba /src | |
parent | bd851fd5cf386d4c8614c3ad114d2aaf2fcf45b5 (diff) |
NetlibBoundPort destructor: code cleaning
Diffstat (limited to 'src')
-rw-r--r-- | src/mir_app/src/netlib.cpp | 9 | ||||
-rw-r--r-- | src/mir_app/src/netlib.h | 6 | ||||
-rw-r--r-- | src/mir_app/src/netlibbind.cpp | 15 |
3 files changed, 20 insertions, 10 deletions
diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp index d9531f8156..dc67a7f990 100644 --- a/src/mir_app/src/netlib.cpp +++ b/src/mir_app/src/netlib.cpp @@ -232,7 +232,8 @@ void NetlibDoCloseSocket(NetlibConnection *nlc, bool noShutdown) Netlib_Logf(nlc->nlu, "(%p:%u) Connection closed internal", nlc, nlc->s);
if (nlc->hSsl) {
- if (!noShutdown) sslApi.shutdown(nlc->hSsl);
+ if (!noShutdown)
+ sslApi.shutdown(nlc->hSsl);
sslApi.sfree(nlc->hSsl);
nlc->hSsl = NULL;
}
@@ -364,8 +365,8 @@ MIR_APP_DLL(void) Netlib_Shutdown(HNETLIBCONN h) NetlibConnection *nlc = h;
if (!nlc->termRequested) {
if (nlc->hSsl) sslApi.shutdown(nlc->hSsl);
- if (nlc->s != INVALID_SOCKET) shutdown(nlc->s, 2);
- if (nlc->s2 != INVALID_SOCKET) shutdown(nlc->s2, 2);
+ if (nlc->s != INVALID_SOCKET) shutdown(nlc->s, SD_BOTH);
+ if (nlc->s2 != INVALID_SOCKET) shutdown(nlc->s2, SD_BOTH);
nlc->termRequested = true;
}
}
@@ -374,7 +375,7 @@ MIR_APP_DLL(void) Netlib_Shutdown(HNETLIBCONN h) case NLH_BOUNDPORT:
NetlibBoundPort *nlb = (NetlibBoundPort*)h;
if (nlb->s != INVALID_SOCKET)
- shutdown(nlb->s, 2);
+ shutdown(nlb->s, SD_BOTH);
break;
}
ReleaseMutex(hConnectionHeaderMutex);
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h index 140353d19d..0c0ed55d89 100644 --- a/src/mir_app/src/netlib.h +++ b/src/mir_app/src/netlib.h @@ -171,7 +171,11 @@ struct NetlibConnection : public MZeroedObject struct NetlibBoundPort : public MZeroedObject
{
NetlibBoundPort(HNETLIBUSER nlu, NETLIBBIND *nlb);
- ~NetlibBoundPort();
+ ~NetlibBoundPort() {
+ close();
+ }
+
+ void close();
int handleType;
SOCKET s;
diff --git a/src/mir_app/src/netlibbind.cpp b/src/mir_app/src/netlibbind.cpp index ad7c160bbe..840429ac1b 100644 --- a/src/mir_app/src/netlibbind.cpp +++ b/src/mir_app/src/netlibbind.cpp @@ -111,6 +111,7 @@ bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn) int NetlibFreeBoundPort(NetlibBoundPort *nlbp)
{
+ nlbp->close();
if (nlbp->hThread)
WaitForSingleObject(nlbp->hThread, INFINITE);
Netlib_Logf(nlbp->nlu, "(%u) Port %u closed for incoming connections", nlbp->s, nlbp->wPort);
@@ -297,10 +298,14 @@ NetlibBoundPort::NetlibBoundPort(HNETLIBUSER _nlu, NETLIBBIND *nlb) s6 = socket(PF_INET6, SOCK_STREAM, 0);
}
-NetlibBoundPort::~NetlibBoundPort()
+void NetlibBoundPort::close()
{
- if (s != INVALID_SOCKET)
- closesocket(s);
- if (s6 != INVALID_SOCKET)
- closesocket(s6);
+ if (s != INVALID_SOCKET) {
+ closesocket(s);
+ s = INVALID_SOCKET;
+ }
+ if (s6 != INVALID_SOCKET) {
+ closesocket(s6);
+ s6 = INVALID_SOCKET;
+ }
}
|