forked from meetecho/janus-gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport.c
39 lines (35 loc) · 1.38 KB
/
transport.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*! \file transport.h
* \author Lorenzo Miniero <[email protected]>
* \copyright GNU General Public License v3
* \brief Modular Janus API transports
* \details This header contains the definition of the callbacks both
* the gateway and all the transports need too implement to interact with
* each other. The structures to make the communication possible are
* defined here as well.
*
* \ingroup transportapi
* \ref transportapi
*/
#include "transport.h"
static void janus_transport_session_free(const janus_refcount *transport_ref) {
janus_transport_session *session = janus_refcount_containerof(transport_ref, janus_transport_session, ref);
/* This session can be destroyed, free all the resources */
if(session->p_free)
session->p_free(session->transport_p);
g_free(session);
}
janus_transport_session *janus_transport_session_create(void *transport_p, void (*p_free)(void *)) {
janus_transport_session *tp = g_malloc0(sizeof(janus_transport_session));
if(tp == NULL)
return NULL;
tp->transport_p = transport_p;
tp->p_free = p_free;
g_atomic_int_set(&tp->destroyed, 0);
janus_refcount_init(&tp->ref, janus_transport_session_free);
janus_mutex_init(&tp->mutex);
return tp;
}
void janus_transport_session_destroy(janus_transport_session *session) {
if(session && g_atomic_int_compare_and_exchange(&session->destroyed, 0, 1))
janus_refcount_decrease(&session->ref);
}