RTI Connext C API Version 7.7.0
transport_shmem.h
1/*
2 * (c) Copyright, Real-Time Innovations, 2005-2024.
3 * All rights reserved.
4 *
5 * No duplications, whole or partial, manual or electronic, may be made
6 * without express written permission. Any such copies, or
7 * revisions thereof, must display this notice unaltered.
8 * This code contains trade secrets of Real-Time Innovations, Inc.
9 */
10
11#ifndef transport_shmem_h
12#define transport_shmem_h
13
14#include "clock/clock_interface.h"
15#include "transport/transport_dll.h"
16#include "transport/transport_interface.h"
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22/* ================================================================= */
23/* Component: Shared Memory Transport Plugin */
24/* ================================================================= */
25
26/*e \dref_ShmemTransportBuiltinGroupDocs
27 */
28
29/*i \file
30 * \ingroup NDDS_Transport_Shmem_Plugin NDDS_TransportBuiltinsComponent
31 * \brief Shared-Memory Transport Plugin interface and definitions.
32 */
33
34/* ================================================================= */
35/* Shared Memory Properties */
36/* ================================================================= */
37/*e \dref_ShmemTransport_Property_t
38 */
40 /*e \dref_ShmemTransport_Property_t_parent
41 */
43
44 /*e \dref_ShmemTransport_Property_t_received_message_count_max
45 */
47
48 /*e \dref_ShmemTransport_Property_t_receive_buffer_size
49 */
51
52 /*e \dref_ShmemTransport_Property_t_enable_udp_debugging
53 */
55
56 /*e \dref_ShmemTransport_Property_t_udp_debugging_address
57 */
59
60 /*e \dref_ShmemTransport_Property_t_udp_debugging_port
61 */
63
64 /*i offset used for port -> segment key mapping */
65 RTI_INT32 segmentKeyOffset;
66
67 /*i factor used for port -> segment key mapping */
68 RTI_INT32 segmentKeyFactor;
69
70 /*i offset used for port -> semaphore key mapping */
71 RTI_INT32 semaphoreKeyOffset;
72
73 /*i factor used for port -> semaphore key mapping */
74 RTI_INT32 semaphoreKeyFactor;
75
76 /*i offset used for port -> mutex key mapping */
77 RTI_INT32 mutexKeyOffset;
78
79 /*i factor used for port -> mutex key mapping */
80 RTI_INT32 mutexKeyFactor;
81
82 /*i
83 * The maximum duration that a writer can take to write this message.
84 * If a writer takes longer, it can be potentially be aborted writing by a
85 * reader believing the writer is stuck (i.e. in an infinite loop).
86 * The resolution is in milliseconds.
87 * Default value is 1000
88 */
89 RTI_UINT32 maxAllowedWriterDurationMillisec;
90
91 /*i
92 * IMPORTANT: This value is used for unit testing purposes ONLY!. Possible
93 * values are:
94 * 1) If this value is
95 * NDDS_TRANSPORT_SHMEM_RESERVED_FORCE_RECV_RESOURCE_FAILURE then create
96 * recv resource will fail
97 * 2) If this value is
98 * NDDS_TRANSPORT_SHMEM_RESERVED_USE_TRANSPORT_UUID_AS_SHMEM_UUID
99 * then the shmemUuid will be the same as the transport_uuid.
100 */
101 RTIBool reserved;
102
103 /*i
104 * UUID used to check the reachability of a shmem locator received through
105 * discovery. After attaching to a shmem segment, we will check that
106 * the UUID in the header matches the one in the received locator.
107 * If it matches, that means that we are on the same machine than
108 * the target locator and that communication is possible through shmem.
109 */
110 NDDS_Transport_Address_t shmemUUID;
111
112 /*i
113 * Major version of the shared memory protocol.
114 * Different major versions are incompatible.
115 */
116 RTI_INT16 majorVersion;
117};
118
119/*i
120 * For testing: When reserved is set to this value, create_recv_resource will
121 * fail.
122 */
123#define NDDS_TRANSPORT_SHMEM_RESERVED_FORCE_RECV_RESOURCE_FAILURE 1
124
125/*i
126 * For testing: When reserved is set to this value,
127 * the shmemUuid will be the same as the transport_uuid.
128 *
129 * This can be used to simulate scenarios where two participants are on
130 * different machines even though they run on the same physical machine.
131 */
132#define NDDS_TRANSPORT_SHMEM_RESERVED_USE_TRANSPORT_UUID_AS_SHMEM_UUID 2
133
134/*i \ingroup NDDS_Transport_Shmem_Plugin
135 * \brief Shmem plugin class string name
136 */
137#define NDDS_TRANSPORT_SHMEM_CLASS_NAME "shmem"
138
139/*i \ingroup NDDS_Transport_Shmem_Plugin
140 * \brief Shmem plugin builtin alias string name
141 */
142#define NDDS_TRANSPORT_BUILTIN_SHMEM_ALIAS "builtin.shmem"
143
144/*e \ingroup NDDS_Transport_Shmem_Plugin
145 * \brief Default value of NDDS_Transport_Property_t#address_bit_count
146 */
147#define NDDS_TRANSPORT_SHMEM_ADDRESS_BIT_COUNT (-96)
148
149/*e @ingroup NDDS_Transport_Shmem_Plugin
150 * @brief Default value of NDDS_Transport_Property_t#properties_bitmap.
151 */
152#define NDDS_TRANSPORT_SHMEM_PROPERTIES_BITMAP_DEFAULT \
153 (NDDS_TRANSPORT_PROPERTY_BIT_BUFFER_ALWAYS_LOANED)
154
155/*e \ingroup NDDS_Transport_Shmem_Plugin
156 * \brief Default value of
157 * NDDS_Transport_Property_t#gather_send_buffer_count_max.
158 */
159#define NDDS_TRANSPORT_SHMEM_GATHER_SEND_BUFFER_COUNT_MAX_DEFAULT (1024)
160
161/*e \ingroup NDDS_Transport_Shmem_Plugin
162 * \brief Default value of NDDS_Transport_Property_t#message_size_max.
163 */
164#if defined(RTI_INTY)
165 #define NDDS_TRANSPORT_SHMEM_MESSAGE_SIZE_MAX_DEFAULT (9216)
166#else
167 #define NDDS_TRANSPORT_SHMEM_MESSAGE_SIZE_MAX_DEFAULT (65536)
168#endif
169
170/*e \ingroup NDDS_Transport_Shmem_Plugin
171 * \brief Default value of
172 * NDDS_Transport_Shmem_Property_t#received_message_count_max.
173 */
174#if defined(RTI_INTY)
175 #define NDDS_TRANSPORT_SHMEM_RECEIVED_MESSAGE_COUNT_MAX_DEFAULT (8)
176#else
177 #define NDDS_TRANSPORT_SHMEM_RECEIVED_MESSAGE_COUNT_MAX_DEFAULT (64)
178#endif
179
180/*e \ingroup NDDS_Transport_Shmem_Plugin
181 * \brief Default value of NDDS_Transport_Shmem_Property_t#receive_buffer_size.
182 */
183#define NDDS_TRANSPORT_SHMEM_RECEIVE_BUFFER_SIZE_DEFAULT \
184 (NDDS_TRANSPORT_SHMEM_RECEIVED_MESSAGE_COUNT_MAX_DEFAULT \
185 * NDDS_TRANSPORT_SHMEM_MESSAGE_SIZE_MAX_DEFAULT / 4)
186
187/*i \ingroup NDDS_Transport_Shmem_Plugin
188 * \brief Major version of the shared memory transport containing bug 14240
189 * (RTI-28)
190 */
191#define NDDS_TRANSPORT_SHMEM_MAJOR_BEFORE_BUG_14240_FIX (1)
192
193/*e \ingroup NDDS_Transport_Shmem_Plugin
194 * \brief Major version for the transport plugin after fixing bug 14240 (RTI-28)
195 */
196#define NDDS_TRANSPORT_SHMEM_MAJOR_AFTER_BUG_14240_FIX (2)
197
198/* SparcSolaris had a shmem version with major 3 */
199#define NDDS_TRANSPORT_SHMEM_MAJOR_SPARC_SOLARIS_DEPRECATED (3)
200
201/*
202 * This is the version of the shared memory transport that uses a concurrent
203 * queue with a writer cookie, used in Network Capture (CORE-10280) to get the
204 * PID of the source for inbound traffic.
205 *
206 * There is a parallelism between concurrent queue versions and shared memory
207 * versions. We are doing the same here as in
208 * REDA_CONCURRENT_QUEUE_VERSION_AFTER_WRITER_COOKIE_SUPPORT: keep the default
209 * major version so that there is no interoperability break, but allow (through
210 * property configuration) to use a newer one.
211 */
212#define NDDS_TRANSPORT_SHMEM_MAJOR_AFTER_WRITER_COOKIE_SUPPORT (4)
213
214/*
215 * This is the version of the shared memory transport that uses a robust
216 * pthread mutex to protect the shared memory segment.
217 */
218#define NDDS_TRANSPORT_SHMEM_MAJOR_AFTER_ROBUST_PTHREAD_MUTEX (5)
219
220/* This is the current default major version. */
221#define NDDS_TRANSPORT_SHMEM_VERSION_MAJOR_DEFAULT \
222 NDDS_TRANSPORT_SHMEM_MAJOR_AFTER_BUG_14240_FIX
223
224/*e \ingroup NDDS_Transport_Shmem_Plugin
225 * \brief Use this to initialize stack variable.
226 * \hideinitializer
227 */
228#define NDDS_TRANSPORT_SHMEM_PROPERTY_DEFAULT \
229 { \
230 { \
231 NDDS_TRANSPORT_CLASSID_SHMEM, \
232 NDDS_TRANSPORT_SHMEM_ADDRESS_BIT_COUNT, \
233 NDDS_TRANSPORT_SHMEM_PROPERTIES_BITMAP_DEFAULT, \
234 NDDS_TRANSPORT_SHMEM_GATHER_SEND_BUFFER_COUNT_MAX_DEFAULT, \
235 NDDS_TRANSPORT_SHMEM_MESSAGE_SIZE_MAX_DEFAULT, \
236 NULL, \
237 0, /* allow_interfaces_list */ \
238 NULL, \
239 0, /* deny_interfaces_list */ \
240 NULL, \
241 0, /* allow_multicast_interfaces_list */ \
242 NULL, \
243 0, /* deny_multicast_interfaces_list */ \
244 NDDS_TRANSPORT_UUID_UNKNOWN, /* transport_uuid */ \
245 NULL, /* domain_participant_ptr */ \
246 NULL, /* domain_participant_forwarder */ \
247 NULL, /* thread_name_prefix */ \
248 NDDS_TRANSPORT_LENGTH_UNLIMITED, /* max_interface_count */ \
249 }, \
250 NDDS_TRANSPORT_SHMEM_RECEIVED_MESSAGE_COUNT_MAX_DEFAULT, \
251 NDDS_TRANSPORT_SHMEM_RECEIVE_BUFFER_SIZE_DEFAULT, \
252 RTI_FALSE, /* enable_udp_debugging */ \
253 { \
254 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 255, 1, 2 } \
255 }, /* udp_debugging_address */ \
256 7399, /* udp_debugging_port */ \
257 0x400000, /* 0100 xxxx ... */ \
258 1, 0x800000, /* 1000 xxxx ... */ \
259 1, 0xB00000, /* 1100 xxxx ... */ \
260 1, 1000, /* maxAllowedWriterDurationMillisec */ \
261 RTI_FALSE, /* reserved */ \
262 NDDS_TRANSPORT_ADDRESS_INVALID_INITIALIZER, /* shmemUUID */ \
263 NDDS_TRANSPORT_SHMEM_VERSION_MAJOR_DEFAULT /* majorVersion */ \
264 }
265
266/* ================================================================= */
267/* Shared Memory Transport Class */
268/* ================================================================= */
269
270/*i \ingroup NDDS_Transport_Shmem_Plugin
271 * \brief Create a new shmem process transport.
272 *
273 * \copydoc NDDS_Transport_Shmem_new
274 *
275 * @exception RTI_LOG_MALLOC_FAILURE_d
276 * RTI_LOG_CREATION_FAILURE_s RTI_LOG_PRECONDITION_FAILURE
277 * RTI_LOG_INIT_FAILURE_s
278 */
279extern NDDS_Transport_DllExport NDDS_Transport_Plugin *
280NDDS_Transport_Shmem_newI(
281 const struct NDDS_Transport_Shmem_Property_t *property);
282
283/*e \ingroup NDDS_Transport_Shmem_Plugin
284 * \brief Create a new shmem process transport.
285 *
286 * An application may create multiple transports, possibly for use in
287 * different domains.
288 *
289 * @param property_in \st_in Desired behavior of this transport. May be NULL
290 * for default property. The transport plugin can only support one unicast
291 * receive interface; therefore the interface selection lists are ignored.
292 *
293 * @return handle to a Shmem inter-process Transport Plugin on success
294 * @return NULL on failure.
295 */
296extern NDDS_Transport_DllExport NDDS_Transport_Plugin *NDDS_Transport_Shmem_new(
297 const struct NDDS_Transport_Shmem_Property_t *property_in);
298
299/*i \ingroup NDDS_Transport_Shmem_Plugin
300 */
301#define NDDS_Transport_Shmem_new(property_in) \
302 NDDS_Transport_Shmem_newI(property_in)
303
304/*i \ingroup NDDS_Transport_Shmem_Plugin
305 * \brief Realization of NDDS_Transport_Get_Class_Name_Fcn_cEA for Shmem
306 * transports.
307 *
308 * Returns the string "shmem".
309 *
310 * @see NDDS_Transport_Get_Class_Name_Fcn_cEA for complete
311 * documentation.
312 */
313extern NDDS_Transport_DllExport const char *
314NDDS_Transport_Shmem_get_class_name_cEA(NDDS_Transport_Plugin *self);
315
316/*i \ingroup NDDS_Transport_Shmem_Plugin
317 * \brief Realization of NDDS_Transport_String_To_Address_Fcn_cEA for Shmem
318 * transports.
319 *
320 * There is no natural string representation for an "Shmem"
321 * transport address. Will always return 0.
322 *
323 * @param address_out \st_out The corresponding numerical value in IPv6
324 * format.
325 *
326 * @param address_in \st_in
327 *
328 * @see NDDS_Transport_String_To_Address_Fcn_cEA for complete
329 * documentation.
330 */
331extern NDDS_Transport_DllExport RTI_INT32
332NDDS_Transport_Shmem_string_to_address_cEA(
333 NDDS_Transport_Plugin *self,
334 NDDS_Transport_Address_t *address_out,
335 const char *address_in);
336
337/*i \ingroup NDDS_Transport_Shmem_Plugin
338 * \brief Realization of NDDS_Transport_Get_Receive_Interfaces_Fcn_cEA
339 * for Shmem transports.
340 *
341 * @see NDDS_Transport_Get_Receive_Interfaces_Fcn_cEA for complete
342 * documentation.
343 *
344 */
345extern NDDS_Transport_DllExport RTI_INT32
346NDDS_Transport_Shmem_get_receive_interfaces_cEA(
347 NDDS_Transport_Plugin *self,
348 RTI_INT32 *found_more_than_provided_for_out,
349 RTI_INT32 *interface_reported_count_out,
350 NDDS_Transport_Interface_t interface_array_inout[],
351 RTI_INT32 interface_array_size_in);
352
353/*i \ingroup NDDS_Transport_Shmem_Plugin
354 * \brief Returns true if the Shared Memory plugin is usable, false if
355 * otherwise.
356 *
357 * The shared memory plugin may be unusable if a call to create_recv_resource
358 * fails to allocate the necessary shared memory segments due to system resource
359 * constraints.
360 */
361extern NDDS_Transport_DllExport RTIBool
362NDDS_Transport_Shmem_is_valid(NDDS_Transport_Plugin *self);
363
364/*i \ingroup NDDS_Transport_Shmem_Plugin
365 * \brief Checks if a shared memory locator is reachable from the current shared
366 * memory plugin.
367 *
368 * @param self \st_out Indicates if the SHMEM segment associated with port_in
369 * exists.
370 * @param s_reachable_out \st_out RTI_TRUE if the locator is reachable
371 * RTI_FALSE otherwise.
372 *
373 * @param address_in \st_in Input address expected to reach
374 *
375 * @param port_in \st_in Port in the address
376 */
377extern NDDS_Transport_DllExport void
378NDDS_Transport_Shmem_check_locator_reachability(
379 const NDDS_Transport_Plugin *self,
380 RTIBool *shmem_segment_exists,
381 RTIBool *is_reachable_out,
382 const NDDS_Transport_Address_t *address_in,
383 NDDS_Transport_Port_t port_in);
384
385#ifdef __cplusplus
386} /* extern "C" */
387#endif
388
389#endif /* transport_shmem_h */
RTI_UINT32 NDDS_Transport_Port_t
Type for storing RTI Connext RTPS ports.
Definition: transport_common.h:92
NDDS_Transport_Plugin * NDDS_Transport_Shmem_new(const struct NDDS_Transport_Shmem_Property_t *property_in)
Create a new shmem process transport.
Addresses are stored individually as network-ordered bytes.
Definition: transport_common_user.h:384
Storage for the description of a network interface used by a Transport Plugin.
Definition: transport_common.h:204
Base configuration structure that must be inherited by derived Transport Plugin classes.
Definition: transport_interface_user.h:38
Subclass of NDDS_Transport_Property_t allowing specification of parameters that are specific to the s...
Definition: transport_shmem.h:39
RTI_INT32 received_message_count_max
Number of messages that can be buffered in the receive queue.
Definition: transport_shmem.h:46
RTI_INT32 receive_buffer_size
The total number of bytes that can be buffered in the receive queue.
Definition: transport_shmem.h:50
struct NDDS_Transport_Property_t parent
Generic properties of all transport plugins.
Definition: transport_shmem.h:42
RTIBool enable_udp_debugging
Enables UDP debugging when using shared memory.
Definition: transport_shmem.h:54
NDDS_Transport_Port_t udp_debugging_port
Port to which shared memory traffic will be published if NDDS_Transport_Shmem_Property_t::enable_udp_...
Definition: transport_shmem.h:62
NDDS_Transport_Address_t udp_debugging_address
IP address to which shared memory traffic will be published if NDDS_Transport_Shmem_Property_t::enabl...
Definition: transport_shmem.h:58