pjsip_transport_management: Shutdown transport immediately on disconnect

The transport management code that checks for idle connections keeps a
reference to PJSIP's transport for IDLE_TIMEOUT milliseconds (32000 by
default). Because of this, if the transport is closed before this
timeout, the idle checking code will keep the transport from actually
being shutdown until the timeout expires.

Rather than passing the AO2 object to the scheduler task, we just pass
its key and look it up when it is time to potentially close the idle
connection. The other transport management code handles cleaning up
everything else for us.

Additionally, because we use the address of the transport when
generating its name, we concatenate an incrementing ID to the end of the
name to guarantee uniqueness.

Related to ASTERISK~28231

Change-Id: I02ee9f4073b6abca9169d30c47aa69b5e8ae9afb
This commit is contained in:
Sean Bright
2019-01-18 17:11:18 -05:00
parent 011e46d5a6
commit fb6e0df173
2 changed files with 56 additions and 32 deletions

View File

@@ -41,6 +41,11 @@
static int transport_type_wss;
static int transport_type_wss_ipv6;
/*!
* Used to ensure uniqueness among WS transport names
*/
static int ws_obj_name_serial;
/*!
* \brief Wrapper for pjsip_transport, for storing the WebSocket session
*/
@@ -163,8 +168,8 @@ static int transport_create(void *data)
}
/* Give websocket transport a unique name for its lifetime */
snprintf(newtransport->transport.obj_name, PJ_MAX_OBJ_NAME, "ws%p",
&newtransport->transport);
snprintf(newtransport->transport.obj_name, PJ_MAX_OBJ_NAME, "ws%p-%d",
&newtransport->transport, ast_atomic_fetchadd_int(&ws_obj_name_serial, 1));
newtransport->transport.endpt = endpt;