From 9aeb9578d8e264d4b351b597f20dc1cd7e86b278 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 18 Jul 2018 21:05:51 +0300 Subject: if there's no need, let's not call that hook --- src/mir_app/src/netlibbind.cpp | 15 ++++++++------- src/mir_app/src/netlibopenconn.cpp | 35 ++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'src/mir_app') diff --git a/src/mir_app/src/netlibbind.cpp b/src/mir_app/src/netlibbind.cpp index 19b86361b4..f56fe5a4a0 100644 --- a/src/mir_app/src/netlibbind.cpp +++ b/src/mir_app/src/netlibbind.cpp @@ -292,13 +292,14 @@ LBL_Error: nlbp->hThread = mir_forkThread(NetlibBindAcceptThread, nlbp); - NETLIBCONNECTIONEVENTINFO ncei; - ZeroMemory(&ncei, sizeof(ncei)); - ncei.connected = 1; - ncei.listening = 1; - ncei.szSettingsModule = nlu->user.szSettingsModule; - memcpy(&ncei.local, &sin, sizeof(sin)); - NotifyFastHook(hEventConnected, (WPARAM)&ncei, 0); + if (GetSubscribersCount((THook*)hEventConnected)) { + NETLIBCONNECTIONEVENTINFO ncei = {}; + ncei.connected = 1; + ncei.listening = 1; + ncei.szSettingsModule = nlu->user.szSettingsModule; + memcpy(&ncei.local, &sin, sizeof(sin)); + NotifyFastHook(hEventConnected, (WPARAM)&ncei, 0); + } return nlbp; } diff --git a/src/mir_app/src/netlibopenconn.cpp b/src/mir_app/src/netlibopenconn.cpp index e0e5bba525..dfd2e365ef 100644 --- a/src/mir_app/src/netlibopenconn.cpp +++ b/src/mir_app/src/netlibopenconn.cpp @@ -773,24 +773,25 @@ bool NetlibDoConnect(NetlibConnection *nlc) Netlib_Logf(nlu, "(%d) Connected to %s:%d", nlc->s, nloc->szHost, nloc->wPort); - NETLIBCONNECTIONEVENTINFO ncei; - ZeroMemory(&ncei, sizeof(ncei)); - ncei.connected = 1; - ncei.szSettingsModule = nlu->user.szSettingsModule; - int size = sizeof(SOCKADDR_IN); - getsockname(nlc->s, (SOCKADDR *)&ncei.local, &size); - if (nlu->settings.useProxy) { - size = sizeof(SOCKADDR_IN); - getpeername(nlc->s, (SOCKADDR *)&ncei.proxy, &size); - ncei.remote.sin_family = AF_INET; - ncei.remote.sin_port = htons((short)nloc->wPort); - ncei.remote.sin_addr.S_un.S_addr = DnsLookup(nlu, nloc->szHost); - } - else { - size = sizeof(SOCKADDR_IN); - getpeername(nlc->s, (SOCKADDR *)&ncei.remote, &size); + if (GetSubscribersCount((THook*)hEventConnected)) { + NETLIBCONNECTIONEVENTINFO ncei = {}; + ncei.connected = 1; + ncei.szSettingsModule = nlu->user.szSettingsModule; + int size = sizeof(SOCKADDR_IN); + getsockname(nlc->s, (SOCKADDR *)&ncei.local, &size); + if (nlu->settings.useProxy) { + size = sizeof(SOCKADDR_IN); + getpeername(nlc->s, (SOCKADDR *)&ncei.proxy, &size); + ncei.remote.sin_family = AF_INET; + ncei.remote.sin_port = htons((short)nloc->wPort); + ncei.remote.sin_addr.S_un.S_addr = DnsLookup(nlu, nloc->szHost); + } + else { + size = sizeof(SOCKADDR_IN); + getpeername(nlc->s, (SOCKADDR *)&ncei.remote, &size); + } + NotifyFastHook(hEventConnected, (WPARAM)&ncei, 0); } - NotifyFastHook(hEventConnected, (WPARAM)&ncei, 0); if (NLOCF_SSL & nloc->flags) return Netlib_StartSsl(nlc, nullptr) != 0; -- cgit v1.2.3