From 8a2898666ab3c2c701fbedc15d484557d486840a Mon Sep 17 00:00:00 2001 From: Connection Refused Date: Tue, 19 Oct 2021 15:42:51 +0800 Subject: [PATCH] [Redirector] Fix udp always retry connect --- Redirector/EventHandler.cpp | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/Redirector/EventHandler.cpp b/Redirector/EventHandler.cpp index 5eceba87..3e721ead 100644 --- a/Redirector/EventHandler.cpp +++ b/Redirector/EventHandler.cpp @@ -352,19 +352,11 @@ void udpSend(ENDPOINT_ID id, const unsigned char* target, const char* buffer, in auto remote = udpContext[id]; udpContextLock.unlock(); - UP += length; + if (remote->tcpSocket == INVALID_SOCKET && !remote->Associate()) + return; - if (remote->tcpSocket == INVALID_SOCKET || remote->udpSocket == INVALID_SOCKET) + if (remote->udpSocket == INVALID_SOCKET) { - if (remote->tcpSocket) closesocket(remote->tcpSocket); - if (remote->udpSocket) closesocket(remote->udpSocket); - - remote->tcpSocket = INVALID_SOCKET; - remote->udpSocket = INVALID_SOCKET; - - if (!remote->Associate()) - return; - if (!remote->CreateUDP()) return; @@ -374,14 +366,8 @@ void udpSend(ENDPOINT_ID id, const unsigned char* target, const char* buffer, in thread(udpReceiveHandler, id, remote, option).detach(); } - if (remote->Send((PSOCKADDR_IN6)target, buffer, length) != length) - { - if (remote->tcpSocket) closesocket(remote->tcpSocket); - if (remote->udpSocket) closesocket(remote->udpSocket); - - remote->tcpSocket = INVALID_SOCKET; - remote->udpSocket = INVALID_SOCKET; - } + if (remote->Send((PSOCKADDR_IN6)target, buffer, length) == length) + UP += length; } void udpCanReceive(ENDPOINT_ID id)