mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-26 17:50:56 +00:00
(Netplay) Some cleaning
This commit is contained in:
parent
5e258eb8f0
commit
17b7b1322e
@ -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).
|
* The following license statement only applies to this file (net_compat.h).
|
||||||
@ -56,6 +56,7 @@
|
|||||||
|
|
||||||
#include <network.h>
|
#include <network.h>
|
||||||
|
|
||||||
|
#define getsockopt net_getsockopt
|
||||||
#define setsockopt net_setsockopt
|
#define setsockopt net_setsockopt
|
||||||
|
|
||||||
#elif defined(VITA)
|
#elif defined(VITA)
|
||||||
@ -70,6 +71,7 @@
|
|||||||
#define socket(a,b,c) sceNetSocket("unknown",a,b,c)
|
#define socket(a,b,c) sceNetSocket("unknown",a,b,c)
|
||||||
#define bind sceNetBind
|
#define bind sceNetBind
|
||||||
#define accept sceNetAccept
|
#define accept sceNetAccept
|
||||||
|
#define getsockopt sceNetGetsockopt
|
||||||
#define setsockopt sceNetSetsockopt
|
#define setsockopt sceNetSetsockopt
|
||||||
#define connect sceNetConnect
|
#define connect sceNetConnect
|
||||||
#define listen sceNetListen
|
#define listen sceNetListen
|
||||||
|
@ -447,9 +447,8 @@ bool socket_connect_with_timeout(int fd, void *data, unsigned timeout)
|
|||||||
if (!isagain(res))
|
if (!isagain(res))
|
||||||
#if !defined(_WIN32) && defined(EINPROGRESS)
|
#if !defined(_WIN32) && defined(EINPROGRESS)
|
||||||
if (errno != EINPROGRESS)
|
if (errno != EINPROGRESS)
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
#endif
|
||||||
|
return false;
|
||||||
|
|
||||||
FD_ZERO(&wfd);
|
FD_ZERO(&wfd);
|
||||||
FD_ZERO(&efd);
|
FD_ZERO(&efd);
|
||||||
|
@ -24,16 +24,15 @@
|
|||||||
|
|
||||||
#include <boolean.h>
|
#include <boolean.h>
|
||||||
#include <libretro.h>
|
#include <libretro.h>
|
||||||
|
#include <retro_miscellaneous.h>
|
||||||
|
|
||||||
|
#include <net/net_compat.h>
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "../../config.h"
|
#include "../../config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <net/net_compat.h>
|
#include "../../retroarch_types.h"
|
||||||
#include <net/net_ifinfo.h>
|
|
||||||
#include <retro_miscellaneous.h>
|
|
||||||
|
|
||||||
#include "../../core.h"
|
|
||||||
|
|
||||||
#include "../natt.h"
|
#include "../natt.h"
|
||||||
|
|
||||||
|
@ -23,54 +23,37 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.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>
|
#include <retro_timers.h>
|
||||||
|
#include <retro_assert.h>
|
||||||
#ifndef HAVE_SOCKET_LEGACY
|
|
||||||
#include <net/net_ifinfo.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <math/float_minmax.h>
|
#include <math/float_minmax.h>
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
|
#include <net/net_socket.h>
|
||||||
|
#include <net/net_http.h>
|
||||||
#include <file/file_path.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
|
#ifndef HAVE_SOCKET_LEGACY
|
||||||
#include "../presence.h"
|
#include <net/net_ifinfo.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"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../../autosave.h"
|
#include "../../autosave.h"
|
||||||
#include "../../configuration.h"
|
#include "../../configuration.h"
|
||||||
#include "../../command.h"
|
#include "../../command.h"
|
||||||
#include "../../content.h"
|
#include "../../content.h"
|
||||||
|
#include "../../core.h"
|
||||||
#include "../../driver.h"
|
#include "../../driver.h"
|
||||||
|
#include "../../file_path_special.h"
|
||||||
|
#include "../../paths.h"
|
||||||
#include "../../retroarch.h"
|
#include "../../retroarch.h"
|
||||||
#include "../../version.h"
|
#include "../../version.h"
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
#include "../../tasks/tasks_internal.h"
|
#include "../../tasks/tasks_internal.h"
|
||||||
|
|
||||||
#include "../../input/input_driver.h"
|
#include "../../input/input_driver.h"
|
||||||
|
|
||||||
#ifdef HAVE_MENU
|
#ifdef HAVE_MENU
|
||||||
@ -82,11 +65,14 @@
|
|||||||
#include "../../gfx/gfx_widgets.h"
|
#include "../../gfx/gfx_widgets.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_PRESENCE
|
||||||
|
#include "../presence.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DISCORD
|
#ifdef HAVE_DISCORD
|
||||||
#include "../discord.h"
|
#include "../discord.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "netplay.h"
|
|
||||||
#include "netplay_private.h"
|
#include "netplay_private.h"
|
||||||
|
|
||||||
#if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) && !defined(_3DS)
|
#if defined(AF_INET6) && !defined(HAVE_SOCKET_LEGACY) && !defined(_3DS)
|
||||||
@ -115,12 +101,15 @@
|
|||||||
|
|
||||||
#define RECV(buf, sz) \
|
#define RECV(buf, sz) \
|
||||||
recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), (sz), false); \
|
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); \
|
if (recvd < (ssize_t) (sz)) \
|
||||||
return true; \
|
{ \
|
||||||
|
netplay_recv_reset(&connection->recv_packet_buffer); \
|
||||||
|
return true; \
|
||||||
|
} \
|
||||||
} \
|
} \
|
||||||
else if (recvd < 0)
|
else
|
||||||
|
|
||||||
#define SET_PING(connection) \
|
#define SET_PING(connection) \
|
||||||
ping = (int32_t)((cpu_features_get_time_usec() - (connection)->ping_timer) / 1000); \
|
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;
|
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
|
#ifdef HAVE_NETPLAYDISCOVERY
|
||||||
/** Initialize Netplay discovery (client) */
|
/** Initialize Netplay discovery (client) */
|
||||||
bool init_netplay_discovery(void)
|
bool init_netplay_discovery(void)
|
||||||
@ -3292,19 +3252,18 @@ static bool netplay_tunnel_connect(int fd, const struct addrinfo *addr)
|
|||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
SET_TCP_NODELAY(fd)
|
|
||||||
SET_FD_CLOEXEC(fd)
|
|
||||||
|
|
||||||
if (!socket_nonblock(fd))
|
if (!socket_nonblock(fd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
result = socket_connect(fd, (void*) addr, false);
|
result = socket_connect(fd, (void*) addr, false);
|
||||||
if (result && !isagain(result))
|
if (result && !isagain(result))
|
||||||
#if !defined(_WIN32) && defined(EINPROGRESS)
|
#if !defined(_WIN32) && defined(EINPROGRESS)
|
||||||
return result < 0 && errno == EINPROGRESS;
|
if (errno != EINPROGRESS)
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
#endif
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SET_TCP_NODELAY(fd)
|
||||||
|
SET_FD_CLOEXEC(fd)
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -5116,10 +5075,13 @@ static void answer_ping(netplay_t *netplay,
|
|||||||
|
|
||||||
#undef RECV
|
#undef RECV
|
||||||
#define RECV(buf, sz) \
|
#define RECV(buf, sz) \
|
||||||
recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), \
|
recvd = netplay_recv(&connection->recv_packet_buffer, connection->fd, (buf), (sz), false); \
|
||||||
(sz), false); \
|
if (recvd >= 0) \
|
||||||
if (recvd >= 0 && recvd < (ssize_t) (sz)) goto shrt; \
|
{ \
|
||||||
else if (recvd < 0)
|
if (recvd < (ssize_t) (sz)) \
|
||||||
|
goto shrt; \
|
||||||
|
} \
|
||||||
|
else
|
||||||
|
|
||||||
static bool netplay_get_cmd(netplay_t *netplay,
|
static bool netplay_get_cmd(netplay_t *netplay,
|
||||||
struct netplay_connection *connection, bool *had_input)
|
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 netplay_room *host_room = &net_st->host_room;
|
||||||
struct retro_system_info *system = &runloop_state_get_ptr()->system.info;
|
struct retro_system_info *system = &runloop_state_get_ptr()->system.info;
|
||||||
struct string_list *subsystem = path_get_subsystem_list();
|
struct string_list *subsystem = path_get_subsystem_list();
|
||||||
#ifndef NETPLAY_TEST_BUILD
|
const char *url = FILE_PATH_LOBBY_LIBRETRO_URL "add";
|
||||||
const char *url = "http://lobby.libretro.com/add";
|
|
||||||
#else
|
|
||||||
const char *url = "http://lobbytest.libretro.com/add";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
net_http_urlencode(&username, netplay->nick);
|
net_http_urlencode(&username, netplay->nick);
|
||||||
|
|
||||||
@ -8187,11 +8145,7 @@ static bool netplay_mitm_query(const char *mitm_name)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char query[512];
|
char query[512];
|
||||||
#ifndef NETPLAY_TEST_BUILD
|
const char *url = FILE_PATH_LOBBY_LIBRETRO_URL "tunnel";
|
||||||
const char *url = "http://lobby.libretro.com/tunnel";
|
|
||||||
#else
|
|
||||||
const char *url = "http://lobbytest.libretro.com/tunnel";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
snprintf(query, sizeof(query), "%s?name=%s", url, mitm_name);
|
snprintf(query, sizeof(query), "%s?name=%s", url, mitm_name);
|
||||||
|
|
||||||
|
@ -21,13 +21,8 @@
|
|||||||
|
|
||||||
#include "netplay.h"
|
#include "netplay.h"
|
||||||
|
|
||||||
#include <net/net_compat.h>
|
|
||||||
#include <features/features_cpu.h>
|
|
||||||
#include <streams/trans_stream.h>
|
#include <streams/trans_stream.h>
|
||||||
|
|
||||||
#include "../../msg_hash.h"
|
|
||||||
#include "../../verbosity.h"
|
|
||||||
|
|
||||||
#define RARCH_DEFAULT_PORT 55435
|
#define RARCH_DEFAULT_PORT 55435
|
||||||
#define RARCH_DEFAULT_NICK "Anonymous"
|
#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 */
|
* callbacks are in use, we assign a pseudodevice for it */
|
||||||
#define RETRO_DEVICE_NETPLAY_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 65535)
|
#define RETRO_DEVICE_NETPLAY_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 65535)
|
||||||
|
|
||||||
#define NETPLAY_MAX_STALL_FRAMES 60
|
#define NETPLAY_MAX_STALL_FRAMES 60
|
||||||
#define NETPLAY_FRAME_RUN_TIME_WINDOW 120
|
#define NETPLAY_FRAME_RUN_TIME_WINDOW 120
|
||||||
#define NETPLAY_MAX_REQ_STALL_TIME 60
|
#define NETPLAY_MAX_REQ_STALL_TIME 60
|
||||||
#define NETPLAY_MAX_REQ_STALL_FREQUENCY 120
|
#define NETPLAY_MAX_REQ_STALL_FREQUENCY 120
|
||||||
|
|
||||||
#define PREV_PTR(x) ((x) == 0 ? netplay->buffer_size - 1 : (x) - 1)
|
#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)
|
#define NETPLAY_QUIRK_PLATFORM_DEPENDENT (1<<4)
|
||||||
|
|
||||||
/* Mapping of serialization quirks to netplay quirks. */
|
/* Mapping of serialization quirks to netplay quirks. */
|
||||||
#define NETPLAY_QUIRK_MAP_UNDERSTOOD \
|
#define NETPLAY_QUIRK_MAP_UNDERSTOOD (\
|
||||||
(RETRO_SERIALIZATION_QUIRK_INCOMPLETE \
|
RETRO_SERIALIZATION_QUIRK_INCOMPLETE |\
|
||||||
|RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE \
|
RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE |\
|
||||||
|RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE \
|
RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE |\
|
||||||
|RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION \
|
RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION |\
|
||||||
|RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT \
|
RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT |\
|
||||||
|RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT)
|
RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT \
|
||||||
|
)
|
||||||
|
|
||||||
#define NETPLAY_QUIRK_MAP_NO_SAVESTATES \
|
#define NETPLAY_QUIRK_MAP_NO_SAVESTATES \
|
||||||
(RETRO_SERIALIZATION_QUIRK_INCOMPLETE)
|
(RETRO_SERIALIZATION_QUIRK_INCOMPLETE)
|
||||||
#define NETPLAY_QUIRK_MAP_NO_TRANSMISSION \
|
#define NETPLAY_QUIRK_MAP_NO_TRANSMISSION \
|
||||||
|
@ -18,13 +18,14 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <string/stdstring.h>
|
#include <string/stdstring.h>
|
||||||
#include <compat/strl.h>
|
|
||||||
#include <formats/rjson.h>
|
#include <formats/rjson.h>
|
||||||
#include "netplay.h"
|
|
||||||
#include "../../verbosity.h"
|
#include "../../verbosity.h"
|
||||||
|
|
||||||
|
#include "netplay.h"
|
||||||
|
|
||||||
enum netplay_parse_state
|
enum netplay_parse_state
|
||||||
{
|
{
|
||||||
STATE_START = 0,
|
STATE_START = 0,
|
||||||
|
@ -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_read(s32 s,void *mem,s32 len);
|
||||||
s32 net_close(s32 s);
|
s32 net_close(s32 s);
|
||||||
s32 net_select(s32 maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,struct timeval *timeout);
|
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_setsockopt(s32 s,u32 level,u32 optname,const void *optval,socklen_t optlen);
|
||||||
s32 net_ioctl(s32 s, u32 cmd, void *argp);
|
s32 net_ioctl(s32 s, u32 cmd, void *argp);
|
||||||
s32 net_fcntl(s32 s, u32 cmd, u32 flags);
|
s32 net_fcntl(s32 s, u32 cmd, u32 flags);
|
||||||
|
@ -997,6 +997,14 @@ s32 net_select(s32 maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset
|
|||||||
return -EINVAL;
|
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 net_setsockopt(s32 s, u32 level, u32 optname, const void *optval, socklen_t optlen)
|
||||||
{
|
{
|
||||||
s32 ret;
|
s32 ret;
|
||||||
|
@ -2096,6 +2096,14 @@ s32 net_select(s32 maxfdp1,fd_set *readset,fd_set *writeset,fd_set *exceptset,st
|
|||||||
return nready;
|
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 net_setsockopt(s32 s,u32 level,u32 optname,const void *optval,socklen_t optlen)
|
||||||
{
|
{
|
||||||
s32 err = 0;
|
s32 err = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user