mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 22:13:51 +00:00
Create socket_bind
This commit is contained in:
parent
78bb85e2f3
commit
004d9a613c
@ -124,7 +124,6 @@ static const struct cmd_map map[] = {
|
||||
static bool cmd_init_network(rarch_cmd_t *handle, uint16_t port)
|
||||
{
|
||||
struct addrinfo *res = NULL;
|
||||
int yes = 1;
|
||||
|
||||
RARCH_LOG("Bringing up command interface on port %hu.\n",
|
||||
(unsigned short)port);
|
||||
@ -137,9 +136,7 @@ static bool cmd_init_network(rarch_cmd_t *handle, uint16_t port)
|
||||
if (!socket_nonblock(handle->net_fd))
|
||||
goto error;
|
||||
|
||||
setsockopt(handle->net_fd, SOL_SOCKET,
|
||||
SO_REUSEADDR, (const char*)&yes, sizeof(int));
|
||||
if (bind(handle->net_fd, res->ai_addr, res->ai_addrlen) < 0)
|
||||
if (!socket_bind(handle->net_fd, res))
|
||||
{
|
||||
RARCH_ERR("Failed to bind socket.\n");
|
||||
goto error;
|
||||
|
@ -50,6 +50,8 @@ int socket_send_all_blocking(int fd, const void *data_, size_t size);
|
||||
|
||||
int socket_receive_all_blocking(int fd, void *data_, size_t size);
|
||||
|
||||
bool socket_bind(int fd, void *data);
|
||||
|
||||
RETRO_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -154,3 +154,14 @@ int socket_send_all_blocking(int fd, const void *data_, size_t size)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool socket_bind(int fd, void *data)
|
||||
{
|
||||
int yes = 1;
|
||||
struct addrinfo *res = (struct addrinfo*)data;
|
||||
setsockopt(fd, SOL_SOCKET,
|
||||
SO_REUSEADDR, (const char*)&yes, sizeof(int));
|
||||
if (bind(fd, res->ai_addr, res->ai_addrlen) < 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user