summaryrefslogtreecommitdiff
path: root/toxcore/network.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-04-13 08:32:33 -0400
committerirungentoo <irungentoo@gmail.com>2015-04-13 08:32:33 -0400
commitd05e39274ca4ce27ddb02c0ec15c0ed1c46000a3 (patch)
tree9700b16370a1357fc7745ab7deb39686c830fa92 /toxcore/network.c
parent42d8be4ce91532d2af1ccb596c2de4054eba34b3 (diff)
Make tox_new return TOX_ERR_NEW_PORT_ALLOC for all socket related errors.
Diffstat (limited to 'toxcore/network.c')
-rw-r--r--toxcore/network.c14
1 files changed, 13 insertions, 1 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)
493 * return Networking_Core object if no problems 493 * return Networking_Core object if no problems
494 * return NULL if there are problems. 494 * return NULL if there are problems.
495 * 495 *
496 * If error is non NULL it is set to 0 if no issues, 1 if bind failed, 2 if other. 496 * If error is non NULL it is set to 0 if no issues, 1 if socket related error, 2 if other.
497 */ 497 */
498Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error) 498Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to, unsigned int *error)
499{ 499{
@@ -546,6 +546,10 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to,
546 fprintf(stderr, "Failed to get a socket?! %u, %s\n", errno, strerror(errno)); 546 fprintf(stderr, "Failed to get a socket?! %u, %s\n", errno, strerror(errno));
547#endif 547#endif
548 free(temp); 548 free(temp);
549
550 if (error)
551 *error = 1;
552
549 return NULL; 553 return NULL;
550 } 554 }
551 555
@@ -562,12 +566,20 @@ Networking_Core *new_networking_ex(IP ip, uint16_t port_from, uint16_t port_to,
562 /* iOS UDP sockets are weird and apparently can SIGPIPE */ 566 /* iOS UDP sockets are weird and apparently can SIGPIPE */
563 if (!set_socket_nosigpipe(temp->sock)) { 567 if (!set_socket_nosigpipe(temp->sock)) {
564 kill_networking(temp); 568 kill_networking(temp);
569
570 if (error)
571 *error = 1;
572
565 return NULL; 573 return NULL;
566 } 574 }
567 575
568 /* Set socket nonblocking. */ 576 /* Set socket nonblocking. */
569 if (!set_socket_nonblock(temp->sock)) { 577 if (!set_socket_nonblock(temp->sock)) {
570 kill_networking(temp); 578 kill_networking(temp);
579
580 if (error)
581 *error = 1;
582
571 return NULL; 583 return NULL;
572 } 584 }
573 585