5 * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com>
6 * David Goulet <dgoulet@efficios.com>
7 * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License, version 2 only, as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 51
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include <urcu/wfcqueue.h>
28 #include <urcu/list.h>
30 #include <common/hashtable/hashtable.h>
31 #include <common/sessiond-comm/sessiond-comm.h>
35 enum connection_type
{
36 RELAY_CONNECTION_UNKNOWN
= 0,
39 RELAY_VIEWER_COMMAND
= 3,
40 RELAY_VIEWER_NOTIFICATION
= 4,
44 * Internal structure to map a socket with the corresponding session.
45 * A hashtable indexed on the socket FD is used for the lookups.
47 * Connections are assumed to be accessed from a single thread. Live
48 * connections between the relay and a live client are only accessed
49 * from the live worker thread.
51 * The connections between the consumerd/sessiond and the relayd are only
52 * handled by the "main" worker thread (as in, the worker thread in main.c).
54 * This is why there are no back references to connections from the
55 * sessions and session list.
57 struct relay_connection
{
58 struct lttcomm_sock
*sock
;
59 struct cds_wfcq_node qnode
;
61 enum connection_type type
;
63 * session is only ever set for RELAY_CONTROL connection type.
65 struct relay_session
*session
;
67 * viewer_session is only ever set for RELAY_VIEWER_COMMAND
70 struct relay_viewer_session
*viewer_session
;
73 * Protocol version to use for this connection. Only valid for
74 * RELAY_CONTROL connection type.
81 bool version_check_done
;
84 * Node member of connection within global socket hash table.
86 struct lttng_ht_node_ulong sock_n
;
88 struct lttng_ht
*socket_ht
; /* HACK: Contained within this hash table. */
89 struct rcu_head rcu_node
; /* For call_rcu teardown. */
92 struct relay_connection
*connection_create(struct lttcomm_sock
*sock
,
93 enum connection_type type
);
94 struct relay_connection
*connection_get_by_sock(struct lttng_ht
*relay_connections_ht
,
96 bool connection_get(struct relay_connection
*connection
);
97 void connection_put(struct relay_connection
*connection
);
98 void connection_ht_add(struct lttng_ht
*relay_connections_ht
,
99 struct relay_connection
*conn
);
101 #endif /* _CONNECTION_H */