summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2015-02-08 14:41:24 +0100
committerMattes D <github@xoft.cz>2015-02-08 14:41:24 +0100
commit81d7329ad31657e9e587dd7231be503ae1b157a9 (patch)
treefc287ec5bf628bf2001d597bdb41afa0c05cfe3e /src
parentWSSAnvil: Fixed chunk data padding. (diff)
downloadcuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar.gz
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar.bz2
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar.lz
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar.xz
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.tar.zst
cuberite-81d7329ad31657e9e587dd7231be503ae1b157a9.zip
Diffstat (limited to '')
-rw-r--r--src/OSSupport/ServerHandleImpl.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/OSSupport/ServerHandleImpl.cpp b/src/OSSupport/ServerHandleImpl.cpp
index 6f4343b1f..72092df10 100644
--- a/src/OSSupport/ServerHandleImpl.cpp
+++ b/src/OSSupport/ServerHandleImpl.cpp
@@ -126,11 +126,6 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
int err;
evutil_socket_t MainSock = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP);
- // Set reuse flag
- #if !defined(_WIN32)
- evutil_make_listen_socket_reuseable(MainSock);
- #endif
-
if (!IsValidSocket(MainSock))
{
// Failed to create IPv6 socket, create an IPv4 one instead:
@@ -144,6 +139,16 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
return false;
}
+ // Allow the port to be reused right after the socket closes:
+ if (evutil_make_listen_socket_reuseable(MainSock) != 0)
+ {
+ m_ErrorCode = EVUTIL_SOCKET_ERROR();
+ Printf(m_ErrorMsg, "Port %d cannot be made reusable: %d (%s). Restarting the server might not work.",
+ a_Port, m_ErrorCode, evutil_socket_error_to_string(m_ErrorCode)
+ );
+ LOG("%s", m_ErrorMsg.c_str());
+ }
+
// Bind to all interfaces:
sockaddr_in name;
memset(&name, 0, sizeof(name));
@@ -170,6 +175,16 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
setsockopt(MainSock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char *>(&Zero), sizeof(Zero));
#endif
+ // Allow the port to be reused right after the socket closes:
+ if (evutil_make_listen_socket_reuseable(MainSock) != 0)
+ {
+ m_ErrorCode = EVUTIL_SOCKET_ERROR();
+ Printf(m_ErrorMsg, "Port %d cannot be made reusable: %d (%s). Restarting the server might not work.",
+ a_Port, m_ErrorCode, evutil_socket_error_to_string(m_ErrorCode)
+ );
+ LOG("%s", m_ErrorMsg.c_str());
+ }
+
// Bind to all interfaces:
sockaddr_in6 name;
memset(&name, 0, sizeof(name));
@@ -209,11 +224,6 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
LOGD("Creating a second socket for IPv4");
evutil_socket_t SecondSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- // Set reuse flag
- #if !defined(_WIN32)
- evutil_make_listen_socket_reuseable(SecondSock);
- #endif
-
if (!IsValidSocket(SecondSock))
{
err = EVUTIL_SOCKET_ERROR();
@@ -221,6 +231,16 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
return true; // Report as success, the primary socket is working
}
+ // Allow the port to be reused right after the socket closes:
+ if (evutil_make_listen_socket_reuseable(MainSock) != 0)
+ {
+ m_ErrorCode = EVUTIL_SOCKET_ERROR();
+ Printf(m_ErrorMsg, "Port %d cannot be made reusable (second socket): %d (%s). Restarting the server might not work.",
+ a_Port, m_ErrorCode, evutil_socket_error_to_string(m_ErrorCode)
+ );
+ LOG("%s", m_ErrorMsg.c_str());
+ }
+
// Make the secondary socket nonblocking:
if (evutil_make_socket_nonblocking(SecondSock) != 0)
{