Skip to content

Commit

Permalink
Pull in RoblKyogre's 3DS polling behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
zoey jodon committed Jan 4, 2024
1 parent 16eefb4 commit 90d3400
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,16 @@ enet_address_make_v4mapped (ENetAddress * address)
ENetAddress oldAddress = *address;
struct sockaddr_in *sin = ((struct sockaddr_in *)&oldAddress.address);
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&address->address;

memset(sin6, 0, sizeof(*sin6));
sin6->sin6_family = AF_INET6;
sin6->sin6_len = sizeof(*sin6);
sin6->sin6_port = sin->sin_port;

sin6->sin6_addr.s6_addr[10] = 0xFF;
sin6->sin6_addr.s6_addr[11] = 0xFF;
memcpy(&sin6->sin6_addr.s6_addr[12], &sin->sin_addr, 4);

address->addressLength = sizeof(*sin6);
}
#endif
Expand Down Expand Up @@ -752,7 +752,7 @@ enet_socket_receive (ENetSocket socket,

if (peerAddress != NULL) {
peerAddress -> addressLength = msgHdr.msg_namelen;

#ifdef __APPLE__
// HACK: Apple platforms return AF_INET addresses in msg_name from recvmsg() on dual-stack sockets
// instead of AF_INET6 addresses then rejects those same addresses when they are passed to sendmsg().
Expand Down Expand Up @@ -795,7 +795,16 @@ enet_socket_wait (ENetSocket socket, enet_uint32 * condition, enet_uint32 timeou
if (* condition & ENET_SOCKET_WAIT_RECEIVE)
pollSocket.events |= POLLIN;

#if defined(__3DS__)
for (int i = 0; i < timeout; i++) {
pollCount = poll(& pollSocket, 1, 1); // need to do this on 3ds since poll will block even if socket is ready before
if (pollCount) {
break;
}
}
#else
pollCount = poll (& pollSocket, 1, timeout);
#endif

if (pollCount < 0)
{
Expand Down

0 comments on commit 90d3400

Please sign in to comment.