Commit | Line | Data |
---|---|---|
7591bab1 MD |
1 | #ifndef _CONNECTION_H |
2 | #define _CONNECTION_H | |
3 | ||
58eb9381 DG |
4 | /* |
5 | * Copyright (C) 2013 - Julien Desfossez <jdesfossez@efficios.com> | |
6 | * David Goulet <dgoulet@efficios.com> | |
7591bab1 | 7 | * 2015 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
58eb9381 DG |
8 | * |
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. | |
12 | * | |
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 | |
16 | * more details. | |
17 | * | |
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. | |
21 | */ | |
22 | ||
58eb9381 DG |
23 | #include <limits.h> |
24 | #include <inttypes.h> | |
25 | #include <pthread.h> | |
26 | #include <urcu.h> | |
8bdee6e2 | 27 | #include <urcu/wfcqueue.h> |
58eb9381 DG |
28 | #include <urcu/list.h> |
29 | ||
30 | #include <common/hashtable/hashtable.h> | |
31 | #include <common/sessiond-comm/sessiond-comm.h> | |
32 | ||
33 | #include "session.h" | |
34 | ||
35 | enum connection_type { | |
7591bab1 | 36 | RELAY_CONNECTION_UNKNOWN = 0, |
58eb9381 DG |
37 | RELAY_DATA = 1, |
38 | RELAY_CONTROL = 2, | |
39 | RELAY_VIEWER_COMMAND = 3, | |
40 | RELAY_VIEWER_NOTIFICATION = 4, | |
41 | }; | |
42 | ||
43 | /* | |
44 | * Internal structure to map a socket with the corresponding session. | |
45 | * A hashtable indexed on the socket FD is used for the lookups. | |
7591bab1 MD |
46 | * |
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. | |
50 | * | |
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). | |
53 | * | |
54 | * This is why there are no back references to connections from the | |
55 | * sessions and session list. | |
58eb9381 DG |
56 | */ |
57 | struct relay_connection { | |
58 | struct lttcomm_sock *sock; | |
8bdee6e2 | 59 | struct cds_wfcq_node qnode; |
7591bab1 | 60 | |
58eb9381 | 61 | enum connection_type type; |
7591bab1 MD |
62 | /* |
63 | * session is only ever set for RELAY_CONTROL connection type. | |
64 | */ | |
65 | struct relay_session *session; | |
66 | /* | |
67 | * viewer_session is only ever set for RELAY_VIEWER_COMMAND | |
68 | * connection type. | |
69 | */ | |
70 | struct relay_viewer_session *viewer_session; | |
71 | ||
72 | /* | |
73 | * Protocol version to use for this connection. Only valid for | |
74 | * RELAY_CONTROL connection type. | |
75 | */ | |
58eb9381 DG |
76 | uint32_t major; |
77 | uint32_t minor; | |
7591bab1 MD |
78 | |
79 | struct urcu_ref ref; | |
80 | pthread_mutex_t reflock; | |
81 | ||
82 | bool version_check_done; | |
cd2ef1ef DG |
83 | |
84 | /* | |
7591bab1 | 85 | * Node member of connection within global socket hash table. |
cd2ef1ef | 86 | */ |
7591bab1 MD |
87 | struct lttng_ht_node_ulong sock_n; |
88 | bool in_socket_ht; | |
89 | struct lttng_ht *socket_ht; /* HACK: Contained within this hash table. */ | |
90 | struct rcu_head rcu_node; /* For call_rcu teardown. */ | |
58eb9381 DG |
91 | }; |
92 | ||
7591bab1 MD |
93 | struct relay_connection *connection_create(struct lttcomm_sock *sock, |
94 | enum connection_type type); | |
95 | struct relay_connection *connection_get_by_sock(struct lttng_ht *relay_connections_ht, | |
58eb9381 | 96 | int sock); |
7591bab1 MD |
97 | bool connection_get(struct relay_connection *connection); |
98 | void connection_put(struct relay_connection *connection); | |
99 | void connection_ht_add(struct lttng_ht *relay_connections_ht, | |
100 | struct relay_connection *conn); | |
58eb9381 DG |
101 | |
102 | #endif /* _CONNECTION_H */ |