(Netplay) Some cleaning

pull/13989/head
Cthulhu-throwaway 2022-05-30 20:58:57 -03:00
parent 5e258eb8f0
commit 17b7b1322e
9 changed files with 78 additions and 109 deletions

View File

@ -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 <network.h>
#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

View File

@ -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);

View File

@ -24,16 +24,15 @@
#include <boolean.h>
#include <libretro.h>
#include <retro_miscellaneous.h>
#include <net/net_compat.h>
#ifdef HAVE_CONFIG_H
#include "../../config.h"
#endif
#include <net/net_compat.h>
#include <net/net_ifinfo.h>
#include <retro_miscellaneous.h>
#include "../../core.h"
#include "../../retroarch_types.h"
#include "../natt.h"

View File

@ -23,54 +23,37 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#include <boolean.h>
#include <retro_assert.h>
#include <compat/strl.h>
#include <net/net_compat.h>
#include <net/net_socket.h>
#include <net/net_http.h>
#include <encodings/crc32.h>
#include <encodings/base64.h>
#include <lrc_hash.h>
#include <retro_timers.h>
#ifndef HAVE_SOCKET_LEGACY
#include <net/net_ifinfo.h>
#endif
#include <retro_assert.h>
#include <math/float_minmax.h>
#include <string/stdstring.h>
#include <net/net_socket.h>
#include <net/net_http.h>
#include <file/file_path.h>
#include <encodings/crc32.h>
#include <encodings/base64.h>
#include <features/features_cpu.h>
#include <lrc_hash.h>
#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 <net/net_ifinfo.h>
#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);

View File

@ -21,13 +21,8 @@
#include "netplay.h"
#include <net/net_compat.h>
#include <features/features_cpu.h>
#include <streams/trans_stream.h>
#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 \

View File

@ -18,13 +18,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <string/stdstring.h>
#include <compat/strl.h>
#include <formats/rjson.h>
#include "netplay.h"
#include "../../verbosity.h"
#include "netplay.h"
enum netplay_parse_state
{
STATE_START = 0,

View File

@ -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);

View File

@ -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;

View File

@ -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;