diff --git a/libretro-common/include/net/net_compat.h b/libretro-common/include/net/net_compat.h index d3a0894f63..8013fa85e3 100644 --- a/libretro-common/include/net/net_compat.h +++ b/libretro-common/include/net/net_compat.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010-2020 The RetroArch team +/* Copyright (C) 2010-2022 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (net_compat.h). @@ -56,6 +56,7 @@ #include +#define getsockopt net_getsockopt #define setsockopt net_setsockopt #elif defined(VITA) @@ -70,6 +71,7 @@ #define socket(a,b,c) sceNetSocket("unknown",a,b,c) #define bind sceNetBind #define accept sceNetAccept +#define getsockopt sceNetGetsockopt #define setsockopt sceNetSetsockopt #define connect sceNetConnect #define listen sceNetListen diff --git a/libretro-common/net/net_socket.c b/libretro-common/net/net_socket.c index fce8282a09..182edf2727 100644 --- a/libretro-common/net/net_socket.c +++ b/libretro-common/net/net_socket.c @@ -447,9 +447,8 @@ bool socket_connect_with_timeout(int fd, void *data, unsigned timeout) if (!isagain(res)) #if !defined(_WIN32) && defined(EINPROGRESS) if (errno != EINPROGRESS) -#else - return false; #endif + return false; FD_ZERO(&wfd); FD_ZERO(&efd); diff --git a/network/netplay/netplay.h b/network/netplay/netplay.h index 89a28e73da..0d25101df1 100644 --- a/network/netplay/netplay.h +++ b/network/netplay/netplay.h @@ -24,16 +24,15 @@ #include #include +#include + +#include #ifdef HAVE_CONFIG_H #include "../../config.h" #endif -#include -#include -#include - -#include "../../core.h" +#include "../../retroarch_types.h" #include "../natt.h" diff --git a/network/netplay/netplay_frontend.c b/network/netplay/netplay_frontend.c index b3044154ee..90e1780b42 100644 --- a/network/netplay/netplay_frontend.c +++ b/network/netplay/netplay_frontend.c @@ -23,54 +23,37 @@ #include #include #include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include #include - -#ifndef HAVE_SOCKET_LEGACY -#include -#endif +#include #include #include +#include +#include #include +#include +#include +#include +#include -#ifdef HAVE_PRESENCE -#include "../presence.h" -#endif -#ifdef HAVE_DISCORD -#include "../discord.h" -#endif - -#include "../../file_path_special.h" -#include "../../paths.h" -#include "../../content.h" - -#ifdef HAVE_CONFIG_H -#include "../../config.h" +#ifndef HAVE_SOCKET_LEGACY +#include #endif #include "../../autosave.h" #include "../../configuration.h" #include "../../command.h" #include "../../content.h" +#include "../../core.h" #include "../../driver.h" +#include "../../file_path_special.h" +#include "../../paths.h" #include "../../retroarch.h" #include "../../version.h" #include "../../verbosity.h" #include "../../tasks/tasks_internal.h" - #include "../../input/input_driver.h" #ifdef HAVE_MENU @@ -82,11 +65,14 @@ #include "../../gfx/gfx_widgets.h" #endif +#ifdef HAVE_PRESENCE +#include "../presence.h" +#endif + #ifdef HAVE_DISCORD #include "../discord.h" #endif -#include "netplay.h" #include "netplay_private.h" #if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) && !defined(_3DS) @@ -115,12 +101,15 @@ #define RECV(buf, sz) \ recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), (sz), false); \ - if (recvd >= 0 && recvd < (ssize_t) (sz)) \ + if (recvd >= 0) \ { \ - netplay_recv_reset(&connection->recv_packet_buffer); \ - return true; \ + if (recvd < (ssize_t) (sz)) \ + { \ + netplay_recv_reset(&connection->recv_packet_buffer); \ + return true; \ + } \ } \ - else if (recvd < 0) + else #define SET_PING(connection) \ ping = (int32_t)((cpu_features_get_time_usec() - (connection)->ping_timer) / 1000); \ @@ -213,35 +202,6 @@ net_driver_state_t *networking_state_get_ptr(void) return &networking_driver_st; } -#ifdef HAVE_SOCKET_LEGACY -#ifndef htons -/* The fact that I need to write this is deeply depressing */ -static int16_t htons_for_morons(int16_t value) -{ - union { - int32_t l; - int16_t s[2]; - } val; - val.l = htonl(value); - return val.s[1]; -} -#define htons htons_for_morons -#endif - -#ifndef ntohs -static int16_t ntohs_for_morons(int16_t value) -{ - union { - int32_t l; - int16_t s[2]; - } val; - val.l = ntohl(value); - return val.l == value ? val.s[1] : val.s[0]; -} -#define ntohs ntohs_for_morons -#endif -#endif - #ifdef HAVE_NETPLAYDISCOVERY /** Initialize Netplay discovery (client) */ bool init_netplay_discovery(void) @@ -3292,19 +3252,18 @@ static bool netplay_tunnel_connect(int fd, const struct addrinfo *addr) { int result; - SET_TCP_NODELAY(fd) - SET_FD_CLOEXEC(fd) - if (!socket_nonblock(fd)) return false; result = socket_connect(fd, (void*) addr, false); if (result && !isagain(result)) #if !defined(_WIN32) && defined(EINPROGRESS) - return result < 0 && errno == EINPROGRESS; -#else - return false; + if (errno != EINPROGRESS) #endif + return false; + + SET_TCP_NODELAY(fd) + SET_FD_CLOEXEC(fd) return true; } @@ -5116,10 +5075,13 @@ static void answer_ping(netplay_t *netplay, #undef RECV #define RECV(buf, sz) \ -recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), \ -(sz), false); \ -if (recvd >= 0 && recvd < (ssize_t) (sz)) goto shrt; \ -else if (recvd < 0) + recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), (sz), false); \ + if (recvd >= 0) \ + { \ + if (recvd < (ssize_t) (sz)) \ + goto shrt; \ + } \ + else static bool netplay_get_cmd(netplay_t *netplay, struct netplay_connection *connection, bool *had_input) @@ -7977,11 +7939,7 @@ static void netplay_announce(netplay_t *netplay) struct netplay_room *host_room = &net_st->host_room; struct retro_system_info *system = &runloop_state_get_ptr()->system.info; struct string_list *subsystem = path_get_subsystem_list(); -#ifndef NETPLAY_TEST_BUILD - const char *url = "http://lobby.libretro.com/add"; -#else - const char *url = "http://lobbytest.libretro.com/add"; -#endif + const char *url = FILE_PATH_LOBBY_LIBRETRO_URL "add"; net_http_urlencode(&username, netplay->nick); @@ -8187,11 +8145,7 @@ static bool netplay_mitm_query(const char *mitm_name) else { char query[512]; -#ifndef NETPLAY_TEST_BUILD - const char *url = "http://lobby.libretro.com/tunnel"; -#else - const char *url = "http://lobbytest.libretro.com/tunnel"; -#endif + const char *url = FILE_PATH_LOBBY_LIBRETRO_URL "tunnel"; snprintf(query, sizeof(query), "%s?name=%s", url, mitm_name); diff --git a/network/netplay/netplay_private.h b/network/netplay/netplay_private.h index 70ddec698a..b4753c5f25 100644 --- a/network/netplay/netplay_private.h +++ b/network/netplay/netplay_private.h @@ -21,13 +21,8 @@ #include "netplay.h" -#include -#include #include -#include "../../msg_hash.h" -#include "../../verbosity.h" - #define RARCH_DEFAULT_PORT 55435 #define RARCH_DEFAULT_NICK "Anonymous" @@ -49,9 +44,9 @@ typedef uint32_t client_bitmap_t; * callbacks are in use, we assign a pseudodevice for it */ #define RETRO_DEVICE_NETPLAY_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 65535) -#define NETPLAY_MAX_STALL_FRAMES 60 -#define NETPLAY_FRAME_RUN_TIME_WINDOW 120 -#define NETPLAY_MAX_REQ_STALL_TIME 60 +#define NETPLAY_MAX_STALL_FRAMES 60 +#define NETPLAY_FRAME_RUN_TIME_WINDOW 120 +#define NETPLAY_MAX_REQ_STALL_TIME 60 #define NETPLAY_MAX_REQ_STALL_FREQUENCY 120 #define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1) @@ -66,13 +61,15 @@ typedef uint32_t client_bitmap_t; #define NETPLAY_QUIRK_PLATFORM_DEPENDENT (1<<4) /* Mapping of serialization quirks to netplay quirks. */ -#define NETPLAY_QUIRK_MAP_UNDERSTOOD \ - (RETRO_SERIALIZATION_QUIRK_INCOMPLETE \ - |RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE \ - |RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE \ - |RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION \ - |RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT \ - |RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT) +#define NETPLAY_QUIRK_MAP_UNDERSTOOD (\ + RETRO_SERIALIZATION_QUIRK_INCOMPLETE |\ + RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE |\ + RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE |\ + RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION |\ + RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT |\ + RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT \ +) + #define NETPLAY_QUIRK_MAP_NO_SAVESTATES \ (RETRO_SERIALIZATION_QUIRK_INCOMPLETE) #define NETPLAY_QUIRK_MAP_NO_TRANSMISSION \ diff --git a/network/netplay/netplay_room_parse.c b/network/netplay/netplay_room_parse.c index 2ab4056c71..f8424c2318 100644 --- a/network/netplay/netplay_room_parse.c +++ b/network/netplay/netplay_room_parse.c @@ -18,13 +18,14 @@ #include #include -#include + #include -#include #include -#include "netplay.h" + #include "../../verbosity.h" +#include "netplay.h" + enum netplay_parse_state { STATE_START = 0, diff --git a/wii/libogc/include/network.h b/wii/libogc/include/network.h index dd6fcca4bd..8c28dcf04c 100644 --- a/wii/libogc/include/network.h +++ b/wii/libogc/include/network.h @@ -268,6 +268,7 @@ s32 net_recvfrom(s32 s,void *mem,s32 len,u32 flags,struct sockaddr *from,socklen s32 net_read(s32 s,void *mem,s32 len); s32 net_close(s32 s); s32 net_select(s32 maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout); +s32 net_getsockopt(s32 s,u32 level,u32 optname,void *optval,socklen_t *optlen); s32 net_setsockopt(s32 s,u32 level,u32 optname,const void *optval,socklen_t optlen); s32 net_ioctl(s32 s, u32 cmd, void *argp); s32 net_fcntl(s32 s, u32 cmd, u32 flags); diff --git a/wii/libogc/libogc/network_wii.c b/wii/libogc/libogc/network_wii.c index 5ac1f409d9..087df1d56c 100644 --- a/wii/libogc/libogc/network_wii.c +++ b/wii/libogc/libogc/network_wii.c @@ -997,6 +997,14 @@ s32 net_select(s32 maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset return -EINVAL; } +s32 net_getsockopt(s32 s, u32 level, u32 optname, void *optval, socklen_t *optlen) +{ + /* TODO/FIXME: Implement getsockopt */ + memset(optval, 0, *optlen); + + return 0; +} + s32 net_setsockopt(s32 s, u32 level, u32 optname, const void *optval, socklen_t optlen) { s32 ret; diff --git a/wii/libogc/lwip/network.c b/wii/libogc/lwip/network.c index 74be92da9e..1b1a8f59db 100644 --- a/wii/libogc/lwip/network.c +++ b/wii/libogc/lwip/network.c @@ -2096,6 +2096,14 @@ s32 net_select(s32 maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,st return nready; } +s32 net_getsockopt(s32 s, u32 level, u32 optname, void *optval, socklen_t *optlen) +{ + /* TODO/FIXME: Implement getsockopt */ + memset(optval, 0, *optlen); + + return 0; +} + s32 net_setsockopt(s32 s,u32 level,u32 optname,const void *optval,socklen_t optlen) { s32 err = 0;