Index: main/tcptls.c =================================================================== --- main/tcptls.c (Revision 281286) +++ main/tcptls.c (Arbeitskopie) @@ -427,6 +427,12 @@ originate from the desired address */ if (!ast_sockaddr_isnull(&desc->local_address)) { setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_REUSEADDR: %s\n",strerror(errno)); + } + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_KEEPALIVE, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_KEEPALIVE: %s\n",strerror(errno)); + } if (ast_bind(desc->accept_fd, &desc->local_address)) { ast_log(LOG_ERROR, "Unable to bind %s to %s: %s\n", desc->name, @@ -494,6 +500,13 @@ } setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)); + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_REUSEADDR: %s\n",strerror(errno)); + } + if (setsockopt(desc->accept_fd, SOL_SOCKET, SO_KEEPALIVE, &x, sizeof(x)) ) { + ast_log(LOG_ERROR, "Failed to set socket option SO_KEEPALIVE: %s\n",strerror(errno)); + } + if (ast_bind(desc->accept_fd, &desc->local_address)) { ast_log(LOG_ERROR, "Unable to bind %s to %s: %s\n", desc->name, Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (Revision 281286) +++ channels/chan_sip.c (Arbeitskopie) @@ -12856,6 +12856,32 @@ int transport_type; const char *useragent; struct ast_sockaddr oldsin, testsa; + + + + /* check if we have already a tcp connection */ + if(!ast_sockaddr_isnull(&peer->addr) && peer->socket.type != SIP_TRANSPORT_UDP){ + /* if the remote address is not me, close this tcp helper thread */ + if(ast_sockaddr_cmp_addr(&peer->addr, &pvt->recv)){ + if (peer->socket.tcptls_session) { + struct sip_threadinfo *th; + + struct sip_threadinfo tmp = { + .tcptls_session = peer->socket.tcptls_session, + }; + + /* search for the tcp_helper_thread */ + th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"); + if(th){ + /* stopping the thread also closes socket an destroy it */ + pthread_t thread = th->threadid; + th->stop = 1; + pthread_kill(thread, SIGURG); + pthread_join(thread, NULL); + } + } + } + } /* end; search for older tcp connection */ ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact));