Skip to content

Commit

Permalink
Merge pull request #692 from f1rmb/f1rmb_fix_UDPSocket_close
Browse files Browse the repository at this point in the history
Fix nasty bug in UDPSocket::close().
  • Loading branch information
g4klx authored Apr 8, 2021
2 parents 6b43bce + c08b41a commit 6ae01af
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions UDPSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std
return false;
}

close(index);

int fd = ::socket(addr.ss_family, SOCK_DGRAM, 0);
if (fd < 0) {
#if defined(_WIN32) || defined(_WIN64)
Expand Down Expand Up @@ -344,13 +346,13 @@ bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const s

void CUDPSocket::close()
{
for (int i = 0; i < UDP_SOCKET_MAX; i++)
close(m_fd[i]);
for (unsigned int i = 0; i < UDP_SOCKET_MAX; i++)
close(i);
}

void CUDPSocket::close(const unsigned int index)
{
if (m_fd[index] >= 0) {
if ((index < UDP_SOCKET_MAX) && (m_fd[index] >= 0)) {
#if defined(_WIN32) || defined(_WIN64)
::closesocket(m_fd[index]);
#else
Expand Down

0 comments on commit 6ae01af

Please sign in to comment.