Add socket_type to socket_init

This commit is contained in:
twinaphex 2016-05-01 22:25:23 +02:00
parent d2a80e26db
commit 8b9456f419
4 changed files with 20 additions and 5 deletions

View File

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

View File

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

View File

@ -24,7 +24,7 @@
#include <net/net_compat.h>
#include <net/net_socket.h>
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
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;

View File

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