Merge pull request #1729 from mc-server/ReuseFlag
Set reuse flag to sockets
This commit is contained in:
commit
5ee5a691b7
@ -125,6 +125,12 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
||||
bool NeedsTwoSockets = false;
|
||||
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:
|
||||
@ -193,6 +199,7 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
||||
}
|
||||
m_ConnListener = evconnlistener_new(cNetworkSingleton::Get().GetEventBase(), Callback, this, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, 0, MainSock);
|
||||
m_IsListening = true;
|
||||
|
||||
if (!NeedsTwoSockets)
|
||||
{
|
||||
return true;
|
||||
@ -201,6 +208,12 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
||||
// If a secondary socket is required (WinXP dual-stack), create it here:
|
||||
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();
|
||||
@ -233,7 +246,7 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
||||
if (listen(SecondSock, 0) != 0)
|
||||
{
|
||||
err = EVUTIL_SOCKET_ERROR();
|
||||
LOGD("Cannot listen on on secondary socket on port %d: %d (%s)", a_Port, err, evutil_socket_error_to_string(err));
|
||||
LOGD("Cannot listen on secondary socket on port %d: %d (%s)", a_Port, err, evutil_socket_error_to_string(err));
|
||||
evutil_closesocket(SecondSock);
|
||||
return true; // Report as success, the primary socket is working
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user