Skip to content

Commit

Permalink
Merge pull request microsoft#253 from nacho-carnicero/OSX_UDP_socket_fix
Browse files Browse the repository at this point in the history
Fix OSX specific UDP socket issue
  • Loading branch information
lovettchris authored Jun 2, 2017
2 parents f861f16 + 3461fca commit 6458eaf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions MavLinkCom/src/serial_com/UdpClientPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ class UdpClientPort::UdpSocketImpl
}

socklen_t addrlen = sizeof(sockaddr_in);
#if defined (__APPLE__)
int hr = ::write(sock, reinterpret_cast<const char*>(ptr), count);
#else
int hr = sendto(sock, reinterpret_cast<const char*>(ptr), count, 0, reinterpret_cast<sockaddr*>(&remoteaddr), addrlen);
#endif
if (hr == SOCKET_ERROR)
{
hr = WSAGetLastError();
Expand All @@ -175,18 +179,22 @@ class UdpClientPort::UdpSocketImpl

int bytesRead = 0;
// try and receive something, up until port is closed anyway.

while (!closed_)
{
socklen_t addrlen = sizeof(sockaddr_in);
#if defined (__APPLE__)
int rc = ::read(sock, reinterpret_cast<char*>(result), bytesToRead);
#else
int rc = recvfrom(sock, reinterpret_cast<char*>(result), bytesToRead, 0, reinterpret_cast<sockaddr*>(&other), &addrlen);
#endif
if (rc < 0)
{
int hr = WSAGetLastError();
#ifdef _WIN32
if (hr == WSAEMSGSIZE)
{
// message was too large for the buffer, no problem, return what we have.
// message was too large for the buffer, no problem, return what we have.
}
else if (hr == WSAECONNRESET || hr == ERROR_IO_PENDING)
{
Expand Down

0 comments on commit 6458eaf

Please sign in to comment.