mirror of
https://github.com/libretro/RetroArch.git
synced 2025-04-02 10:51:52 -04:00
open different sockets per-user
This commit is contained in:
parent
ef3a07c515
commit
ac1695e7fd
6 changed files with 41 additions and 25 deletions
|
@ -81,14 +81,12 @@ static void event_init_remote(void)
|
|||
driver_t *driver = driver_get_ptr();
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
for(int i=0; i < settings->input.max_users; i++)
|
||||
if (settings->network_remote_enable)
|
||||
{
|
||||
if (settings->network_remote_enable[i])
|
||||
{
|
||||
if (!(driver->remote = rarch_remote_new(55400 + i,i)))
|
||||
RARCH_ERR("Failed to initialize remote gamepad interface.\n");
|
||||
}
|
||||
if (!(driver->remote = rarch_remote_new(settings->network_remote_base_port)))
|
||||
RARCH_ERR("Failed to initialize remote gamepad interface.\n");
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1627,12 +1627,12 @@ static bool config_load_file(const char *path, bool set_defaults)
|
|||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
|
||||
CONFIG_GET_BOOL_BASE(conf, settings, network_remote_enable, "network_remote_enable");
|
||||
for (int i=0; i < MAX_USERS; i++)
|
||||
{
|
||||
char tmp[64] = {0};
|
||||
snprintf(tmp, sizeof(tmp), "network_remote_enable_p%u", i + 1);
|
||||
config_get_bool(conf, tmp, &settings->network_remote_enable[i]);
|
||||
snprintf(tmp, sizeof(tmp), "network_remote_enable_user_p%u", i + 1);
|
||||
config_get_bool(conf, tmp, &settings->network_remote_enable_user[i]);
|
||||
}
|
||||
CONFIG_GET_INT_BASE(conf, settings, network_remote_base_port, "network_remote_base_port");
|
||||
|
||||
|
@ -2784,9 +2784,10 @@ bool config_save_file(const char *path)
|
|||
for (int i=0; i < MAX_USERS; i++)
|
||||
{
|
||||
char tmp[64] = {0};
|
||||
snprintf(tmp, sizeof(tmp), "network_remote_enable_p%u", i + 1);
|
||||
config_set_bool(conf, tmp, settings->network_remote_enable[i]);
|
||||
snprintf(tmp, sizeof(tmp), "network_remote_enable_user_p%u", i + 1);
|
||||
config_set_bool(conf, tmp, settings->network_remote_enable_user[i]);
|
||||
}
|
||||
config_set_bool(conf, "network_remote_enable", settings->network_remote_enable);
|
||||
config_set_int(conf, "network_remote_base_port", settings->network_remote_base_port);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -347,7 +347,8 @@ typedef struct settings
|
|||
bool network_cmd_enable;
|
||||
unsigned network_cmd_port;
|
||||
bool stdin_cmd_enable;
|
||||
bool network_remote_enable[MAX_USERS];
|
||||
bool network_remote_enable;
|
||||
bool network_remote_enable_user[MAX_USERS];
|
||||
unsigned network_remote_base_port;
|
||||
bool debug_panel_enable;
|
||||
|
||||
|
|
|
@ -460,6 +460,11 @@ void input_poll(void)
|
|||
if (driver->command)
|
||||
rarch_cmd_poll(driver->command);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NETWORK_GAMEPAD
|
||||
/*if (driver->remote)
|
||||
rarch_remote_poll(driver->remote);*/
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
35
remote.c
35
remote.c
|
@ -43,7 +43,7 @@ struct rarch_remote
|
|||
{
|
||||
|
||||
#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
|
||||
int net_fd;
|
||||
int net_fd[MAX_USERS];
|
||||
#endif
|
||||
|
||||
bool state[RARCH_BIND_LIST_END];
|
||||
|
@ -57,6 +57,8 @@ static bool remote_init_network(rarch_remote_t *handle, uint16_t port, unsigned
|
|||
struct addrinfo *res = NULL;
|
||||
int yes = 1;
|
||||
|
||||
port = port + user;
|
||||
|
||||
if (!network_init())
|
||||
return false;
|
||||
|
||||
|
@ -76,17 +78,17 @@ static bool remote_init_network(rarch_remote_t *handle, uint16_t port, unsigned
|
|||
if (getaddrinfo_retro(NULL, port_buf, &hints, &res) < 0)
|
||||
goto error;
|
||||
|
||||
handle->net_fd = socket(res->ai_family,
|
||||
handle->net_fd[user] = socket(res->ai_family,
|
||||
res->ai_socktype, res->ai_protocol);
|
||||
if (handle->net_fd < 0)
|
||||
if (handle->net_fd[user] < 0)
|
||||
goto error;
|
||||
|
||||
if (!socket_nonblock(handle->net_fd))
|
||||
if (!socket_nonblock(handle->net_fd[user]))
|
||||
goto error;
|
||||
|
||||
setsockopt(handle->net_fd, SOL_SOCKET,
|
||||
setsockopt(handle->net_fd[user], SOL_SOCKET,
|
||||
SO_REUSEADDR, (const char*)&yes, sizeof(int));
|
||||
if (bind(handle->net_fd, res->ai_addr, res->ai_addrlen) < 0)
|
||||
if (bind(handle->net_fd[user], res->ai_addr, res->ai_addrlen) < 0)
|
||||
{
|
||||
RARCH_ERR("Failed to bind socket.\n");
|
||||
goto error;
|
||||
|
@ -102,18 +104,24 @@ error:
|
|||
}
|
||||
#endif
|
||||
|
||||
rarch_remote_t *rarch_remote_new(uint16_t port, unsigned user)
|
||||
rarch_remote_t *rarch_remote_new(uint16_t port)
|
||||
{
|
||||
rarch_remote_t *handle = (rarch_remote_t*)calloc(1, sizeof(*handle));
|
||||
settings_t *settings = config_get_ptr();
|
||||
if (!handle)
|
||||
return NULL;
|
||||
|
||||
(void)port;
|
||||
|
||||
#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
|
||||
handle->net_fd = -1;
|
||||
if (!remote_init_network(handle, port, user))
|
||||
goto error;
|
||||
for(int user = 0; user < MAX_USERS; user ++)
|
||||
{
|
||||
handle->net_fd[user] = -1;
|
||||
if(settings->network_remote_enable_user[user])
|
||||
if (!remote_init_network(handle, port, user))
|
||||
goto error;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return handle;
|
||||
|
@ -128,8 +136,11 @@ error:
|
|||
void rarch_remote_free(rarch_remote_t *handle)
|
||||
{
|
||||
#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
|
||||
if (handle && handle->net_fd >= 0)
|
||||
socket_close(handle->net_fd);
|
||||
for(int user = 0; user < MAX_USERS; user ++)
|
||||
{
|
||||
socket_close(handle->net_fd[user]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
free(handle);
|
||||
|
|
2
remote.h
2
remote.h
|
@ -30,7 +30,7 @@ extern "C" {
|
|||
|
||||
typedef struct rarch_remote rarch_remote_t;
|
||||
|
||||
rarch_remote_t *rarch_remote_new(uint16_t port, unsigned user);
|
||||
rarch_remote_t *rarch_remote_new(uint16_t port);
|
||||
|
||||
void rarch_remote_free(rarch_remote_t *handle);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue