diff --git a/src/apps/relay/ns_ioalib_engine_impl.c b/src/apps/relay/ns_ioalib_engine_impl.c index 1a12dbb..7f2b896 100644 --- a/src/apps/relay/ns_ioalib_engine_impl.c +++ b/src/apps/relay/ns_ioalib_engine_impl.c @@ -1634,7 +1634,7 @@ void close_ioa_socket(ioa_socket_handle s) } } -ioa_socket_handle detach_ioa_socket(ioa_socket_handle s) +ioa_socket_handle detach_ioa_socket(ioa_socket_handle s, int full_detach) { ioa_socket_handle ret = NULL; @@ -1666,15 +1666,13 @@ ioa_socket_handle detach_ioa_socket(ioa_socket_handle s) evutil_socket_t udp_fd = -1; - if(s->parent_s) { -#if defined(SO_REUSEPORT) + if(s->parent_s && full_detach) { udp_fd = socket(s->local_addr.ss.sa_family, SOCK_DGRAM, 0); if (udp_fd < 0) { perror("socket"); TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"%s: Cannot allocate new socket\n",__FUNCTION__); return ret; } -#endif } detach_socket_net_data(s); @@ -1826,8 +1824,9 @@ ioa_addr* get_local_addr_from_ioa_socket(ioa_socket_handle s) { if (s && (s->magic == SOCKET_MAGIC) && !(s->done)) { - if(s->parent_s) + if(s->parent_s) { s = s->parent_s; + } if (s->local_addr_known) { return &(s->local_addr); diff --git a/src/server/ns_turn_ioalib.h b/src/server/ns_turn_ioalib.h index 46711e3..896f797 100644 --- a/src/server/ns_turn_ioalib.h +++ b/src/server/ns_turn_ioalib.h @@ -235,7 +235,7 @@ int register_callback_on_ioa_socket(ioa_engine_handle e, ioa_socket_handle s, in int send_data_from_ioa_socket_nbh(ioa_socket_handle s, ioa_addr* dest_addr, ioa_network_buffer_handle nbh, int ttl, int tos); void close_ioa_socket(ioa_socket_handle s); #define IOA_CLOSE_SOCKET(S) do { if(S) { close_ioa_socket(S); S = NULL; } } while(0) -ioa_socket_handle detach_ioa_socket(ioa_socket_handle s); +ioa_socket_handle detach_ioa_socket(ioa_socket_handle s, int full_detach); void detach_socket_net_data(ioa_socket_handle s); int set_df_on_ioa_socket(ioa_socket_handle s, int value); void set_do_not_use_df(ioa_socket_handle s); diff --git a/src/server/ns_turn_server.c b/src/server/ns_turn_server.c index 01955ce..e5738f8 100644 --- a/src/server/ns_turn_server.c +++ b/src/server/ns_turn_server.c @@ -1240,7 +1240,7 @@ static int handle_turn_refresh(turn_turnserver *server, if(tsid != server->id) { if(server->send_socket_to_relay) { - ioa_socket_handle new_s = detach_ioa_socket(ss->client_session.s); + ioa_socket_handle new_s = detach_ioa_socket(ss->client_session.s,1); if(new_s) { if(server->send_socket_to_relay(tsid, mid, tid, new_s, message_integrity, RMT_MOBILE_SOCKET, in_buffer)<0) { @@ -1318,7 +1318,7 @@ static int handle_turn_refresh(turn_turnserver *server, //Transfer socket: - ioa_socket_handle s = detach_ioa_socket(ss->client_session.s); + ioa_socket_handle s = detach_ioa_socket(ss->client_session.s,0); ss->to_be_closed = 1; @@ -1952,7 +1952,7 @@ static int handle_turn_connection_bind(turn_turnserver *server, turnserver_id sid = (id & 0xFF000000)>>24; ioa_socket_handle s = ss->client_session.s; if(s) { - ioa_socket_handle new_s = detach_ioa_socket(s); + ioa_socket_handle new_s = detach_ioa_socket(s,1); if(new_s) { if(server->send_socket_to_relay(sid, id, tid, new_s, message_integrity, RMT_CB_SOCKET, NULL)<0) { *err_code = 400;