From d05e39274ca4ce27ddb02c0ec15c0ed1c46000a3 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Mon, 13 Apr 2015 08:32:33 -0400 Subject: [PATCH] Make tox_new return TOX_ERR_NEW_PORT_ALLOC for all socket related errors. --- toxcore/network.c | 14 +++++++++++++- toxcore/network.h | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/toxcore/network.c b/toxcore/network.c index b3df3fbd..e1f845d2 100644 --- a/toxcore/network.c +++ b/toxcore/network.c @@ -493,7 +493,7 @@ Networking_Core *new_networking(IP ip, uint16_t port) * return Networking_Core object if no problems * return NULL if there are problems. * - * If error is non NULL it is set to 0 if no issues, 1 if bind failed, 2 if other. + * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. */ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) { @@ -546,6 +546,10 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, fprintf(stderr, "Failed to get a socket?! %u, %s\n", errno, strerror(errno)); #endif free(temp); + + if (error) + *error = 1; + return NULL; } @@ -562,12 +566,20 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, /* iOS UDP sockets are weird and apparently can SIGPIPE */ if (!set_socket_nosigpipe(temp->sock)) { kill_networking(temp); + + if (error) + *error = 1; + return NULL; } /* Set socket nonblocking. */ if (!set_socket_nonblock(temp->sock)) { kill_networking(temp); + + if (error) + *error = 1; + return NULL; } diff --git a/toxcore/network.h b/toxcore/network.h index b06c0f6a..56494562 100644 --- a/toxcore/network.h +++ b/toxcore/network.h @@ -370,7 +370,7 @@ void networking_poll(Networking_Core *net); * return Networking_Core object if no problems * return NULL if there are problems. * - * If error is non NULL it is set to 0 if no issues, 1 if bind failed, 2 if other. + * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other. */ Networking_Core *new_networking(IP ip, uint16_t port); Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error);