From 951a0212d8ac12520eaa8236d4b6405d9ddd512c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sat, 18 Jul 2020 14:20:31 +0100 Subject: Move IsValidSocket out of global namespace --- src/OSSupport/UDPEndpointImpl.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/OSSupport/UDPEndpointImpl.cpp') diff --git a/src/OSSupport/UDPEndpointImpl.cpp b/src/OSSupport/UDPEndpointImpl.cpp index 5984bc4e2..3f04dd4f5 100644 --- a/src/OSSupport/UDPEndpointImpl.cpp +++ b/src/OSSupport/UDPEndpointImpl.cpp @@ -14,13 +14,16 @@ //////////////////////////////////////////////////////////////////////////////// // Globals: -static bool IsValidSocket(evutil_socket_t a_Socket) +namespace UDPEndpointImplHelper { - #ifdef _WIN32 + static bool IsValidSocket(evutil_socket_t a_Socket) + { +#ifdef _WIN32 return (a_Socket != INVALID_SOCKET); - #else // _WIN32 +#else // _WIN32 return (a_Socket >= 0); - #endif // else _WIN32 +#endif // else _WIN32 + } } @@ -281,7 +284,7 @@ bool cUDPEndpointImpl::Send(const AString & a_Payload, const AString & a_Host, U reinterpret_cast(&sa)->sin_port = htons(a_Port); if (m_IsMainSockIPv6) { - if (IsValidSocket(m_SecondarySock)) + if (UDPEndpointImplHelper::IsValidSocket(m_SecondarySock)) { // The secondary socket, which is always IPv4, is present: NumSent = static_cast(sendto(m_SecondarySock, a_Payload.data(), a_Payload.size(), 0, reinterpret_cast(&sa), static_cast(salen))); @@ -339,7 +342,7 @@ void cUDPEndpointImpl::EnableBroadcasts(void) } // Enable broadcasts on the secondary socket, if opened (use char, it worked for primary): - if (IsValidSocket(m_SecondarySock)) + if (UDPEndpointImplHelper::IsValidSocket(m_SecondarySock)) { if (setsockopt(m_SecondarySock, SOL_SOCKET, SO_BROADCAST, &broadcastChar, sizeof(broadcastChar)) == -1) { @@ -351,7 +354,7 @@ void cUDPEndpointImpl::EnableBroadcasts(void) } // Enable broadcasts on the secondary socket, if opened (use int, it worked for primary): - if (IsValidSocket(m_SecondarySock)) + if (UDPEndpointImplHelper::IsValidSocket(m_SecondarySock)) { if (setsockopt(m_SecondarySock, SOL_SOCKET, SO_BROADCAST, reinterpret_cast(&broadcastInt), sizeof(broadcastInt)) == -1) { @@ -379,14 +382,14 @@ void cUDPEndpointImpl::Open(UInt16 a_Port) m_MainSock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP); int err; - if (!IsValidSocket(m_MainSock)) + if (!UDPEndpointImplHelper::IsValidSocket(m_MainSock)) { // Failed to create IPv6 socket, create an IPv4 one instead: m_IsMainSockIPv6 = false; err = EVUTIL_SOCKET_ERROR(); LOGD("UDP: Failed to create IPv6 MainSock: %d (%s)", err, evutil_socket_error_to_string(err)); m_MainSock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (!IsValidSocket(m_MainSock)) + if (!UDPEndpointImplHelper::IsValidSocket(m_MainSock)) { err = EVUTIL_SOCKET_ERROR(); m_Callbacks.OnError(err, Printf("Cannot create UDP socket for port %d: %s", a_Port, evutil_socket_error_to_string(err))); @@ -492,7 +495,7 @@ void cUDPEndpointImpl::Open(UInt16 a_Port) LOGD("Creating a second UDP socket for IPv4"); m_SecondarySock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); - if (!IsValidSocket(m_SecondarySock)) + if (!UDPEndpointImplHelper::IsValidSocket(m_SecondarySock)) { // Don't report as an error, the primary socket is working err = EVUTIL_SOCKET_ERROR(); -- cgit v1.2.3