Skip to content

Commit

Permalink
Sleep for 5 seconds when creating a socket failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Jul 15, 2024
1 parent de6f657 commit 76ddeb3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion source/socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#include "socket.h"

#include "log.h"
#include "platform.h"

#include <chrono>
#include <fcntl.h>
#include <sys/socket.h>
#include <unistd.h>
Expand All @@ -31,6 +32,8 @@
#include <cstdio>
#include <cstring>

using namespace std::chrono_literals;

///////////////////////////////////////////////////////////////////////////
Socket::~Socket ()
{
Expand Down Expand Up @@ -100,6 +103,7 @@ bool Socket::bind (SockAddr const &addr_)
case AF_INET:
if (::bind (m_fd, addr_, sizeof (struct sockaddr_in)) != 0)
{
platform::Thread::sleep (5000ms);
error ("bind: %s\n", std::strerror (errno));
return false;
}
Expand All @@ -110,6 +114,7 @@ bool Socket::bind (SockAddr const &addr_)
if (::bind (m_fd, addr_, sizeof (struct sockaddr_in6)) != 0)
{
error ("bind: %s\n", std::strerror (errno));
platform::Thread::sleep (5000ms);
return false;
}
break;
Expand Down

0 comments on commit 76ddeb3

Please sign in to comment.