diff --git a/command.c b/command.c index 81e8443521..2fdcef7b13 100644 --- a/command.c +++ b/command.c @@ -130,7 +130,7 @@ static bool cmd_init_network(rarch_cmd_t *handle, uint16_t port) RARCH_LOG("Bringing up command interface on port %hu.\n", (unsigned short)port); - if (!socket_init(res, file_desc, port, NULL)) + if (!socket_init(res, file_desc, port, NULL, SOCKET_TYPE_DATAGRAM)) goto error; if (*file_desc < 0) diff --git a/libretro-common/include/net/net_socket.h b/libretro-common/include/net/net_socket.h index d0dfac95e4..742c973315 100644 --- a/libretro-common/include/net/net_socket.h +++ b/libretro-common/include/net/net_socket.h @@ -31,7 +31,13 @@ RETRO_BEGIN_DECLS -bool socket_init(void *address, int *fd, uint16_t port, const char *server); +enum socket_type +{ + SOCKET_TYPE_DATAGRAM = 0, + SOCKET_TYPE_STREAM +}; + +bool socket_init(void *address, int *fd, uint16_t port, const char *server, enum socket_type type); int socket_close(int fd); diff --git a/libretro-common/net/net_socket.c b/libretro-common/net/net_socket.c index ce02827a46..fd0f640f66 100644 --- a/libretro-common/net/net_socket.c +++ b/libretro-common/net/net_socket.c @@ -24,7 +24,7 @@ #include #include -bool socket_init(void *address, int *fd, uint16_t port, const char *server) +bool socket_init(void *address, int *fd, uint16_t port, const char *server, enum socket_type type) { char port_buf[16] = {0}; struct addrinfo hints = {0}; @@ -41,7 +41,16 @@ bool socket_init(void *address, int *fd, uint16_t port, const char *server) #else hints.ai_family = AF_UNSPEC; #endif - hints.ai_socktype = SOCK_DGRAM; + + switch (type) + { + case SOCKET_TYPE_DATAGRAM: + hints.ai_socktype = SOCK_DGRAM; + break; + case SOCKET_TYPE_STREAM: + hints.ai_socktype = SOCK_STREAM; + break; + } if (!server) hints.ai_flags = AI_PASSIVE; diff --git a/netplay/netplay.c b/netplay/netplay.c index 785baf205a..0c660976d7 100644 --- a/netplay/netplay.c +++ b/netplay/netplay.c @@ -763,7 +763,7 @@ static bool init_udp_socket(netplay_t *netplay, const char *server, uint16_t port) { int *file_desc = (int*)&netplay->udp_fd; - if (!socket_init(&netplay->addr, file_desc, port, server)) + if (!socket_init(&netplay->addr, file_desc, port, server, SOCKET_TYPE_DATAGRAM)) return false; if (*file_desc < 0)