Merge pull request #72 from inada-s/garkun/skip-recvfrom-with-invalid-sock

[MODEM] avoid WSAEINVAL error
This commit is contained in:
flyinghead 2020-04-15 10:43:23 +02:00 committed by GitHub
commit 3495a0b53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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;
}
}