Skip to content

Commit

Permalink
Merge upstream branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
unforgiven512 committed Jul 12, 2024
2 parents 5b01e16 + 5a0f35e commit 402cc3b
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions UDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@
CUDPSocket::CUDPSocket(const std::string& address, unsigned short port) :
m_localAddress(address),
m_localPort(port),
#if defined(_WIN32) || defined(_WIN64)
m_fd(INVALID_SOCKET),
#else
m_fd(-1),
#endif
m_af(AF_UNSPEC)
{
}

CUDPSocket::CUDPSocket(unsigned short port) :
m_localAddress(),
m_localPort(port),
#if defined(_WIN32) || defined(_WIN64)
m_fd(INVALID_SOCKET),
#else
m_fd(-1),
#endif
m_af(AF_UNSPEC)
{
}
Expand Down Expand Up @@ -97,7 +105,9 @@ int CUDPSocket::lookup(const std::string& hostname, unsigned short port, sockadd
return err;
}

::memcpy(&addr, res->ai_addr, address_length = res->ai_addrlen);
address_length = (unsigned int)res->ai_addrlen;

::memcpy(&addr, res->ai_addr, address_length);

::freeaddrinfo(res);

Expand Down Expand Up @@ -160,7 +170,11 @@ bool CUDPSocket::open(const sockaddr_storage& address)

bool CUDPSocket::open()
{
#if defined(_WIN32) || defined(_WIN64)
assert(m_fd == INVALID_SOCKET);
#else
assert(m_fd == -1);
#endif

sockaddr_storage addr;
unsigned int addrlen;
Expand Down Expand Up @@ -221,7 +235,14 @@ int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storag
{
assert(buffer != NULL);
assert(length > 0U);
assert(m_fd >= 0);

#if defined(_WIN32) || defined(_WIN64)
if (m_fd == INVALID_SOCKET)
return 0;
#else
if (m_fd == -1)
return 0;
#endif

// Check that the readfrom() won't block
struct pollfd pfd;
Expand Down Expand Up @@ -282,7 +303,11 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s
{
assert(buffer != NULL);
assert(length > 0U);
#if defined(_WIN32) || defined(_WIN64)
assert(m_fd != INVALID_SOCKET);
#else
assert(m_fd >= 0);
#endif

bool result = false;

Expand Down Expand Up @@ -313,13 +338,16 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s

void CUDPSocket::close()
{
if (m_fd >= 0) {
#if defined(_WIN32) || defined(_WIN64)
if (m_fd != INVALID_SOCKET) {
::closesocket(m_fd);
m_fd = INVALID_SOCKET;
}
#else
if (m_fd >= 0) {
::close(m_fd);
#endif
m_fd = -1;
}
#endif
}

0 comments on commit 402cc3b

Please sign in to comment.