From 645c771af2121287756b62947961226444789148 Mon Sep 17 00:00:00 2001 From: Shingo INADA Date: Wed, 15 Apr 2020 11:44:01 +0900 Subject: [PATCH] [MODEM] mark as invalid-socket if failed to bind udp sockets to avoid WSAEINVAL error --- core/hw/modem/picoppp.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/hw/modem/picoppp.cpp b/core/hw/modem/picoppp.cpp index d39fe42e8..30f8de96b 100644 --- a/core/hw/modem/picoppp.cpp +++ b/core/hw/modem/picoppp.cpp @@ -478,6 +478,9 @@ static void read_native_sockets() // Read UDP sockets for (auto it = udp_sockets.begin(); it != udp_sockets.end(); it++) { + if (!VALID(it->second)) + continue; + addr_len = sizeof(src_addr); memset(&src_addr, 0, addr_len); r = recvfrom(it->second, buf, sizeof(buf), 0, (struct sockaddr *)&src_addr, &addr_len); @@ -735,6 +738,10 @@ static void *pico_thread_func(void *) if (::bind(sockfd, (struct sockaddr *)&saddr, saddr_len) < 0) { perror("bind"); + closesocket(sockfd); + auto it = udp_sockets.find(port); + if (it != udp_sockets.end()) + it->second = INVALID_SOCKET; continue; } }