Fix missing MSG_NOSIGNAL and TCP_KEEPIDLE on macos

This commit is contained in:
ImperatorS79 2020-11-21 21:29:23 +01:00
parent 143d7d391a
commit 255812c80e
1 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,10 @@
#include <cstring>
#include <Nazara/Network/Debug.hpp>
#if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE)
#define TCP_KEEPIDLE TCP_KEEPALIVE // see -> https://gitlab.freedesktop.org/spice/usbredir/-/issues/9
#endi
namespace Nz
{
constexpr int SOCKET_ERROR = -1;
@ -597,8 +601,11 @@ namespace Nz
}
IpAddress senderIp;
#if not defined(MSG_NOSIGNAL)
int byteRead = recvmsg(handle, &msgHdr, MSG_NOSIGNAL);
#else
int byteRead = recvmsg(handle, &msgHdr, 0);
#endif
if (byteRead == -1)
{
int errorCode = GetLastErrorCode();
@ -714,7 +721,12 @@ namespace Nz
msgHdr.msg_iov = sysBuffers.data();
msgHdr.msg_iovlen = static_cast<int>(bufferCount);
#if not defined(MSG_NOSIGNAL)
int byteSent = sendmsg(handle, &msgHdr, MSG_NOSIGNAL);
#else
int byteSent = sendmsg(handle, &msgHdr, 0);
#endif
if (byteSent == SOCKET_ERROR)
{
int errorCode = GetLastErrorCode();
@ -896,6 +908,18 @@ namespace Nz
if (error)
*error = SocketError_NoError;
#if not defined(MSG_NOSIGNAL) // -> https://github.com/intel/parameter-framework/pull/133/files
//There is no MSG_NOSIGNAL on macos
const int set = 1;
if (setsockopt(handle, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set)) == SOCKET_ERROR)
{
if (error)
*error = TranslateErrnoToSocketError(GetLastErrorCode());
return false; //< Error
}
#endif
return true;
}