detached socket cleaning
This commit is contained in:
parent
016b2587b4
commit
4d700ef90a
@ -1661,7 +1661,7 @@ void close_ioa_socket(ioa_socket_handle s)
|
||||
}
|
||||
}
|
||||
|
||||
ioa_socket_handle detach_ioa_socket(ioa_socket_handle s, int full_detach)
|
||||
ioa_socket_handle detach_ioa_socket(ioa_socket_handle s)
|
||||
{
|
||||
ioa_socket_handle ret = NULL;
|
||||
|
||||
@ -1693,13 +1693,29 @@ ioa_socket_handle detach_ioa_socket(ioa_socket_handle s, int full_detach)
|
||||
|
||||
evutil_socket_t udp_fd = -1;
|
||||
|
||||
if(s->parent_s && full_detach) {
|
||||
if(s->parent_s) {
|
||||
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;
|
||||
}
|
||||
if(sock_bind_to_device(udp_fd, (unsigned char*)(s->e->relay_ifname))<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot bind udp server socket to device %s\n",(char*)(s->e->relay_ifname));
|
||||
}
|
||||
|
||||
if(addr_bind(udp_fd,&(s->local_addr),1)<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot bind new detached udp server socket to local addr\n");
|
||||
close(udp_fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int connect_err=0;
|
||||
if(addr_connect(udp_fd, &(s->remote_addr), &connect_err)<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot connect new detached udp server socket to remote addr\n");
|
||||
close(udp_fd);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
detach_socket_net_data(s);
|
||||
@ -1737,39 +1753,14 @@ ioa_socket_handle detach_ioa_socket(ioa_socket_handle s, int full_detach)
|
||||
addr_cpy(&(ret->remote_addr),&(s->remote_addr));
|
||||
|
||||
STRCPY(ret->orig_ctx_type, s->orig_ctx_type);
|
||||
|
||||
ioa_socket_handle parent_s = s->parent_s;
|
||||
ur_addr_map *sockets_container = s->sockets_container;
|
||||
|
||||
delete_socket_from_map(s);
|
||||
delete_socket_from_parent(s);
|
||||
|
||||
if(udp_fd<0) {
|
||||
|
||||
add_socket_to_parent(parent_s, ret);
|
||||
add_socket_to_map(ret,sockets_container);
|
||||
|
||||
} else {
|
||||
if(udp_fd>=0) {
|
||||
|
||||
ret->fd = udp_fd;
|
||||
|
||||
if(sock_bind_to_device(udp_fd, (unsigned char*)(s->e->relay_ifname))<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot bind udp server socket to device %s\n",(char*)(s->e->relay_ifname));
|
||||
}
|
||||
|
||||
if(addr_bind(udp_fd,&(s->local_addr),1)<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot bind new detached udp server socket to local addr\n");
|
||||
IOA_CLOSE_SOCKET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int connect_err=0;
|
||||
if(addr_connect(udp_fd, &(s->remote_addr), &connect_err)<0) {
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR,"Cannot connect new detached udp server socket to remote addr\n");
|
||||
IOA_CLOSE_SOCKET(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
set_socket_options(ret);
|
||||
}
|
||||
|
||||
|
||||
@ -365,6 +365,7 @@ int main(int argc, char **argv)
|
||||
case 'P':
|
||||
passive_tcp = 1;
|
||||
/* implies 'T': */
|
||||
/* no break */
|
||||
case 'T':
|
||||
relay_transport = STUN_ATTRIBUTE_TRANSPORT_TCP_VALUE;
|
||||
break;
|
||||
|
||||
@ -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, int full_detach);
|
||||
ioa_socket_handle detach_ioa_socket(ioa_socket_handle s);
|
||||
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);
|
||||
|
||||
@ -1525,7 +1525,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_socket,1);
|
||||
ioa_socket_handle new_s = detach_ioa_socket(ss->client_socket);
|
||||
if(new_s) {
|
||||
if(server->send_socket_to_relay(tsid, mid, tid, new_s, message_integrity,
|
||||
RMT_MOBILE_SOCKET, in_buffer, can_resume)<0) {
|
||||
@ -1616,7 +1616,7 @@ static int handle_turn_refresh(turn_turnserver *server,
|
||||
|
||||
//Transfer socket:
|
||||
|
||||
ioa_socket_handle s = detach_ioa_socket(ss->client_socket,0);
|
||||
ioa_socket_handle s = detach_ioa_socket(ss->client_socket);
|
||||
|
||||
ss->to_be_closed = 1;
|
||||
|
||||
@ -2310,7 +2310,7 @@ static int handle_turn_connection_bind(turn_turnserver *server,
|
||||
turnserver_id sid = (id & 0xFF000000)>>24;
|
||||
ioa_socket_handle s = ss->client_socket;
|
||||
if(s && !ioa_socket_tobeclosed(s)) {
|
||||
ioa_socket_handle new_s = detach_ioa_socket(s,1);
|
||||
ioa_socket_handle new_s = detach_ioa_socket(s);
|
||||
if(new_s) {
|
||||
if(server->send_socket_to_relay(sid, id, tid, new_s, message_integrity, RMT_CB_SOCKET, in_buffer, can_resume)<0) {
|
||||
*err_code = 400;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user