diff options
author | George Hazan <ghazan@miranda.im> | 2022-05-11 12:40:31 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-05-11 12:40:31 +0300 |
commit | 84311b23f36c084723e8f42af60fc2c77d4d9a54 (patch) | |
tree | b1144daf11bab6235f904031ce6d85ba8476c546 | |
parent | ad9b7e867404e4c2d14153a2d5c63007338101e4 (diff) |
old Windows-dependent code removed
-rw-r--r-- | src/mir_app/src/netlib.cpp | 99 | ||||
-rw-r--r-- | src/mir_app/src/netlib.h | 6 | ||||
-rw-r--r-- | src/mir_app/src/netlib_log.cpp | 15 | ||||
-rw-r--r-- | src/mir_app/src/netlib_openconn.cpp | 1 | ||||
-rw-r--r-- | src/mir_app/src/netlib_sock.cpp | 38 |
5 files changed, 76 insertions, 83 deletions
diff --git a/src/mir_app/src/netlib.cpp b/src/mir_app/src/netlib.cpp index 12ca034ab8..68c2d6e3d0 100644 --- a/src/mir_app/src/netlib.cpp +++ b/src/mir_app/src/netlib.cpp @@ -27,7 +27,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static BOOL bModuleInitialized = FALSE;
-HANDLE hConnectionHeaderMutex, hConnectionOpenMutex, hEventConnected = NULL, hEventDisconnected = NULL;
+mir_cs csConnectionHeader;
+HANDLE hConnectionOpenMutex, hEventConnected = NULL, hEventDisconnected = NULL;
uint32_t g_LastConnectionTick;
int connectionTimeout;
HANDLE hSendEvent = nullptr, hRecvEvent = nullptr;
@@ -79,22 +80,22 @@ int NetlibEnterNestedCS(NetlibConnection *nlc, int which) {
NetlibNestedCriticalSection *nlncs;
uint32_t dwCurrentThreadId = GetCurrentThreadId();
+ {
+ mir_cslock lock(csConnectionHeader);
- WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
- if (nlc == nullptr || nlc->handleType != NLH_CONNECTION) {
- ReleaseMutex(hConnectionHeaderMutex);
- SetLastError(ERROR_INVALID_PARAMETER);
- return 0;
- }
- nlncs = (which == NLNCS_SEND) ? &nlc->ncsSend : &nlc->ncsRecv;
- if (nlncs->lockCount && nlncs->dwOwningThreadId == dwCurrentThreadId) {
- nlncs->lockCount++;
- ReleaseMutex(hConnectionHeaderMutex);
- return 1;
+ if (nlc == nullptr || nlc->handleType != NLH_CONNECTION) {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+ nlncs = (which == NLNCS_SEND) ? &nlc->ncsSend : &nlc->ncsRecv;
+ if (nlncs->lockCount && nlncs->dwOwningThreadId == dwCurrentThreadId) {
+ nlncs->lockCount++;
+ return 1;
+ }
+ InterlockedIncrement(&nlc->dontCloseNow);
+ ResetEvent(nlc->hOkToCloseEvent);
}
- InterlockedIncrement(&nlc->dontCloseNow);
- ResetEvent(nlc->hOkToCloseEvent);
- ReleaseMutex(hConnectionHeaderMutex);
+
WaitForSingleObject(nlncs->hMutex, INFINITE);
nlncs->dwOwningThreadId = dwCurrentThreadId;
nlncs->lockCount = 1;
@@ -285,25 +286,26 @@ MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib) switch (GetNetlibHandleType(hNetlib)) {
case NLH_USER:
- {
- NetlibUser *nlu = (NetlibUser*)hNetlib;
{
- mir_cslock lck(csNetlibUser);
- int i = netlibUser.getIndex(nlu);
- if (i >= 0)
- netlibUser.remove(i);
- }
+ NetlibUser *nlu = (NetlibUser*)hNetlib;
+ {
+ mir_cslock lck(csNetlibUser);
+ int i = netlibUser.getIndex(nlu);
+ if (i >= 0)
+ netlibUser.remove(i);
+ }
- NetlibFreeUserSettingsStruct(&nlu->settings);
- mir_free(nlu->user.szSettingsModule);
- mir_free(nlu->user.szDescriptiveName.a);
- mir_free(nlu->szStickyHeaders);
- }
- break;
+ NetlibFreeUserSettingsStruct(&nlu->settings);
+ mir_free(nlu->user.szSettingsModule);
+ mir_free(nlu->user.szDescriptiveName.a);
+ mir_free(nlu->szStickyHeaders);
+ }
+ break;
case NLH_CONNECTION:
- WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
{
+ mir_cslockfull lock(csConnectionHeader);
+
NetlibConnection *nlc = (NetlibConnection*)hNetlib;
if (GetNetlibHandleType(nlc) == NLH_CONNECTION) {
if (nlc->s != INVALID_SOCKET)
@@ -312,12 +314,11 @@ MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib) closesocket(nlc->s2);
nlc->s2 = INVALID_SOCKET;
- ReleaseMutex(hConnectionHeaderMutex);
+ lock.unlock();
- HANDLE waitHandles[4] = { hConnectionHeaderMutex, nlc->hOkToCloseEvent, nlc->ncsRecv.hMutex, nlc->ncsSend.hMutex };
+ HANDLE waitHandles[] = { nlc->hOkToCloseEvent, nlc->ncsRecv.hMutex, nlc->ncsSend.hMutex };
uint32_t waitResult = WaitForMultipleObjects(_countof(waitHandles), waitHandles, TRUE, INFINITE);
if (waitResult >= WAIT_OBJECT_0 + _countof(waitHandles)) {
- ReleaseMutex(hConnectionHeaderMutex);
SetLastError(ERROR_INVALID_PARAMETER); //already been closed
return 0;
}
@@ -326,7 +327,6 @@ MIR_APP_DLL(int) Netlib_CloseHandle(HANDLE hNetlib) delete nlc;
}
}
- ReleaseMutex(hConnectionHeaderMutex);
return 1;
case NLH_BOUNDPORT:
@@ -357,7 +357,8 @@ MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HNETLIBCONN hConnection) SetLastError(ERROR_INVALID_PARAMETER);
}
else {
- WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
+ mir_cslock lock(csConnectionHeader);
+
switch (GetNetlibHandleType(hConnection)) {
case NLH_CONNECTION:
s = ((NetlibConnection*)hConnection)->s;
@@ -370,7 +371,6 @@ MIR_APP_DLL(UINT_PTR) Netlib_GetSocket(HNETLIBCONN hConnection) SetLastError(ERROR_INVALID_PARAMETER);
break;
}
- ReleaseMutex(hConnectionHeaderMutex);
}
return s;
}
@@ -396,10 +396,13 @@ MIR_APP_DLL(char*) Netlib_GetUserAgent() MIR_APP_DLL(void) Netlib_Shutdown(HNETLIBCONN h)
{
- if (h) {
- WaitForSingleObject(hConnectionHeaderMutex, INFINITE);
- switch (GetNetlibHandleType(h)) {
- case NLH_CONNECTION:
+ if (h == nullptr)
+ return;
+
+ mir_cslock lock(csConnectionHeader);
+
+ switch (GetNetlibHandleType(h)) {
+ case NLH_CONNECTION:
{
NetlibConnection *nlc = h;
if (!nlc->termRequested) {
@@ -411,19 +414,17 @@ MIR_APP_DLL(void) Netlib_Shutdown(HNETLIBCONN h) }
break;
- case NLH_BOUNDPORT:
- NetlibBoundPort * nlb = (NetlibBoundPort*)h;
- if (nlb->s != INVALID_SOCKET)
- shutdown(nlb->s, SD_BOTH);
- break;
- }
- ReleaseMutex(hConnectionHeaderMutex);
+ case NLH_BOUNDPORT:
+ NetlibBoundPort * nlb = (NetlibBoundPort*)h;
+ if (nlb->s != INVALID_SOCKET)
+ shutdown(nlb->s, SD_BOTH);
+ break;
}
}
void UnloadNetlibModule(void)
{
- if (!bModuleInitialized || hConnectionHeaderMutex == nullptr) return;
+ if (!bModuleInitialized) return;
NetlibUnloadIeProxy();
NetlibUPnPDestroy();
@@ -435,9 +436,6 @@ void UnloadNetlibModule(void) for (auto &it : netlibUser.rev_iter())
Netlib_CloseHandle(it);
- CloseHandle(hConnectionHeaderMutex);
- if (hConnectionOpenMutex)
- CloseHandle(hConnectionOpenMutex);
WSACleanup();
OpenSsl_Unload();
}
@@ -452,7 +450,6 @@ int LoadNetlibModule(void) if (!OpenSsl_Init())
return 1;
- hConnectionHeaderMutex = CreateMutex(nullptr, FALSE, nullptr);
NetlibLogInit();
HookEvent(ME_OPT_INITIALISE, NetlibOptInitialise);
diff --git a/src/mir_app/src/netlib.h b/src/mir_app/src/netlib.h index 0087c4b05f..4b85f6c365 100644 --- a/src/mir_app/src/netlib.h +++ b/src/mir_app/src/netlib.h @@ -149,8 +149,9 @@ void NetlibLeaveNestedCS(NetlibNestedCriticalSection *nlncs); extern mir_cs csNetlibUser;
extern LIST<NetlibUser> netlibUser;
-extern HANDLE hEventConnected;
-extern HANDLE hEventDisconnected;
+extern HANDLE hEventConnected, hEventDisconnected;
+extern HANDLE hConnectionOpenMutex;
+extern mir_cs csConnectionHeader;
// netlibautoproxy.cpp
void NetlibLoadIeProxy(void);
@@ -165,7 +166,6 @@ bool BindSocketToPort(const char *szPorts, SOCKET s, SOCKET s6, int* portn); // netlibhttp.cpp
void NetlibHttpSetLastErrorUsingHttpResult(int result);
NETLIBHTTPREQUEST* NetlibHttpRecv(NetlibConnection* nlc, uint32_t hflags, uint32_t dflags, bool isConnect = false);
-void NetlibConnFromUrl(const char* szUrl, bool secur, NETLIBOPENCONNECTION &nloc);
// netliblog.cpp
void NetlibLogShowOptions(void);
diff --git a/src/mir_app/src/netlib_log.cpp b/src/mir_app/src/netlib_log.cpp index e09cde90e0..4a1cea21df 100644 --- a/src/mir_app/src/netlib_log.cpp +++ b/src/mir_app/src/netlib_log.cpp @@ -27,8 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_NETLIB_LOGWIN "Netlib/Log/Win" -extern HANDLE hConnectionHeaderMutex; - #define TIMEFORMAT_NONE 0 #define TIMEFORMAT_HHMMSS 1 #define TIMEFORMAT_MILLISECONDS 2 @@ -469,14 +467,15 @@ MIR_APP_DLL(void) Netlib_Dump(HNETLIBCONN nlc, const void *pBuf, size_t len, boo if ((flags & MSG_DUMPSSL) && !logOptions.dumpSsl) return; + NetlibUser *nlu; CMStringA str; + { + mir_cslock lock(csConnectionHeader); - WaitForSingleObject(hConnectionHeaderMutex, INFINITE); - NetlibUser *nlu = nlc ? nlc->nlu : nullptr; - - if (!(flags & MSG_NOTITLE)) - str.Format("(%p:%u) Data %s%s\r\n", nlc, nlc ? (int)nlc->s : 0, bIsSent ? "sent" : "received", flags & MSG_DUMPPROXY ? " (proxy)" : ""); - ReleaseMutex(hConnectionHeaderMutex); + nlu = nlc ? nlc->nlu : nullptr; + if (!(flags & MSG_NOTITLE)) + str.Format("(%p:%u) Data %s%s\r\n", nlc, nlc ? (int)nlc->s : 0, bIsSent ? "sent" : "received", flags & MSG_DUMPPROXY ? " (proxy)" : ""); + } // check filter settings if (nlu == nullptr) { diff --git a/src/mir_app/src/netlib_openconn.cpp b/src/mir_app/src/netlib_openconn.cpp index b131b02f4e..49e584e4d3 100644 --- a/src/mir_app/src/netlib_openconn.cpp +++ b/src/mir_app/src/netlib_openconn.cpp @@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "netlib.h" extern mir_cs csNetlibUser; -extern HANDLE hConnectionOpenMutex; extern uint32_t g_LastConnectionTick; extern int connectionTimeout; static int iUPnPCleanup = 0; diff --git a/src/mir_app/src/netlib_sock.cpp b/src/mir_app/src/netlib_sock.cpp index 2c88e7c5e9..ebd7f3a7ea 100644 --- a/src/mir_app/src/netlib_sock.cpp +++ b/src/mir_app/src/netlib_sock.cpp @@ -25,7 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "netlib.h" -extern HANDLE hConnectionHeaderMutex, hSendEvent, hRecvEvent; +extern HANDLE hSendEvent, hRecvEvent; ///////////////////////////////////////////////////////////////////////////////////////// @@ -107,15 +107,14 @@ MIR_APP_DLL(int) Netlib_Select(NETLIBSELECT *nls) int pending = 0; fd_set readfd, writefd, exceptfd; - WaitForSingleObject(hConnectionHeaderMutex, INFINITE); - if (!ConnectionListToSocketList(nls->hReadConns, &readfd, pending) - || !ConnectionListToSocketList(nls->hWriteConns, &writefd, pending) - || !ConnectionListToSocketList(nls->hExceptConns, &exceptfd, pending)) { - ReleaseMutex(hConnectionHeaderMutex); - return SOCKET_ERROR; + mir_cslock lock(csConnectionHeader); + if (!ConnectionListToSocketList(nls->hReadConns, &readfd, pending) + || !ConnectionListToSocketList(nls->hWriteConns, &writefd, pending) + || !ConnectionListToSocketList(nls->hExceptConns, &exceptfd, pending)) { + return SOCKET_ERROR; + } } - ReleaseMutex(hConnectionHeaderMutex); if (pending) return 1; @@ -132,25 +131,25 @@ MIR_APP_DLL(int) Netlib_SelectEx(NETLIBSELECTEX *nls) return SOCKET_ERROR; } + int pending = 0; + fd_set readfd, writefd, exceptfd; + TIMEVAL tv; tv.tv_sec = nls->dwTimeout / 1000; tv.tv_usec = (nls->dwTimeout % 1000) * 1000; - WaitForSingleObject(hConnectionHeaderMutex, INFINITE); - - int pending = 0; - fd_set readfd, writefd, exceptfd; - if (!ConnectionListToSocketList(nls->hReadConns, &readfd, pending) - || !ConnectionListToSocketList(nls->hWriteConns, &writefd, pending) - || !ConnectionListToSocketList(nls->hExceptConns, &exceptfd, pending)) { - ReleaseMutex(hConnectionHeaderMutex); - return SOCKET_ERROR; + mir_cslock lock(csConnectionHeader); + + if (!ConnectionListToSocketList(nls->hReadConns, &readfd, pending) + || !ConnectionListToSocketList(nls->hWriteConns, &writefd, pending) + || !ConnectionListToSocketList(nls->hExceptConns, &exceptfd, pending)) { + return SOCKET_ERROR; + } } - ReleaseMutex(hConnectionHeaderMutex); int rc = (pending) ? pending : select(0, &readfd, &writefd, &exceptfd, nls->dwTimeout == INFINITE ? nullptr : &tv); - WaitForSingleObject(hConnectionHeaderMutex, INFINITE); + mir_cslock lock(csConnectionHeader); /* go thru each passed HCONN array and grab its socket handle, then give it to FD_ISSET() to see if an event happened for that socket, if it has it will be returned as TRUE (otherwise not) This happens for read/write/except */ @@ -176,7 +175,6 @@ MIR_APP_DLL(int) Netlib_SelectEx(NETLIBSELECTEX *nls) if (conn == nullptr || conn == INVALID_HANDLE_VALUE) break; nls->hExceptStatus[j] = FD_ISSET(conn->s, &exceptfd); } - ReleaseMutex(hConnectionHeaderMutex); return rc; } |