From 26fcb932443df9a74871ba9d59d818dbc05a18b6 Mon Sep 17 00:00:00 2001 From: Nicolas Bats Date: Tue, 22 Apr 2014 09:21:40 +0200 Subject: [PATCH] Update network.c allow to reuse 6454 port --- artnet/network.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/artnet/network.c b/artnet/network.c index a975103..cc25ed3 100644 --- a/artnet/network.c +++ b/artnet/network.c @@ -508,13 +508,6 @@ int artnet_net_start(node n) { if (n->state.verbose) printf("Binding to %s \n", inet_ntoa(servAddr.sin_addr)); - // bind sockets - if (bind(sock, (SA *) &servAddr, sizeof(servAddr)) == -1) { - artnet_error("Failed to bind to socket %s", artnet_net_last_error()); - artnet_net_close(sock); - return ARTNET_ENET; - } - // allow bcasting if (setsockopt(sock, SOL_SOCKET, @@ -548,8 +541,30 @@ int artnet_net_start(node n) { artnet_net_close(sock); return ARTNET_ENET; } +#else +// allow reusing 6454 port _ + if (setsockopt(sock, + SOL_SOCKET, + SO_REUSEPORT, + (char*) &true_flag, // char* for win32 + sizeof(int)) == -1) { + artnet_error("Failed to bind to socket %s", artnet_net_last_error()); + artnet_net_close(sock); + return ARTNET_ENET; + } #endif + if (n->state.verbose) + printf("Binding to %s \n", inet_ntoa(servAddr.sin_addr)); + + // bind sockets + if (bind(sock, (SA *) &servAddr, sizeof(servAddr)) == -1) { + artnet_error("Failed to bind to socket %s", artnet_net_last_error()); + artnet_net_close(sock); + return ARTNET_ENET; + } + + n->sd = sock; // Propagate the socket to all our peers for (tmp = n->peering.peer; tmp && tmp != n; tmp = tmp->peering.peer)