cNetwork: Added error logging to server socket creation.
This is mainly for WinXP and RasPi testing.
This commit is contained in:
parent
ddb1818dd5
commit
235b8f1f6b
@ -823,6 +823,8 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
|||||||
if (!IsValidSocket(MainSock))
|
if (!IsValidSocket(MainSock))
|
||||||
{
|
{
|
||||||
// Failed to create IPv6 socket, create an IPv4 one instead:
|
// Failed to create IPv6 socket, create an IPv4 one instead:
|
||||||
|
int err = EVUTIL_SOCKET_ERROR();
|
||||||
|
LOGD("Failed to create IPv6 MainSock: %d (%s)", err, evutil_socket_error_to_string(err));
|
||||||
MainSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
MainSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (!IsValidSocket(MainSock))
|
if (!IsValidSocket(MainSock))
|
||||||
{
|
{
|
||||||
@ -850,9 +852,12 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
|||||||
UInt32 Zero = 0;
|
UInt32 Zero = 0;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
// WinXP doesn't support this feature, so if the setting fails, create another socket later on:
|
// WinXP doesn't support this feature, so if the setting fails, create another socket later on:
|
||||||
NeedsTwoSockets = (
|
int res = setsockopt(MainSock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char *>(&Zero), sizeof(Zero));
|
||||||
(setsockopt(MainSock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char *>(&Zero), sizeof(Zero)) == SOCKET_ERROR) &&
|
int err = EVUTIL_SOCKET_ERROR();
|
||||||
(EVUTIL_SOCKET_ERROR() == WSAENOPROTOOPT)
|
NeedsTwoSockets = ((res == SOCKET_ERROR) && (err == WSAENOPROTOOPT));
|
||||||
|
LOGD("setsockopt(IPV6_V6ONLY) returned %d, err is %d (%s). %s",
|
||||||
|
res, err, evutil_socket_error_to_string(err),
|
||||||
|
NeedsTwoSockets ? "Second socket will be created" : "Second socket not needed"
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
setsockopt(MainSock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char *>(&Zero), sizeof(Zero));
|
setsockopt(MainSock, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast<const char *>(&Zero), sizeof(Zero));
|
||||||
@ -890,11 +895,24 @@ bool cServerHandleImpl::Listen(UInt16 a_Port)
|
|||||||
// If a secondary socket is required (WinXP dual-stack), create it here:
|
// If a secondary socket is required (WinXP dual-stack), create it here:
|
||||||
if (NeedsTwoSockets)
|
if (NeedsTwoSockets)
|
||||||
{
|
{
|
||||||
|
LOGD("Creating a second socket for IPv4");
|
||||||
evutil_socket_t SecondSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
evutil_socket_t SecondSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
if (!IsValidSocket(SecondSock))
|
if (IsValidSocket(SecondSock))
|
||||||
{
|
{
|
||||||
evutil_make_socket_nonblocking(SecondSock);
|
if (evutil_make_socket_nonblocking(SecondSock) == 0)
|
||||||
m_SecondaryConnListener = evconnlistener_new(cNetworkSingleton::Get().m_EventBase, Callback, this, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, 0, SecondSock);
|
{
|
||||||
|
m_SecondaryConnListener = evconnlistener_new(cNetworkSingleton::Get().m_EventBase, Callback, this, LEV_OPT_CLOSE_ON_FREE | LEV_OPT_REUSEABLE, 0, SecondSock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int err = EVUTIL_SOCKET_ERROR();
|
||||||
|
LOGD("evutil_make_socket_nonblocking() failed: %d, %s", err, evutil_socket_error_to_string(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int err = EVUTIL_SOCKET_ERROR();
|
||||||
|
LOGD("socket(AF_INET, ...) failed: %d, %s", err, evutil_socket_error_to_string(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_IsListening = true;
|
m_IsListening = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user