Skip to content

Commit

Permalink
Merge branch 'cgutman:moonlight' into moonlight
Browse files Browse the repository at this point in the history
  • Loading branch information
zoeyjodon authored Feb 1, 2024
2 parents 90d3400 + 061ce30 commit f8f5d0b
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 9 deletions.
4 changes: 2 additions & 2 deletions protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1725,8 +1725,8 @@ enet_protocol_send_outgoing_commands (ENetHost * host, ENetEvent * event, int ch

currentPeer -> lastSendTime = host -> serviceTime;

if (currentPeer -> state == ENET_PEER_STATE_CONNECTING && currentPeer -> packetsLost == 2) {
// Disable QoS tagging if we don't get a response to 2 connection requests in a row.
if ((currentPeer -> state == ENET_PEER_STATE_CONNECTING || currentPeer -> state == ENET_PEER_STATE_ACKNOWLEDGING_CONNECT) && currentPeer -> packetsLost == 3) {
// Disable QoS tagging if we don't get a response to 3 connection requests/acks in a row.
// Some networks drop QoS tagged packets, so let's try without it.
enet_socket_set_option (host -> socket, ENET_SOCKOPT_QOS, 0);
}
Expand Down
22 changes: 19 additions & 3 deletions unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,26 @@ enet_socket_send (ENetSocket socket,

if (sentLength == -1)
{
if (errno == EWOULDBLOCK)
return 0;
switch (errno)
{
case EWOULDBLOCK:
return 0;

return -1;
// These errors are treated as possible transient
// conditions that could be caused by a network
// interruption. We'll ignore them and allow the
// socket timeout to kill us if the connection
// is permanently interrupted.
case EADDRNOTAVAIL:
case ENETDOWN:
case ENETUNREACH:
case EHOSTDOWN:
case EHOSTUNREACH:
return 0;

default:
return -1;
}
}

return sentLength;
Expand Down
54 changes: 50 additions & 4 deletions win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ typedef UINT32 *PQOS_FLOWID;
#define QOS_NON_ADAPTIVE_FLOW 0x00000002
#endif

// This is missing from MinGW headers
#ifndef IN6ADDR_V4MAPPEDPREFIX_INIT
#define IN6ADDR_V4MAPPEDPREFIX_INIT { \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0xff, 0xff, \
}
#endif

static enet_uint32 timeBase = 0;

#if !(defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_APP)
Expand Down Expand Up @@ -435,14 +443,36 @@ enet_socket_send (ENetSocket socket,
#ifdef HAS_QWAVE
if (!qosAddedFlow && qosHandle != INVALID_HANDLE_VALUE)
{
static const char V4_MAPPED_V6_PREFIX[] = IN6ADDR_V4MAPPEDPREFIX_INIT;

BOOL isV4MappedV6Addr =
peerAddress->address.ss_family == AF_INET6 &&
!memcmp(&((PSOCKADDR_IN6)&peerAddress->address)->sin6_addr, V4_MAPPED_V6_PREFIX, sizeof(V4_MAPPED_V6_PREFIX));

// qWAVE doesn't properly support IPv4-mapped IPv6 addresses, nor does it
// correctly support IPv4 addresses on a dual-stack socket (despite MSDN's
// claims to the contrary). To get proper QoS tagging when hosting in dual
// stack mode, we will temporarily connect() the socket to allow qWAVE to
// successfully initialize a flow, then disconnect it again so WSASendMsg()
// works later on.
if (isV4MappedV6Addr) {
connect(socket, (PSOCKADDR)&peerAddress->address, peerAddress->addressLength);
}

qosFlowId = 0; // Must be initialized to 0
pfnQOSAddSocketToFlow(qosHandle,
socket,
(struct sockaddr *)&peerAddress->address,
isV4MappedV6Addr ? NULL : (struct sockaddr *)&peerAddress->address,
QOSTrafficTypeControl,
QOS_NON_ADAPTIVE_FLOW,
&qosFlowId);

if (isV4MappedV6Addr) {
SOCKADDR_IN6 empty = { 0 };
empty.sin6_family = AF_INET6;
connect(socket, (PSOCKADDR)&empty, sizeof(empty));
}

// Even if we failed, don't try again
qosAddedFlow = TRUE;
}
Expand Down Expand Up @@ -496,10 +526,26 @@ enet_socket_send (ENetSocket socket,
NULL,
NULL) == SOCKET_ERROR)
{
if (WSAGetLastError () == WSAEWOULDBLOCK)
return 0;
switch (WSAGetLastError ())
{
case WSAEWOULDBLOCK:
return 0;

// These errors are treated as possible transient
// conditions that could be caused by a network
// interruption. We'll ignore them and allow the
// socket timeout to kill us if the connection
// is permanently interrupted.
case WSAEADDRNOTAVAIL:
case WSAENETDOWN:
case WSAENETUNREACH:
case WSAEHOSTDOWN:
case WSAEHOSTUNREACH:
return 0;

return -1;
default:
return -1;
}
}

return (int) sentLength;
Expand Down

0 comments on commit f8f5d0b

Please sign in to comment.