Skip to content

Commit

Permalink
Fix bug in UDP client code.
Browse files Browse the repository at this point in the history
  • Loading branch information
lovettchris committed Mar 9, 2017
1 parent 23c2e84 commit d5f8837
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions MavLinkCom/src/serial_com/UdpClientPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ class UdpClientPort::UdpSocketImpl
throw std::runtime_error(Utils::stringf("UdpClientPort socket bind failed with error: %d\n", hr));
return hr;
}

if (hasRemote && remotePort != 0) {
// limit the socket to only send/receive to/from this remote address/port, this ensures our
// subsequent recvfrom calls don't steal messages from other UdpClientPorts.
rc = ::connect(sock, reinterpret_cast<sockaddr*>(&remoteaddr), addrlen);
if (rc < 0)
{
int hr = WSAGetLastError();
throw std::runtime_error(Utils::stringf("UdpClientPort socket could not connect to remote host at %s:%d, error: %d\n",
remoteHost.c_str(), remotePort, hr));
return hr;
}
}
closed_ = false;
return 0;
}
Expand Down Expand Up @@ -172,11 +185,15 @@ class UdpClientPort::UdpSocketImpl
// try again - this can happen if server recreates the socket on their side.
continue;
}
else
else if (hr == WSAEINTR)
{
// skip this, it is was interrupted, and if user is closing the port closed_ will be true.
continue;
}
#else
if (hr == EINTR)
{
// skip this, it is was interrupted.
// skip this, it is was interrupted, and if user is closing the port closed_ will be true.
continue;
}
else
Expand Down

0 comments on commit d5f8837

Please sign in to comment.