From 6aac0ef550e7a62fdbbc160dbd5bda3f25c27f6e Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Sun, 11 Feb 2024 01:10:11 +0100 Subject: [PATCH 1/6] timeouts added --- .../package/aawg/src/proxyHandler.cpp | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp index d6d2124..d54cbcf 100644 --- a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp @@ -112,6 +112,28 @@ void AAWProxy::forward(ProxyDirection direction, std::atomic& should_exit) void AAWProxy::handleClient(int server_sock) { struct sockaddr client_address; socklen_t client_addresslen = sizeof(client_address); + int rc; + struct timeval timeout; + + while (true) { + fd_set rfds; + timeout.tv_sec = 30; + timeout.tv_usec = 0; + + FD_ZERO(&rfds); + FD_SET(server_sock, &rfds); + + rc = select(server_sock+1,&rfds,NULL,NULL,&timeout); + if (rc == 0) { + Logger::instance()->info("Server socket timeout 30s\n"); + close(server_sock); + return; + } + if (rc > 0) { + break; + } + } + if ((m_tcp_fd = accept(server_sock, &client_address, &client_addresslen)) < 0) { close(server_sock); Logger::instance()->info("accept failed: %s\n", strerror(errno)); @@ -138,6 +160,8 @@ void AAWProxy::handleClient(int server_sock) { usb_tcp.join(); tcp_usb.join(); + should_exit = true; + close(m_usb_fd); m_usb_fd = -1; @@ -145,6 +169,8 @@ void AAWProxy::handleClient(int server_sock) { m_tcp_fd = -1; Logger::instance()->info("Forwarding stopped\n"); + Logger::instance()->info("Restart communication\n"); + return; } std::optional AAWProxy::startServer(int32_t port) { @@ -160,7 +186,16 @@ std::optional AAWProxy::startServer(int32_t port) { Logger::instance()->info("setsockopt failed: %s\n", strerror(errno)); return std::nullopt; } - + + struct timeval tv = { + .tv_sec = 30 + }; + + if (setsockopt(server_sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv))) { + Logger::instance()->info("setsockopt failed timeout set: %s\n", strerror(errno)); + return std::nullopt; + } + struct sockaddr_in address; address.sin_family = AF_INET; address.sin_addr.s_addr = INADDR_ANY; From 1ce70ae52ed4f0171a4aa8054e749c4b83fe154b Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:19:20 +0100 Subject: [PATCH 2/6] enable default after new loop --- aa_wireless_dongle/package/aawg/src/usb.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aa_wireless_dongle/package/aawg/src/usb.cpp b/aa_wireless_dongle/package/aawg/src/usb.cpp index a354e37..db492ca 100644 --- a/aa_wireless_dongle/package/aawg/src/usb.cpp +++ b/aa_wireless_dongle/package/aawg/src/usb.cpp @@ -77,6 +77,9 @@ void UsbManager::disableGadget() { disableGadget(accessoryGadgetName); Logger::instance()->info("USB Manager: Disabled all USB gadgets\n"); + + enableGadget(defaultGadgetName); + Logger::instance()->info("USB Manager: Start default gadget after restart\n"); } void UsbManager::enableDefaultAndWaitForAccessroy() { From de9a2d5a76dd9adf3429db4bae16d5f35630673b Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Sun, 11 Feb 2024 10:20:09 +0100 Subject: [PATCH 3/6] close new sock of select --- aa_wireless_dongle/package/aawg/src/proxyHandler.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp index d54cbcf..17762d4 100644 --- a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp @@ -127,6 +127,7 @@ void AAWProxy::handleClient(int server_sock) { if (rc == 0) { Logger::instance()->info("Server socket timeout 30s\n"); close(server_sock); + close(server_sock+1); return; } if (rc > 0) { From 2d3a93c364fd4f4c70dfc4e2b1bff1a8836573ee Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Sat, 17 Feb 2024 21:42:53 +0100 Subject: [PATCH 4/6] extract fot other new branch --- .../package/aawg/src/proxyHandler.cpp | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp index 17762d4..c640dda 100644 --- a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp @@ -112,28 +112,6 @@ void AAWProxy::forward(ProxyDirection direction, std::atomic& should_exit) void AAWProxy::handleClient(int server_sock) { struct sockaddr client_address; socklen_t client_addresslen = sizeof(client_address); - int rc; - struct timeval timeout; - - while (true) { - fd_set rfds; - timeout.tv_sec = 30; - timeout.tv_usec = 0; - - FD_ZERO(&rfds); - FD_SET(server_sock, &rfds); - - rc = select(server_sock+1,&rfds,NULL,NULL,&timeout); - if (rc == 0) { - Logger::instance()->info("Server socket timeout 30s\n"); - close(server_sock); - close(server_sock+1); - return; - } - if (rc > 0) { - break; - } - } if ((m_tcp_fd = accept(server_sock, &client_address, &client_addresslen)) < 0) { close(server_sock); From 8374562dd3675ca398f9c4ab9c8397a42f06c7c4 Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:04:51 +0100 Subject: [PATCH 5/6] Update proxyHandler.cpp --- aa_wireless_dongle/package/aawg/src/proxyHandler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp index c640dda..283cabc 100644 --- a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp @@ -112,7 +112,6 @@ void AAWProxy::forward(ProxyDirection direction, std::atomic& should_exit) void AAWProxy::handleClient(int server_sock) { struct sockaddr client_address; socklen_t client_addresslen = sizeof(client_address); - if ((m_tcp_fd = accept(server_sock, &client_address, &client_addresslen)) < 0) { close(server_sock); Logger::instance()->info("accept failed: %s\n", strerror(errno)); From 3715306a822eab599262787d88bf1269d9121ec7 Mon Sep 17 00:00:00 2001 From: Ioniq3 <156689157+Ioniq3@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:08:45 +0100 Subject: [PATCH 6/6] remove should_exit --- aa_wireless_dongle/package/aawg/src/proxyHandler.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp index 5bef646..c7a96c5 100644 --- a/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp +++ b/aa_wireless_dongle/package/aawg/src/proxyHandler.cpp @@ -140,8 +140,6 @@ void AAWProxy::handleClient(int server_sock) { usb_tcp.join(); tcp_usb.join(); - should_exit = true; - close(m_usb_fd); m_usb_fd = -1;