blob: 8a15725a732d8f3d57795a64f9754e8dee9682d0 [file] [log] [blame]
E. Scott Daniels392168d2019-11-06 15:12:38 -05001
E. Scott Daniels117030c2020-04-10 17:17:02 -04002
E. Scott Daniels392168d2019-11-06 15:12:38 -05003.. This work is licensed under a Creative Commons Attribution 4.0 International License.
4.. SPDX-License-Identifier: CC-BY-4.0
5.. CAUTION: this document is generated from source in doc/src/rtd.
6.. To make changes edit the source and recompile the document.
7.. Do NOT make changes directly to .rst or .md files.
8
9
E. Scott Daniels117030c2020-04-10 17:17:02 -040010
E. Scott Daniels392168d2019-11-06 15:12:38 -050011RMR User's Guide
12============================================================================================
13
Lott, Christopher (cl778h)fe6a8562020-04-06 15:05:22 -040014The RIC Message Router (RMR) is a library for peer-to-peer
15communication. Applications use the library to send and
16receive messages where the message routing and endpoint
17selection is based on the message type rather than DNS host
18name-IP port combinations.
19
20This document contains information that developers need to
21know to use the RMR library. Because the primary
22documentation for the RMR library is a collection of UNIX
23manpages (included in the development package, and available
24via the man command when installed), there is no separate
25"User's Guide." To provide something for the document
26scrapers to find, this is a collection of the RMR manual
27pages formatted directly from their source, which might be a
28bit ragged when combined into a single markup document. Read
29the manual pages :)
E. Scott Daniels392168d2019-11-06 15:12:38 -050030
31
32
33NAME
34--------------------------------------------------------------------------------------------
35
36rmr_alloc_msg
37
38SYNOPSIS
39--------------------------------------------------------------------------------------------
40
41
42::
43
44 #include <rmr/rmr.h>
45 rmr_mbuf_t* rmr_alloc_msg( void* ctx, int size );
46
47
48
49DESCRIPTION
50--------------------------------------------------------------------------------------------
51
52The rmr_alloc_msg function is used to allocate a buffer which
53the user programme can write into and then send through the
54RMR library. The buffer is allocated such that sending it
55requires no additional copying out of the buffer. If the
E. Scott Daniels117030c2020-04-10 17:17:02 -040056value passed in size is less than or equal to 0, then the
57*normal maximum size* supplied on the *rmr_init* call will be
58used. When *size* is greater than zero, the message allocated
59will have at least the indicated number of bytes in the
60payload. There is no maximum size imposed by RMR, however the
61underlying system memory managerment (e.g. malloc) functions
62may impose a limit.
63
64The *ctx* parameter is the void context pointer that was
65returned by the *rmr_init* function.
E. Scott Daniels392168d2019-11-06 15:12:38 -050066
67The pointer to the message buffer returned is a structure
68which has some user application visible fields; the structure
69is described in rmr.h, and is illustrated below.
70
71
72::
73
74 typedef struct {
75 int state;
76 int mtype;
77 int len;
78 unsigned char* payload;
79 unsigned char* xaction;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -040080 int sub_id;
81 int tp_state;
E. Scott Daniels392168d2019-11-06 15:12:38 -050082 } rmr_mbuf_t;
83
84
85
86
87
88state
89
90 Is the current buffer state. Following a call to
91 rmr_send_msg the state indicates whether the buffer was
92 successfully sent which determines exactly what the
93 payload points to. If the send failed, the payload
94 referenced by the buffer is the message that failed to
95 send (allowing the application to attempt a
96 retransmission). When the state is RMR_OK the buffer
97 represents an empty buffer that the application may fill
98 in in preparation to send.
99
100
101mtype
102
103 When sending a message, the application is expected to set
104 this field to the appropriate message type value (as
105 determined by the user programme). Upon send this value
106 determines how the RMR library will route the message. For
107 a buffer which has been received, this field will contain
108 the message type that was set by the sending application.
109
110
111len
112
113 The application using a buffer to send a message is
114 expected to set the length value to the actual number of
115 bytes that it placed into the message. This is likely less
116 than the total number of bytes that the message can carry.
117 For a message buffer that is passed to the application as
118 the result of a receive call, this will be the value that
119 the sending application supplied and should indicate the
120 number of bytes in the payload which are valid.
121
122
123payload
124
125 The payload is a pointer to the actual received data. The
126 user programme may read and write from/to the memory
127 referenced by the payload up until the point in time that
128 the buffer is used on a rmr_send, rmr_call or rmr_reply
129 function call. Once the buffer has been passed back to a
130 RMR library function the user programme should **NOT**
131 make use of the payload pointer.
132
133
134xaction
135
136 The *xaction* field is a pointer to a fixed sized area in
137 the message into which the user may write a transaction
138 ID. The ID is optional with the exception of when the user
139 application uses the rmr_call function to send a message
140 and wait for the reply; the underlying RMR processing
141 expects that the matching reply message will also contain
142 the same data in the *xaction* field.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500143
E. Scott Daniels392168d2019-11-06 15:12:38 -0500144
145sub_id
146
147 This value is the subscription ID. It, in combination with
148 the message type is used by rmr to determine the target
149 endpoint when sending a message. If the application to
150 application protocol does not warrant the use of a
151 subscription ID, the RMR constant RMR_VOID_SUBID should be
152 placed in this field. When an application is forwarding or
153 returning a buffer to the sender, it is the application's
154 responsibility to set/reset this value.
155
156
157tp_state
158
159 For C applications making use of RMR, the state of a
160 transport based failure will often be available via errno.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500161 However, some wrapper environments may not have direct
162 access to the C-lib errno value. RMR send and receive
163 operations will place the current value of errno into this
164 field which should make it available to wrapper functions.
165 User applications are strongly cautioned against relying
166 on the value of errno as some transport mechanisms may not
167 set this value on all calls. This value should also be
168 ignored any time the message status is RMR_OK.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500169
170
171RETURN VALUE
172--------------------------------------------------------------------------------------------
173
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500174The function returns a pointer to a rmr_mbuf structure, or
175NULL on error.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500176
177ERRORS
178--------------------------------------------------------------------------------------------
179
180
181
182ENOMEM
183
184 Unable to allocate memory.
185
186
187SEE ALSO
188--------------------------------------------------------------------------------------------
189
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500190rmr_tralloc_msg(3), rmr_call(3), rmr_free_msg(3),
191rmr_init(3), rmr_init_trace(3), rmr_get_trace(3),
192rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
193rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
194rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
195rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -0500196
197
198NAME
199--------------------------------------------------------------------------------------------
200
201rmr_bytes2meid
202
203SYNOPSIS
204--------------------------------------------------------------------------------------------
205
206
207::
208
209 #include <rmr/rmr.h>
210 int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
211
212
213
214DESCRIPTION
215--------------------------------------------------------------------------------------------
216
217The rmr_bytes2meid function will copy up to *len* butes from
E. Scott Daniels190665f2019-12-09 09:05:22 -0500218*src* to the managed entity ID (meid) field in the message.
219The field is a fixed length, gated by the constant
E. Scott Daniels392168d2019-11-06 15:12:38 -0500220RMR_MAX_MEID and if len is larger than this value, only
221RMR_MAX_MEID bytes will actually be copied.
222
223RETURN VALUE
224--------------------------------------------------------------------------------------------
225
226On success, the actual number of bytes copied is returned, or
227-1 to indicate a hard error. If the length is less than 0, or
228not the same as length passed in, errno is set to one of the
229errors described in the *Errors* section.
230
231ERRORS
232--------------------------------------------------------------------------------------------
233
234If the returned length does not match the length passed in,
235errno will be set to one of the following constants with the
236meaning listed below.
237
238
239
240EINVAL
241
242 The message, or an internal portion of the message, was
243 corrupted or the pointer was invalid.
244
245
246EOVERFLOW
247
248 The length passed in was larger than the maximum length of
249 the field; only a portion of the source bytes were copied.
250
251
252EXAMPLE
253--------------------------------------------------------------------------------------------
254
255
256SEE ALSO
257--------------------------------------------------------------------------------------------
258
259rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_call(3),
260rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_meid(3),
261rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
262rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
263rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
264rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
265rmr_wh_open(3), rmr_wh_send_msg(3)
266
267
268NAME
269--------------------------------------------------------------------------------------------
270
271rmr_bytes2payload
272
273SYNOPSIS
274--------------------------------------------------------------------------------------------
275
276
277::
278
279 #include <rmr/rmr.h>
280 void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char* src, int len )
281
282
283
284DESCRIPTION
285--------------------------------------------------------------------------------------------
286
287This is a convenience function as some wrapper languages
288might not have the ability to directly copy into the payload
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500289buffer. The bytes from *src* for the length given are copied
290to the payload. It is the caller's responsibility to ensure
291that the payload is large enough. Upon successfully copy, the
292len field in the message buffer is updated to reflect the
293number of bytes copied.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500294
295There is little error checking, and no error reporting.
296
297RETURN VALUE
298--------------------------------------------------------------------------------------------
299
300None.
301
302EXAMPLE
303--------------------------------------------------------------------------------------------
304
305
306SEE ALSO
307--------------------------------------------------------------------------------------------
308
309rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2payload(3),
310rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
311rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
312rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
313rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
314rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
315rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
316
317
318NAME
319--------------------------------------------------------------------------------------------
320
321rmr_bytes2xact
322
323SYNOPSIS
324--------------------------------------------------------------------------------------------
325
326
327::
328
329 #include <rmr/rmr.h>
330 int rmr_bytes2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
331
332
333
334DESCRIPTION
335--------------------------------------------------------------------------------------------
336
337The rmr_bytes2xact function will copy up to *len* butes from
338*src* to the transaction ID (xaction) field in the message.
339The field is a fixed length, gated by the constant
340RMR_MAX_XID and if len is larger than this value, only
341RMR_MAX_XID bytes will actually be copied.
342
343
344RETURN VALUE
345--------------------------------------------------------------------------------------------
346
347On success, the actual number of bytes copied is returned,
348or -1 to indicate a hard error. If the length is less than
3490, or not the same as length passed in, errno is set to
350one of the errors described in the *Errors* section.
351
352ERRORS
353--------------------------------------------------------------------------------------------
354
355If the returned length does not match the length passed
356in, errno will be set to one of the following constants
357with the meaning listed below.
358
359
360EINVAL
361
362 The message, or an internal portion of the message, was
363 corrupted or the pointer was invalid.
364
365
366EOVERFLOW
367
368 The length passed in was larger than the maximum length of
369 the field; only a portion of the source bytes were copied.
370
371
372EXAMPLE
373--------------------------------------------------------------------------------------------
374
375
376SEE ALSO
377--------------------------------------------------------------------------------------------
378
379rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_call(3),
380rmr_free_msg(3), rmr_get_meid(3), rmr_get_rcvfd(3),
381rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
382rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
383rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
384rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
385rmr_wh_open(3), rmr_wh_send_msg(3)
386
387
388NAME
389--------------------------------------------------------------------------------------------
390
391rmr_call
392
393SYNOPSIS
394--------------------------------------------------------------------------------------------
395
396
397::
398
399 #include <rmr/rmr.h>
400 extern rmr_mbuf_t* rmr_call( void* vctx, rmr_mbuf_t* msg );
401
402
403
404DESCRIPTION
405--------------------------------------------------------------------------------------------
406
407The rmr_call function sends the user application message to a
408remote endpoint, and waits for a corresponding response
409message before returning control to the user application. The
410user application supplies a completed message buffer, as it
411would for a rmr_send call, but unlike with the send, the
412buffer returned will have the response from the application
413that received the message.
414
415Messages which are received while waiting for the response
416are queued internally by RMR, and are returned to the user
417application when rmr_rcv_msg is invoked. These messages are
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400418returned in the order received, one per call to rmr_rcv_msg.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500419
420Call Timeout
E. Scott Daniels117030c2020-04-10 17:17:02 -0400421~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -0500422
423The rmr_call function implements a timeout failsafe to
424prevent, in most cases, the function from blocking forever.
425The timeout period is **not** based on time (calls to clock
426are deemed too expensive for a low latency system level
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400427library), but instead the period is based on the number of
E. Scott Daniels392168d2019-11-06 15:12:38 -0500428received messages which are not the response. Using a
429non-time mechanism for *timeout* prevents the async queue
430from filling (which would lead to message drops) in an
431environment where there is heavy message traffic.
432
433When the threshold number of messages have been queued
434without receiving a response message, control is returned to
E. Scott Daniels117030c2020-04-10 17:17:02 -0400435the user application and a nil pointer is returned to
E. Scott Daniels392168d2019-11-06 15:12:38 -0500436indicate that no message was received to process. Currently
437the threshold is fixed at 20 messages, though in future
438versions of the library this might be extended to be a
439parameter which the user application may set.
440
441Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -0400442~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -0500443
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400444The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -0500445until one of three conditions occurs:
446
447
448
4491.
450
451 The message is sent without error
452
453
4542.
455
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400456 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -0500457
458
4593.
460
461 The maximum number of retry loops has been attempted
462
463
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400464A retry loop consists of approximately 1000 send attempts
465**without** any intervening calls to *sleep()* or *usleep().*
466The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -05004671000 send attempts is performed before returning to the user
468application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400469initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -0500470allowing the user application to completely disable retires
471(set to 0), or to increase the number of retry loops.
472
473Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -0400474~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -0500475
476The underlying transport mechanism used to send messages is
477configured in *non-blocking* mode. This means that if a
478message cannot be sent immediately the transport mechanism
479will **not** pause with the assumption that the inability to
480send will clear quickly (within a few milliseconds). This
481means that when the retry loop is completely disabled (set to
4820), that the failure to accept a message for sending by the
483underlying mechanisms (software or hardware) will be reported
484immediately to the user application.
485
486It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400487mechanism being used, it is extremely likely that retry
488conditions will happen during normal operations. These are
489completely out of RMR's control, and there is nothing that
490RMR can do to avoid or mitigate these other than by allowing
491RMR to retry the send operation, and even then it is possible
492(e.g., during connection reattempts), that a single retry
493loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500494
495RETURN VALUE
496--------------------------------------------------------------------------------------------
497
498The rmr_call function returns a pointer to a message buffer
499with the state set to reflect the overall state of call
E. Scott Daniels117030c2020-04-10 17:17:02 -0400500processing (see Errors below). In some cases a nil pointer
E. Scott Daniels392168d2019-11-06 15:12:38 -0500501will be returned; when this is the case only *errno* will be
502available to describe the reason for failure.
503
504ERRORS
505--------------------------------------------------------------------------------------------
506
507These values are reflected in the state field of the returned
508message.
509
510
511
512RMR_OK
513
514 The call was successful and the message buffer references
515 the response message.
516
517
518RMR_ERR_CALLFAILED
519
520 The call failed and the value of *errno,* as described
521 below, should be checked for the specific reason.
522
523
524The global "variable" *errno* will be set to one of the
525following values if the overall call processing was not
526successful.
527
528
529
530ETIMEDOUT
531
532 Too many messages were queued before receiving the
533 expected response
534
535
536ENOBUFS
537
538 The queued message ring is full, messages were dropped
539
540
541EINVAL
542
543 A parameter was not valid
544
545
546EAGAIN
547
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400548 The underlying message system was interrupted or the
549 device was busy; the message was **not** sent, and the
550 user application should call this function with the
551 message again.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500552
553
554EXAMPLE
555--------------------------------------------------------------------------------------------
556
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400557The following code snippet shows one way of using the
558rmr_call function, and illustrates how the transaction ID
559must be set.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500560
561
562::
563
564 int retries_left = 5; // max retries on dev not available
565 int retry_delay = 50000; // retry delay (usec)
566 static rmr_mbuf_t* mbuf = NULL; // response msg
E. Scott Daniels117030c2020-04-10 17:17:02 -0400567 msg_t* pm; // application struct for payload
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400568 // get a send buffer and reference the payload
E. Scott Daniels117030c2020-04-10 17:17:02 -0400569 mbuf = rmr_alloc_msg( mr, sizeof( pm->req ) );
E. Scott Daniels392168d2019-11-06 15:12:38 -0500570 pm = (msg_t*) mbuf->payload;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400571 // generate an xaction ID and fill in payload with data and msg type
E. Scott Daniels392168d2019-11-06 15:12:38 -0500572 snprintf( mbuf->xaction, RMR_MAX_XID, "%s", gen_xaction() );
573 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
574 mbuf->mtype = MT_REQ;
E. Scott Daniels392168d2019-11-06 15:12:38 -0500575 msg = rmr_call( mr, msg );
576 if( ! msg ) { // probably a timeout and no msg received
577 return NULL; // let errno trickle up
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400578 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500579 if( mbuf->state != RMR_OK ) {
580 while( retries_left-- > 0 && // loop as long as eagain
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400581 errno == EAGAIN &&
582 (msg = rmr_call( mr, msg )) != NULL &&
E. Scott Daniels392168d2019-11-06 15:12:38 -0500583 mbuf->state != RMR_OK ) {
584 usleep( retry_delay );
585 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500586 if( mbuf == NULL || mbuf->state != RMR_OK ) {
587 rmr_free_msg( mbuf ); // safe if nil
588 return NULL;
589 }
590 }
591 // do something with mbuf
592
593
594
595SEE ALSO
596--------------------------------------------------------------------------------------------
597
598rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
599rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
600rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
601rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
602rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
603
604
605NAME
606--------------------------------------------------------------------------------------------
607
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400608rmr_close
E. Scott Daniels392168d2019-11-06 15:12:38 -0500609
610SYNOPSIS
611--------------------------------------------------------------------------------------------
612
613
614::
615
616 #include <rmr/rmr.h>
617 void rmr_close( void* vctx )
618
619
620
621DESCRIPTION
622--------------------------------------------------------------------------------------------
623
624The rmr_close function closes the listen socket effectively
625cutting the application off. The route table listener is also
626stopped. Calls to rmr_rcv_msg() will fail with unpredictable
627error codes, and calls to rmr_send_msg(), rmr_call(), and
628rmr_rts_msg() will have unknown results.
629
630
631SEE ALSO
632--------------------------------------------------------------------------------------------
633
634rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
635rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
636rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
637rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
638rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
639rmr_wh_send_msg(3)
640
641
642NAME
643--------------------------------------------------------------------------------------------
644
645rmr_free_msg
646
647SYNOPSIS
648--------------------------------------------------------------------------------------------
649
650
651::
652
653 #include <rmr/rmr.h>
654 void rmr_free_msg( rmr_mbuf_t* mbuf );
655
656
657
658DESCRIPTION
659--------------------------------------------------------------------------------------------
660
661The message buffer is returned to the pool, or the associated
662memory is released depending on the needs of the underlying
663messaging system. This allows the user application to release
664a buffer that is not going to be used. It is safe to pass a
665nil pointer to this function, and doing so does not result in
666a change to the value of errrno.
667
668After calling, the user application should **not** use any of
669the pointers (transaction ID, or payload) which were
670available.
671
672SEE ALSO
673--------------------------------------------------------------------------------------------
674
675rmr_alloc_msg(3), rmr_call(3), rmr_init(3),
676rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
677rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
678rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
679rmr_ring_free(3)
680
681
682NAME
683--------------------------------------------------------------------------------------------
684
E. Scott Daniels117030c2020-04-10 17:17:02 -0400685rmr_get_const
686
687SYNOPSIS
688--------------------------------------------------------------------------------------------
689
690
691::
692
693 #include <rmr/rmr.h>
694 unsigned char* rmr_get_const();
695
696
697
698DESCRIPTION
699--------------------------------------------------------------------------------------------
700
701The rmr_get_const function is a convenience function for
702wrappers which do not have the ability to "compile in" RMR
703constants. The function will build a nil terminated string
704containing JSON which defines the RMR constants that C and Go
705applications have at compile time via the rmr.h header file.
706
707All values are represented as strings and the JSON format is
708illustrated in the following (partial) example:
709
710
711::
712
713 {
714 "RMR_MAX_XID": "32",
715 "RMR_OK": "0",
716 "RMR_ERR_BADARG", "1",
717 "RMR_ERR_NOENDPT" "2"
718 }
719
720
721
722RETURN VALUE
723--------------------------------------------------------------------------------------------
724
725On success, a pointer to a string containing the JSON
726defining constant and value pairs. On failure a nil pointer
727is returned.
728
729SEE ALSO
730--------------------------------------------------------------------------------------------
731
732rmr(7)
733
734
735NAME
736--------------------------------------------------------------------------------------------
737
E. Scott Daniels392168d2019-11-06 15:12:38 -0500738rmr_get_meid
739
740SYNOPSIS
741--------------------------------------------------------------------------------------------
742
743
744::
745
746 #include <rmr/rmr.h>
747 char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest )
748
749
750
751DESCRIPTION
752--------------------------------------------------------------------------------------------
753
E. Scott Daniels190665f2019-12-09 09:05:22 -0500754The rmr_get_meid function will copy the managed entity ID
E. Scott Daniels392168d2019-11-06 15:12:38 -0500755(meid) field from the message into the *dest* buffer provided
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500756by the user. The buffer referenced by *dest* is assumed to be
757at least RMR_MAX_MEID bytes in length. If *dest* is NULL,
758then a buffer is allocated (the calling application is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500759expected to free when the buffer is no longer needed).
760
761RETURN VALUE
762--------------------------------------------------------------------------------------------
763
764On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500765*dest* was supplied, then this is just a pointer to the
766caller's buffer. If *dest* was NULL, this is a pointer to the
767allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500768returned and errno is set as described below.
769
770ERRORS
771--------------------------------------------------------------------------------------------
772
773If an error occurs, the value of the global variable errno
774will be set to one of the following with the indicated
775meaning.
776
777
778
779EINVAL
780
781 The message, or an internal portion of the message, was
782 corrupted or the pointer was invalid.
783
784
785ENOMEM
786
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500787 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -0500788 possible to allocate a buffer using malloc().
789
790
791SEE ALSO
792--------------------------------------------------------------------------------------------
793
794rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
795rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
796rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
797rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
798rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
799rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
800rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
801
802
803NAME
804--------------------------------------------------------------------------------------------
805
806rmr_get_rcvfd
807
808SYNOPSIS
809--------------------------------------------------------------------------------------------
810
811
812::
813
814 #include <rmr/rmr.h>
815 void* rmr_get_rcvfd( void* ctx )
816
817
818
819DESCRIPTION
820--------------------------------------------------------------------------------------------
821
822The rmr_get_rcvfd function returns a file descriptor which
823may be given to epoll_wait() by an application that wishes to
824use event poll in a single thread rather than block on the
825arrival of a message via calls to rmr_rcv_msg(). When
826epoll_wait() indicates that this file descriptor is ready, a
827call to rmr_rcv_msg() will not block as at least one message
828has been received.
829
830The context (ctx) pointer passed in is the pointer returned
831by the call to rmr_init().
832
E. Scott Daniels392168d2019-11-06 15:12:38 -0500833RETURN VALUE
834--------------------------------------------------------------------------------------------
835
836The rmr_get_rcvfd function returns a file descriptor greater
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400837or equal to 0 on success and -1 on error.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500838
839ERRORS
840--------------------------------------------------------------------------------------------
841
842The following error values are specifically set by this RMR
843function. In some cases the error message of a system call is
844propagated up, and thus this list might be incomplete.
845
846
847EINVAL
848
849 The use of this function is invalid in this environment.
850
851
852EXAMPLE
853--------------------------------------------------------------------------------------------
854
855The following short code bit illustrates the use of this
856function. Error checking has been omitted for clarity.
857
858
859::
860
861 #include <stdio.h>
862 #include <stdlib.h>
863 #include <sys/epoll.h>
864 #include <rmr/rmr.h>
865 int main() {
866 int rcv_fd; // pollable fd
867 void* mrc; //msg router context
868 struct epoll_event events[10]; // support 10 events to poll
869 struct epoll_event epe; // event definition for event to listen to
870 int ep_fd = -1;
871 rmr_mbuf_t* msg = NULL;
872 int nready;
873 int i;
E. Scott Daniels117030c2020-04-10 17:17:02 -0400874 int norm_msg_size = 1500; // 95% messages are less than this
875 mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
E. Scott Daniels392168d2019-11-06 15:12:38 -0500876 rcv_fd = rmr_get_rcvfd( mrc );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400877 ep_fd = epoll_create1( 0 ); // initialise epoll environment
E. Scott Daniels392168d2019-11-06 15:12:38 -0500878 epe.events = EPOLLIN;
879 epe.data.fd = rcv_fd;
880 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
E. Scott Daniels392168d2019-11-06 15:12:38 -0500881 while( 1 ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400882 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
883 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
884 if( events[i].data.fd == rcv_fd ) { // RMR has something
E. Scott Daniels392168d2019-11-06 15:12:38 -0500885 msg = rmr_rcv_msg( mrc, msg );
886 if( msg ) {
887 // do something with msg
888 }
889 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500890 // check for other ready fds....
891 }
892 }
893 }
894
895
896
897SEE ALSO
898--------------------------------------------------------------------------------------------
899
900rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
901rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
902rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
903rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
904rmr_ring_free(3)
905
906
907NAME
908--------------------------------------------------------------------------------------------
909
910rmr_get_src
911
912SYNOPSIS
913--------------------------------------------------------------------------------------------
914
915
916::
917
918 #include <rmr/rmr.h>
919 unsigned char* rmr_get_src( rmr_mbuf_t* mbuf, unsigned char* dest )
920
921
922
923DESCRIPTION
924--------------------------------------------------------------------------------------------
925
926The rmr_get_src function will copy the *source* information
927from the message to a buffer (dest) supplied by the user. In
928an RMr message, the source is the sender's information that
929is used for return to sender function calls, and is generally
930the hostname and port in the form *name*. The source might be
931an IP address port combination; the data is populated by the
932sending process and the only requirement is that it be
933capable of being used to start a TCP session with the sender.
934
935The maximum size allowed by RMr is 64 bytes (including the
936nil string terminator), so the user must ensure that the
937destination buffer given is at least 64 bytes.
938
939RETURN VALUE
940--------------------------------------------------------------------------------------------
941
942On success, a pointer to the destination buffer is given as a
943convenience to the user programme. On failure, a nil pointer
944is returned and the value of errno is set.
945
946ERRORS
947--------------------------------------------------------------------------------------------
948
949If an error occurs, the value of the global variable errno
950will be set to one of the following with the indicated
951meaning.
952
953
954
955EINVAL
956
957 The message, or an internal portion of the message, was
958 corrupted or the pointer was invalid.
959
960
961SEE ALSO
962--------------------------------------------------------------------------------------------
963
964rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
965rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
966rmr_get_srcip(3), rmr_payload_size(3), rmr_send_msg(3),
967rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
968rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
969rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
970rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
971
972
973NAME
974--------------------------------------------------------------------------------------------
975
976rmr_get_srcip
977
978SYNOPSIS
979--------------------------------------------------------------------------------------------
980
981
982::
983
984 #include <rmr/rmr.h>
985 unsigned char* rmr_get_srcip( rmr_mbuf_t* mbuf, unsigned char* dest )
986
987
988
989DESCRIPTION
990--------------------------------------------------------------------------------------------
991
992The rmr_get_srcip function will copy the *source IP address*
993from the message to a buffer (dest) supplied by the user. In
994an RMr message, the source IP address is the sender's
995information that is used for return to sender function calls;
996this function makes it available to the user application. The
997address is maintained as IP:port where *IP* could be either
998an IPv6 or IPv4 address depending on what was provided by the
999sending application.
1000
1001The maximum size allowed by RMr is 64 bytes (including the
1002nil string terminator), so the user must ensure that the
1003destination buffer given is at least 64 bytes. The user
1004application should use the RMr constant RMR_MAX_SRC to ensure
1005that the buffer supplied is large enough, and to protect
1006against future RMr enhancements which might increase the
1007address buffer size requirement.
1008
1009RETURN VALUE
1010--------------------------------------------------------------------------------------------
1011
1012On success, a pointer to the destination buffer is given as a
1013convenience to the user programme. On failure, a nil pointer
1014is returned and the value of errno is set.
1015
1016ERRORS
1017--------------------------------------------------------------------------------------------
1018
1019If an error occurs, the value of the global variable errno
1020will be set to one of the following with the indicated
1021meaning.
1022
1023
1024
1025EINVAL
1026
1027 The message, or an internal portion of the message, was
1028 corrupted or the pointer was invalid.
1029
1030
1031SEE ALSO
1032--------------------------------------------------------------------------------------------
1033
1034rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
1035rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
1036rmr_get_src(3), rmr_payload_size(3), rmr_send_msg(3),
1037rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1038rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1039rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1040rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
1041
1042
1043NAME
1044--------------------------------------------------------------------------------------------
1045
1046rmr_get_trace
1047
1048SYNOPSIS
1049--------------------------------------------------------------------------------------------
1050
1051
1052::
1053
1054 #include <rmr/rmr.h>
1055 int rmr_get_trace( rmr_mbuf_t* mbuf, unsigned char* dest, int size )
1056
1057
1058
1059DESCRIPTION
1060--------------------------------------------------------------------------------------------
1061
1062The rmr_get_trace function will copy the trace information
1063from the message into the user's allocated memory referenced
1064by dest. The size parameter is assumed to be the maximum
1065number of bytes which can be copied (size of the destination
1066buffer).
1067
1068RETURN VALUE
1069--------------------------------------------------------------------------------------------
1070
1071On success, the number of bytes actually copied is returned.
1072If the return value is 0, no bytes copied, then the reason
1073could be that the message pointer was nil, or the size
1074parameter was <= 0.
1075
1076SEE ALSO
1077--------------------------------------------------------------------------------------------
1078
1079rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
1080rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
1081rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
1082rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
1083rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1084rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1085rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1086rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
1087rmr_set_trace(3), rmr_trace_ref(3)
1088
1089
1090NAME
1091--------------------------------------------------------------------------------------------
1092
1093rmr_get_trlen
1094
1095SYNOPSIS
1096--------------------------------------------------------------------------------------------
1097
1098
1099::
1100
1101 #include <rmr/rmr.h>
1102 int rmr_get_trlen( rmr_mbuf_t* msg );
1103
1104
1105
1106DESCRIPTION
1107--------------------------------------------------------------------------------------------
1108
1109Given a message buffer, this function returns the amount of
1110space (bytes) that have been allocated for trace data. If no
1111trace data has been allocated, then 0 is returned.
1112
1113RETURN VALUE
1114--------------------------------------------------------------------------------------------
1115
1116The number of bytes allocated for trace information in the
1117given message.
1118
1119ERRORS
1120--------------------------------------------------------------------------------------------
1121
1122
1123
1124INVAL
1125
1126 Parameter(s) passed to the function were not valid.
1127
1128
1129SEE ALSO
1130--------------------------------------------------------------------------------------------
1131
1132rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1133rmr_get_trace(3), rmr_init(3), rmr_init_trace(3),
1134rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
1135rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1136rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
1137rmr_set_trace(3), rmr_tralloc_msg(3)
1138
1139
1140NAME
1141--------------------------------------------------------------------------------------------
1142
1143rmr_get_xact
1144
1145SYNOPSIS
1146--------------------------------------------------------------------------------------------
1147
1148
1149::
1150
1151 #include <rmr/rmr.h>
1152 char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest )
1153
1154
1155
1156DESCRIPTION
1157--------------------------------------------------------------------------------------------
1158
1159The rmr_get_xact function will copy the transaction field
1160from the message into the *dest* buffer provided by the user.
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001161The buffer referenced by *dest* is assumed to be at least
1162RMR_MAX_XID bytes in length. If *dest* is NULL, then a buffer
1163is allocated (the calling application is expected to free
1164when the buffer is no longer needed).
E. Scott Daniels392168d2019-11-06 15:12:38 -05001165
1166RETURN VALUE
1167--------------------------------------------------------------------------------------------
1168
1169On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001170*dest* was supplied, then this is just a pointer to the
1171caller's buffer. If *dest* was NULL, this is a pointer to the
1172allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -05001173returned and errno is set as described below.
1174
1175ERRORS
1176--------------------------------------------------------------------------------------------
1177
1178If an error occurs, the value of the global variable errno
1179will be set to one of the following with the indicated
1180meaning.
1181
1182
1183
1184EINVAL
1185
1186 The message, or an internal portion of the message, was
1187 corrupted or the pointer was invalid.
1188
1189
1190ENOMEM
1191
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001192 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -05001193 possible to allocate a buffer using malloc().
1194
1195
1196SEE ALSO
1197--------------------------------------------------------------------------------------------
1198
1199rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
1200rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
1201rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
1202rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1203rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1204rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1205rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
1206
1207
1208NAME
1209--------------------------------------------------------------------------------------------
1210
1211rmr_init
1212
1213SYNOPSIS
1214--------------------------------------------------------------------------------------------
1215
1216
1217::
1218
1219 #include <rmr/rmr.h>
E. Scott Daniels117030c2020-04-10 17:17:02 -04001220 void* rmr_init( char* proto_port, int norm_msg_size, int flags );
E. Scott Daniels392168d2019-11-06 15:12:38 -05001221
1222
1223
1224DESCRIPTION
1225--------------------------------------------------------------------------------------------
1226
1227The rmr_init function prepares the environment for sending
1228and receiving messages. It does so by establishing a worker
1229thread (pthread) which subscribes to a route table generator
1230which provides the necessary routing information for the RMR
1231library to send messages.
1232
1233*Port* is used to listen for connection requests from other
E. Scott Daniels117030c2020-04-10 17:17:02 -04001234RMR based applications. The *norm_msg_size* parameter is used
1235to allocate receive buffers and should be set to what the
1236user application expects to be a size which will hold the
1237vast majority of expected messages. When computing the size,
1238the application should consider the usual payload size
1239**and** the maximum trace data size that will be used. This
1240value is also used as the default message size when
1241allocating message buffers (when a zero size is given to
1242rmr_alloc_msg(); see the rmr_alloc_msg() manual page).
1243Messages arriving which are longer than the given normal size
1244will cause RMR to allocate a new buffer which is large enough
1245for the arriving message.
1246
1247Starting with version 3.8.0 RMR no longer places a maximum
1248buffer size for received messages. The underlying system
1249memory manager might impose such a limit and the attempt to
1250allocate a buffer larger than that limit will likely result
1251in an application abort. Other than the potential performance
1252impact from extra memory allocation and release, there is no
1253penality to the user programme for specifyning a normal
1254buffer size which is usually smaller than received buffers.
1255Similarly, the only penality to the application for over
1256specifying the normal buffer size might be a larger memory
1257footprint.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001258
1259*Flags* allows for selection of some RMr options at the time
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001260of initialisation. These are set by ORing RMRFL constants
E. Scott Daniels392168d2019-11-06 15:12:38 -05001261from the RMr header file. Currently the following flags are
1262supported:
1263
1264
1265
1266RMRFL_NONE
1267
1268 No flags are set.
1269
1270
1271RMRFL_NOTHREAD
1272
1273 The route table collector thread is not to be started.
1274 This should only be used by the route table generator
1275 application if it is based on RMr.
1276
1277
1278RMRFL_MTCALL
1279
1280 Enable multi-threaded call support.
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001281
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001282
1283RMRFL_NOLOCK
1284
1285 Some underlying transport providers (e.g. SI95) enable
1286 locking to be turned off if the user application is single
1287 threaded, or otherwise can guarantee that RMR functions
1288 will not be invoked concurrently from different threads.
1289 Turning off locking can help make message receipt more
1290 efficient. If this flag is set when the underlying
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001291 transport does not support disabling locks, it will be
1292 ignored.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001293
1294
1295Multi-threaded Calling
E. Scott Daniels117030c2020-04-10 17:17:02 -04001296~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05001297
1298The support for an application to issue a *blocking call* by
1299the rmr_call() function was limited such that only user
1300applications which were operating in a single thread could
1301safely use the function. Further, timeouts were message count
1302based and not time unit based. Multi-threaded call support
1303adds the ability for a user application with multiple threads
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001304to invoke a blocking call function with the guarantee that
E. Scott Daniels392168d2019-11-06 15:12:38 -05001305the correct response message is delivered to the thread. The
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001306additional support is implemented with the *rmr_mt_call()*
1307and *rmr_mt_rcv()* function calls.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001308
1309Multi-threaded call support requires the user application to
1310specifically enable it when RMr is initialised. This is
1311necessary because a second, dedicated, receiver thread must
1312be started, and requires all messages to be examined and
1313queued by this thread. The additional overhead is minimal,
1314queuing information is all in the RMr message header, but as
1315an additional process is necessary the user application must
1316"opt in" to this approach.
1317
1318
1319ENVIRONMENT
1320--------------------------------------------------------------------------------------------
1321
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001322As a part of the initialisation process rmr_init reads
1323environment variables to configure itself. The following
1324variables are used if found.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001325
1326
1327
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001328RMR_ASYNC_CONN
E. Scott Daniels392168d2019-11-06 15:12:38 -05001329
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001330 Allows the async connection mode to be turned off (by
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001331 setting the value to 0). When set to 1, or missing from
1332 the environment, RMR will invoke the connection interface
1333 in the transport mechanism using the non-blocking (async)
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001334 mode. This will likely result in many "soft failures"
1335 (retry) until the connection is established, but allows
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001336 the application to continue unimpeded should the
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001337 connection be slow to set up.
1338
1339
1340RMR_BIND_IF
1341
1342 This provides the interface that RMR will bind listen
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001343 ports to, allowing for a single interface to be used
1344 rather than listening across all interfaces. This should
1345 be the IP address assigned to the interface that RMR
1346 should listen on, and if not defined RMR will listen on
1347 all interfaces.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001348
1349
1350RMR_CTL_PORT
1351
1352 This variable defines the port that RMR should open for
1353 communications with Route Manager, and other RMR control
1354 applications. If not defined, the port 4561 is assumed.
1355
1356 Previously, the RMR_RTG_SVC (route table generator service
1357 port) was used to define this port. However, a future
1358 version of Route Manager will require RMR to connect and
1359 request tables, thus that variable is now used to supply
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001360 the Route Manager's well-known address and port.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001361
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001362 To maintain backwards compatibility with the older Route
1363 Manager versions, the presence of this variable in the
1364 environment will shift RMR's behaviour with respect to the
1365 default value used when RMR_RTG_SVC is **not** defined.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001366
1367 When RMR_CTL_PORT is **defined:** RMR assumes that Route
1368 Manager requires RMR to connect and request table updates
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001369 is made, and the default well-known address for Route
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001370 manager is used (routemgr:4561).
1371
1372 When RMR_CTL_PORT is **undefined:** RMR assumes that Route
1373 Manager will connect and push table updates, thus the
1374 default listen port (4561) is used.
1375
1376 To avoid any possible misinterpretation and/or incorrect
1377 assumptions on the part of RMR, it is recommended that
1378 both the RMR_CTL_PORT and RMR_RTG_SVC be defined. In the
1379 case where both variables are defined, RMR will behave
1380 exactly as is communicated with the variable's values.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001381
1382
1383RMR_RTG_SVC
1384
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001385 The value of this variable depends on the Route Manager in
1386 use.
1387
1388 When the Route Manager is expecting to connect to an xAPP
1389 and push route tables, this variable must indicate the
1390 port which RMR should use to listen for these connections.
1391
1392 When the Route Manager is expecting RMR to connect and
1393 request a table update during initialisation, the variable
1394 should be the host of the Route Manager process.
1395
1396 The RMR_CTL_PORT variable (added with the support of
1397 sending table update requests to Route manager), controls
1398 the behaviour if this variable is not set. See the
1399 description of that variable for details.
1400
1401
1402RMR_HR_LOG
1403
1404 By default RMR writes messages to standard error
1405 (incorrectly referred to as log messages) in human
1406 readable format. If this environment variable is set to 0,
1407 the format of standard error messages might be written in
1408 some format not easily read by humans. If missing, a value
1409 of 1 is assumed.
1410
1411
1412RMR_LOG_VLEVEL
1413
1414 This is a numeric value which corresponds to the verbosity
1415 level used to limit messages written to standard error.
1416 The lower the number the less chatty RMR functions are
1417 during execution. The following is the current
1418 relationship between the value set on this variable and
1419 the messages written:
1420
1421
14220
1423
1424 Off; no messages of any sort are written.
1425
1426
14271
1428
1429 Only critical messages are written (default if this
1430 variable does not exist)
1431
1432
14332
1434
1435 Errors and all messages written with a lower value.
1436
1437
14383
1439
1440 Warnings and all messages written with a lower value.
1441
1442
14434
1444
1445 Informational and all messages written with a lower
1446 value.
1447
1448
14495
1450
1451 Debugging mode -- all messages written, however this
1452 requires RMR to have been compiled with debugging
1453 support enabled.
1454
1455
1456
1457RMR_RTG_ISRAW
1458
1459 **Deprecated.** Should be set to 1 if the route table
1460 generator is sending "plain" messages (not using RMR to
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001461 send messages), 0 if the RTG is using RMR to send. The
1462 default is 1 as we don't expect the RTG to use RMR.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001463
1464 This variable is only recognised when using the NNG
1465 transport library as it is not possible to support NNG
1466 "raw" communications with other transport libraries. It is
1467 also necessary to match the value of this variable with
1468 the capabilities of the Route Manager; at some point in
1469 the future RMR will assume that all Route Manager messages
1470 will arrive via an RMR connection and will ignore this
1471 variable.
1472
1473RMR_SEED_RT
1474
1475 This is used to supply a static route table which can be
1476 used for debugging, testing, or if no route table
1477 generator process is being used to supply the route table.
1478 If not defined, no static table is used and RMR will not
1479 report *ready* until a table is received. The static route
1480 table may contain both the route table (between newrt
1481 start and end records), and the MEID map (between meid_map
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001482 start and end records).
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001483
1484RMR_SRC_ID
1485
1486 This is either the name or IP address which is placed into
1487 outbound messages as the message source. This will used
1488 when an RMR based application uses the rmr_rts_msg()
1489 function to return a response to the sender. If not
1490 supplied RMR will use the hostname which in some container
1491 environments might not be routable.
1492
1493 The value of this variable is also used for Route Manager
1494 messages which are sent via an RMR connection.
1495
1496RMR_VCTL_FILE
1497
1498 This supplies the name of a verbosity control file. The
1499 core RMR functions do not produce messages unless there is
1500 a critical failure. However, the route table collection
1501 thread, not a part of the main message processing
1502 component, can write additional messages to standard
1503 error. If this variable is set, RMR will extract the
1504 verbosity level for these messages (0 is silent) from the
1505 first line of the file. Changes to the file are detected
1506 and thus the level can be changed dynamically, however RMR
1507 will only suss out this variable during initialisation, so
1508 it is impossible to enable verbosity after startup.
1509
1510RMR_WARNINGS
1511
1512 If set to 1, RMR will write some warnings which are
1513 non-performance impacting. If the variable is not defined,
1514 or set to 0, RMR will not write these additional warnings.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001515
1516
1517RETURN VALUE
1518--------------------------------------------------------------------------------------------
1519
1520The rmr_init function returns a void pointer (a contex if you
1521will) that is passed as the first parameter to nearly all
1522other RMR functions. If rmr_init is unable to properly
1523initialise the environment, NULL is returned and errno is set
1524to an appropriate value.
1525
1526ERRORS
1527--------------------------------------------------------------------------------------------
1528
1529The following error values are specifically set by this RMR
1530function. In some cases the error message of a system call is
1531propagated up, and thus this list might be incomplete.
1532
1533
1534ENOMEM
1535
1536 Unable to allocate memory.
1537
1538
1539EXAMPLE
1540--------------------------------------------------------------------------------------------
1541
1542
1543::
1544
1545 void* uh;
1546 rmr_mbuf* buf = NULL;
1547 uh = rmr_init( "43086", 4096, 0 );
1548 buf = rmr_rcv_msg( uh, buf );
1549
1550
1551
1552SEE ALSO
1553--------------------------------------------------------------------------------------------
1554
1555rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1556rmr_get_rcvfd(3), rmr_mt_call(3), rmr_mt_rcv(3),
1557rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
1558rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
1559rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
1560rmr_ring_free(3)
1561
1562
1563NAME
1564--------------------------------------------------------------------------------------------
1565
1566rmr_init_trace
1567
1568SYNOPSIS
1569--------------------------------------------------------------------------------------------
1570
1571
1572::
1573
1574 #include <rmr/rmr.h>
1575 void* rmr_init_trace( void* ctx )
1576
1577
1578
1579DESCRIPTION
1580--------------------------------------------------------------------------------------------
1581
1582The rmr_init_trace function establishes the default trace
1583space placed in each message buffer allocated with
1584rmr_alloc_msg(). If this function is never called, then no
1585trace space is allocated by default into any message buffer.
1586
1587Trace space allows the user application to pass some trace
1588token, or other data with the message, but outside of the
1589payload. Trace data may be added to any message with
1590rmr_set_trace(), and may be extracted from a message with
1591rmr_get_trace(). The number of bytes that a message contains
1592for/with trace data can be determined by invoking
1593rmr_get_trlen().
1594
1595This function may be safely called at any time during the
1596life of the user programme to (re)set the default trace space
1597reserved. If the user programme needs to allocate a message
1598with trace space of a different size than is allocated by
1599default, without fear of extra overhead of reallocating a
1600message later, the rmr_tralloc_msg() function can be used.
1601
1602RETURN VALUE
1603--------------------------------------------------------------------------------------------
1604
1605A value of 1 is returned on success, and 0 on failure. A
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001606failure indicates that the RMr context (a void pointer passed
1607to this function was not valid.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001608
1609SEE ALSO
1610--------------------------------------------------------------------------------------------
1611
1612rmr_alloc_msg(3), rmr_tr_alloc_msg(3), rmr_call(3),
1613rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_trace(3),
1614rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
1615rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1616rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1617rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
1618
1619
1620NAME
1621--------------------------------------------------------------------------------------------
1622
1623rmr_mt_call
1624
1625SYNOPSIS
1626--------------------------------------------------------------------------------------------
1627
1628
1629::
1630
1631 #include <rmr/rmr.h>
1632 extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* msg, int id, int timeout );
1633
1634
1635
1636DESCRIPTION
1637--------------------------------------------------------------------------------------------
1638
1639The rmr_mt_call function sends the user application message
1640to a remote endpoint, and waits for a corresponding response
1641message before returning control to the user application. The
1642user application supplies a completed message buffer, as it
1643would for a rmr_send_msg call, but unlike with a send, the
1644buffer returned will have the response from the application
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001645that received the message. The thread invoking the
1646*rmr_mt_call()* will block until a message arrives or until
E. Scott Daniels392168d2019-11-06 15:12:38 -05001647*timeout* milliseconds has passed; which ever comes first.
1648Using a timeout value of zero (0) will cause the thread to
1649block without a timeout.
1650
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001651The *id* supplied as the third parameter is an integer in the
1652range of 2 through 255 inclusive. This is a caller defined
1653"thread number" and is used to match the response message
1654with the correct user application thread. If the ID value is
1655not in the proper range, the attempt to make the call will
1656fail.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001657
1658Messages which are received while waiting for the response
1659are queued on a *normal* receive queue and will be delivered
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001660to the user application with the next invocation of
1661*rmr_mt_rcv()* or *rmr_rvv_msg().* by RMR, and are returned
E. Scott Daniels392168d2019-11-06 15:12:38 -05001662to the user application when rmr_rcv_msg is invoked. These
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001663messages are returned in the order received, one per call to
E. Scott Daniels392168d2019-11-06 15:12:38 -05001664rmr_rcv_msg.
1665
E. Scott Daniels392168d2019-11-06 15:12:38 -05001666The Transaction ID
E. Scott Daniels117030c2020-04-10 17:17:02 -04001667~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05001668
1669The user application is responsible for setting the value of
1670the transaction ID field before invoking *rmr_mt_call.* The
1671transaction ID is a RMR_MAX_XID byte field that is used to
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001672match the response message when it arrives. RMR will compare
E. Scott Daniels392168d2019-11-06 15:12:38 -05001673**all** of the bytes in the field, so the caller must ensure
1674that they are set correctly to avoid missing the response
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001675message. The application which returns the response message
E. Scott Daniels392168d2019-11-06 15:12:38 -05001676is also expected to ensure that the return buffer has the
1677matching transaction ID. This can be done transparently if
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001678the application uses the *rmr_rts_msg()* function and does
E. Scott Daniels392168d2019-11-06 15:12:38 -05001679not adjust the transaction ID.
1680
1681Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04001682~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05001683
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001684The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05001685until one of three conditions occurs:
1686
1687
1688
16891.
1690
1691 The message is sent without error
1692
1693
16942.
1695
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001696 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05001697
1698
16993.
1700
1701 The maximum number of retry loops has been attempted
1702
1703
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001704A retry loop consists of approximately 1000 send attempts
1705**without** any intervening calls to *sleep()* or *usleep().*
1706The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050017071000 send attempts is performed before returning to the user
1708application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001709initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05001710allowing the user application to completely disable retires
1711(set to 0), or to increase the number of retry loops.
1712
1713Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -04001714~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05001715
1716The underlying transport mechanism used to send messages is
1717configured in *non-blocking* mode. This means that if a
1718message cannot be sent immediately the transport mechanism
1719will **not** pause with the assumption that the inability to
1720send will clear quickly (within a few milliseconds). This
1721means that when the retry loop is completely disabled (set to
17220), that the failure to accept a message for sending by the
1723underlying mechanisms (software or hardware) will be reported
1724immediately to the user application.
1725
1726It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001727mechanism being used, it is extremely likely that retry
1728conditions will happen during normal operations. These are
1729completely out of RMR's control, and there is nothing that
1730RMR can do to avoid or mitigate these other than by allowing
1731RMR to retry the send operation, and even then it is possible
1732(e.g., during connection reattempts), that a single retry
1733loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001734
1735RETURN VALUE
1736--------------------------------------------------------------------------------------------
1737
1738The rmr_mt_call function returns a pointer to a message
1739buffer with the state set to reflect the overall state of
1740call processing. If the state is RMR_OK then the buffer
1741contains the response message; otherwise the state indicates
1742the error encountered while attempting to send the message.
1743
1744If no response message is received when the timeout period
1745has expired, a nil pointer will be returned (NULL).
1746
1747ERRORS
1748--------------------------------------------------------------------------------------------
1749
1750These values are reflected in the state field of the returned
1751message.
1752
1753
1754
1755RMR_OK
1756
1757 The call was successful and the message buffer references
1758 the response message.
1759
1760
1761RMR_ERR_BADARG
1762
1763 An argument passed to the function was invalid.
1764
1765
1766RMR_ERR_CALLFAILED
1767
1768 The call failed and the value of *errno,* as described
1769 below, should be checked for the specific reason.
1770
1771
1772RMR_ERR_NOENDPT
1773
1774 An endpoint associated with the message type could not be
1775 found in the route table.
1776
1777
1778RMR_ERR_RETRY
1779
1780 The underlying transport mechanism was unable to accept
1781 the message for sending. The user application can retry
1782 the call operation if appropriate to do so.
1783
1784
1785The global "variable" *errno* will be set to one of the
1786following values if the overall call processing was not
1787successful.
1788
1789
1790
1791ETIMEDOUT
1792
1793 Too many messages were queued before receiving the
1794 expected response
1795
1796
1797ENOBUFS
1798
1799 The queued message ring is full, messages were dropped
1800
1801
1802EINVAL
1803
1804 A parameter was not valid
1805
1806
1807EAGAIN
1808
1809 The underlying message system wsa interrupted or the
1810 device was busy; the message was **not** sent, and user
1811 application should call this function with the message
1812 again.
1813
1814
1815EXAMPLE
1816--------------------------------------------------------------------------------------------
1817
1818The following code bit shows one way of using the rmr_mt_call
1819function, and illustrates how the transaction ID must be set.
1820
1821
1822::
1823
1824 int retries_left = 5; // max retries on dev not available
1825 static rmr_mbuf_t* mbuf = NULL; // response msg
E. Scott Daniels117030c2020-04-10 17:17:02 -04001826 msg_t* pm; // appl message struct (payload)
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001827 // get a send buffer and reference the payload
E. Scott Daniels117030c2020-04-10 17:17:02 -04001828 mbuf = rmr_alloc_msg( mr, sizeof( pm->req ) );
E. Scott Daniels392168d2019-11-06 15:12:38 -05001829 pm = (msg_t*) mbuf->payload;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001830 // generate an xaction ID and fill in payload with data and msg type
E. Scott Daniels392168d2019-11-06 15:12:38 -05001831 rmr_bytes2xact( mbuf, xid, RMR_MAX_XID );
1832 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
1833 mbuf->mtype = MT_USR_RESP;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001834 msg = rmr_mt_call( mr, msg, my_id, 100 ); // wait up to 100ms
E. Scott Daniels392168d2019-11-06 15:12:38 -05001835 if( ! msg ) { // probably a timeout and no msg received
1836 return NULL; // let errno trickle up
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001837 }
E. Scott Daniels392168d2019-11-06 15:12:38 -05001838 if( mbuf->state != RMR_OK ) {
1839 while( retries_left-- > 0 && // loop as long as eagain
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001840 mbuf->state == RMR_ERR_RETRY &&
1841 (msg = rmr_mt_call( mr, msg )) != NULL &&
E. Scott Daniels392168d2019-11-06 15:12:38 -05001842 mbuf->state != RMR_OK ) {
1843 usleep( retry_delay );
1844 }
E. Scott Daniels392168d2019-11-06 15:12:38 -05001845 if( mbuf == NULL || mbuf->state != RMR_OK ) {
1846 rmr_free_msg( mbuf ); // safe if nil
1847 return NULL;
1848 }
1849 }
1850 // do something with mbuf
1851
1852
1853
1854SEE ALSO
1855--------------------------------------------------------------------------------------------
1856
1857rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
1858rmr_mt_rcv(3), rmr_payload_size(3), rmr_send_msg(3),
1859rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1860rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1861rmr_set_stimeout(3), rmr_tokenise(3), rmr_mk_ring(3),
1862rmr_ring_free(3)
1863
1864
1865NAME
1866--------------------------------------------------------------------------------------------
1867
1868rmr_mt_rcv
1869
1870SYNOPSIS
1871--------------------------------------------------------------------------------------------
1872
1873
1874::
1875
1876 #include <rmr/rmr.h>
1877 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
1878
1879
1880
1881DESCRIPTION
1882--------------------------------------------------------------------------------------------
1883
1884The rmr_mt_rcv function blocks until a message is received,
1885or the timeout period (milliseconds) has passed. The result
1886is an RMr message buffer which references a received message.
1887In the case of a timeout the state will be reflected in an
1888"empty buffer" (if old_msg was not nil, or simply with the
1889return of a nil pointer. If a timeout value of zero (0) is
1890given, then the function will block until the next message
1891received.
1892
1893The *vctx* pointer is the pointer returned by the rmr_init
1894function. *Old_msg* is a pointer to a previously used message
1895buffer or NULL. The ability to reuse message buffers helps to
1896avoid alloc/free cycles in the user application. When no
1897buffer is available to supply, the receive function will
1898allocate one.
1899
1900The *old_msg* parameter allows the user to pass a previously
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001901generated RMR message back to RMR for reuse. Optionally, the
E. Scott Daniels392168d2019-11-06 15:12:38 -05001902user application may pass a nil pointer if no reusable
1903message is available. When a timeout occurs, and old_msg was
1904not nil, the state will be returned by returning a pointer to
1905the old message with the state set.
1906
1907It is possible to use the *rmr_rcv_msg()* function instead of
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001908this function. Doing so might be advantageous if the user
E. Scott Daniels392168d2019-11-06 15:12:38 -05001909programme does not always start the multi-threaded mode and
1910the use of *rmr_rcv_msg()* would make the flow of the code
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001911more simple. The advantages of using this function are the
E. Scott Daniels392168d2019-11-06 15:12:38 -05001912ability to set a timeout without using epoll, and a small
1913performance gain (if multi-threaded mode is enabled, and the
1914*rmr_rcv_msg()* function is used, it simply invokes this
1915function without a timeout value, thus there is the small
1916cost of a second call that results). Similarly, the
1917*rmr_torcv_msg()* call can be used when in multi-threaded
1918mode with the same "pass through" overhead to using this
1919function directly.
1920
E. Scott Daniels392168d2019-11-06 15:12:38 -05001921RETURN VALUE
1922--------------------------------------------------------------------------------------------
1923
1924When a message is received before the timeout period expires,
1925a pointer to the RMr message buffer which describes the
1926message is returned. This will, with a high probability, be a
1927different message buffer than *old_msg;* the user application
1928should not continue to use *old_msg* after it is passed to
1929this function.
1930
1931In the event of a timeout the return value will be the old
1932msg with the state set, or a nil pointer if no old message
1933was provided.
1934
1935ERRORS
1936--------------------------------------------------------------------------------------------
1937
1938The *state* field in the message buffer will be set to one of
1939the following values:
1940
1941
1942
1943RMR_OK
1944
1945 The message was received without error.
1946
1947
1948RMR_ERR_BADARG
1949
1950 A parameter passed to the function was not valid (e.g. a
1951 nil pointer). indicate either RMR_OK or RMR_ERR_EMPTY if
1952 an empty message was received.
1953
1954
1955RMR_ERR_EMPTY
1956
1957 The message received had no associated data. The length of
1958 the message will be 0.
1959
1960
1961RMR_ERR_NOTSUPP
1962
1963 The multi-threaded option was not enabled when RMr was
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001964 initialised. See the man page for *rmr_init()* for
E. Scott Daniels392168d2019-11-06 15:12:38 -05001965 details.
1966
1967
1968RMR_ERR_RCVFAILED
1969
1970 A hard error occurred preventing the receive from
1971 completing.
1972
1973When a nil pointer is returned, or any other state value was
1974set in the message buffer, errno will be set to one of the
1975following:
1976
1977
1978
1979INVAL
1980
1981 Parameter(s) passed to the function were not valid.
1982
1983
1984EBADF
1985
1986 The underlying message transport is unable to process the
1987 request.
1988
1989
1990ENOTSUP
1991
1992 The underlying message transport is unable to process the
1993 request.
1994
1995
1996EFSM
1997
1998 The underlying message transport is unable to process the
1999 request.
2000
2001
2002EAGAIN
2003
2004 The underlying message transport is unable to process the
2005 request.
2006
2007
2008EINTR
2009
2010 The underlying message transport is unable to process the
2011 request.
2012
2013
2014ETIMEDOUT
2015
2016 The underlying message transport is unable to process the
2017 request.
2018
2019
2020ETERM
2021
2022 The underlying message transport is unable to process the
2023 request.
2024
2025
2026EXAMPLE
2027--------------------------------------------------------------------------------------------
2028
2029
2030
2031::
2032
2033 rmr_mbuf_t* mbuf = NULL; // received msg
2034 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
2035 if( msg != NULL ) {
2036 switch( msg->state ) {
2037 case RMR_OK:
2038 printf( "got a good message\\n" );
2039 break;
2040 case RMR_ERR_EMPTY:
2041 printf( "received timed out\\n" );
2042 break;
2043 default:
2044 printf( "receive error: %d\\n", mbuf->state );
2045 break;
2046 }
2047 } else {
2048 printf( "receive timeout (nil)\\n" );
2049 }
2050
2051
2052
2053SEE ALSO
2054--------------------------------------------------------------------------------------------
2055
2056rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
2057rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
2058rmr_mt_call(3), rmr_payload_size(3), rmr_send_msg(3),
2059rmr_torcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
2060rmr_ready(3), rmr_ring_free(3), rmr_torcv_msg(3)
2061
2062
2063NAME
2064--------------------------------------------------------------------------------------------
2065
2066rmr_payload_size
2067
2068SYNOPSIS
2069--------------------------------------------------------------------------------------------
2070
2071
2072::
2073
2074 #include <rmr/rmr.h>
2075 int rmr_payload_size( rmr_mbuf_t* msg );
2076
2077
2078
2079DESCRIPTION
2080--------------------------------------------------------------------------------------------
2081
2082Given a message buffer, this function returns the amount of
2083space (bytes) available for the user application to consume
2084in the message payload. This is different than the message
2085length available as a field in the message buffer.
2086
2087RETURN VALUE
2088--------------------------------------------------------------------------------------------
2089
2090The number of bytes available in the payload.
2091
2092ERRORS
2093--------------------------------------------------------------------------------------------
2094
2095
2096
2097INVAL
2098
2099 Parameter(s) passed to the function were not valid.
2100
2101
2102SEE ALSO
2103--------------------------------------------------------------------------------------------
2104
2105rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2106rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2107rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
2108rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
2109
2110
2111NAME
2112--------------------------------------------------------------------------------------------
2113
2114rmr_rcv_msg
2115
2116SYNOPSIS
2117--------------------------------------------------------------------------------------------
2118
2119
2120::
2121
2122 #include <rmr/rmr.h>
2123 rmr_mbuf_t* rmr_rcv_msg( void* vctx, rmr_mbuf_t* old_msg );
2124
2125
2126
2127DESCRIPTION
2128--------------------------------------------------------------------------------------------
2129
2130The rmr_rcv_msg function blocks until a message is received,
2131returning the message to the caller via a pointer to a
2132rmr_mbuf_t structure type. If messages were queued while
2133waiting for the response to a previous invocation of
2134rmr_call, the oldest message is removed from the queue and
2135returned without delay.
2136
2137The *vctx* pointer is the pointer returned by the rmr_init
2138function. *Old_msg* is a pointer to a previously used message
2139buffer or NULL. The ability to reuse message buffers helps to
2140avoid alloc/free cycles in the user application. When no
2141buffer is available to supply, the receive function will
2142allocate one.
2143
2144RETURN VALUE
2145--------------------------------------------------------------------------------------------
2146
2147The function returns a pointer to the rmr_mbuf_t structure
2148which references the message information (state, length,
E. Scott Daniels117030c2020-04-10 17:17:02 -04002149payload), or a nil pointer in the case of an extreme error.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002150
2151ERRORS
2152--------------------------------------------------------------------------------------------
2153
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002154The *state* field in the message buffer will indicate RMR_OK
2155when the message receive process was successful and the
2156message can be used by the caller. Depending on the
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002157underlying transport mechanism, one of the following RMR
2158error stats may be returned:
2159
2160
2161
2162RMR_ERR_EMPTY
2163
2164 The message received had no payload, or was completely
2165 empty.
2166
2167
2168RMR_ERR_TIMEOUT
2169
2170 For some transport mechanisms, or if reading the receive
2171 queue from multiple threads, it is possible for one thread
2172 to find no data waiting when it queries the queue. When
2173 this state is reported, the message buffer does not
2174 contain message data and the user application should
2175 reinvoke the receive function.
2176
2177
2178When an RMR error state is reported, the underlying errno
2179value might provide more information. The following is a list
2180of possible values that might accompany the states listed
2181above:
2182
2183RMR_ERR_EMPTY if an empty message was received. If a nil
2184pointer is returned, or any other state value was set in the
2185message buffer, errno will be set to one of the following:
E. Scott Daniels392168d2019-11-06 15:12:38 -05002186
2187
2188
2189INVAL
2190
2191 Parameter(s) passed to the function were not valid.
2192
2193
2194EBADF
2195
2196 The underlying message transport is unable to process the
2197 request.
2198
2199
2200ENOTSUP
2201
2202 The underlying message transport is unable to process the
2203 request.
2204
2205
2206EFSM
2207
2208 The underlying message transport is unable to process the
2209 request.
2210
2211
2212EAGAIN
2213
2214 The underlying message transport is unable to process the
2215 request.
2216
2217
2218EINTR
2219
2220 The underlying message transport is unable to process the
2221 request.
2222
2223
2224ETIMEDOUT
2225
2226 The underlying message transport is unable to process the
2227 request.
2228
2229
2230ETERM
2231
2232 The underlying message transport is unable to process the
2233 request.
2234
2235
2236EXAMPLE
2237--------------------------------------------------------------------------------------------
2238
2239
2240SEE ALSO
2241--------------------------------------------------------------------------------------------
2242
2243rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
2244rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
2245rmr_payload_size(3), rmr_send_msg(3), rmr_torcv_msg(3),
2246rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2247rmr_ring_free(3), rmr_torcv_msg(3)
2248
2249
2250NAME
2251--------------------------------------------------------------------------------------------
2252
2253rmr_ready
2254
2255SYNOPSIS
2256--------------------------------------------------------------------------------------------
2257
2258
2259::
2260
2261 #include <rmr/rmr.h>
2262 int rmr_ready( void* vctx );
2263
2264
2265
2266DESCRIPTION
2267--------------------------------------------------------------------------------------------
2268
2269The rmr_ready function checks to see if a routing table has
2270been successfully received and installed. The return value
2271indicates the state of readiness.
2272
2273RETURN VALUE
2274--------------------------------------------------------------------------------------------
2275
2276A return value of 1 (true) indicates that the routing table
2277is in place and attempts to send messages can be made. When 0
2278is returned (false) the routing table has not been received
2279and thus attempts to send messages will fail with *no
2280endpoint* errors.
2281
2282SEE ALSO
2283--------------------------------------------------------------------------------------------
2284
2285rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2286rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2287rmr_rcv_specific(3), rmr_rts_msg(3), rmr_fib(3),
2288rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
2289rmr_ring_free(3)
2290
2291
2292NAME
2293--------------------------------------------------------------------------------------------
2294
2295rmr_realloc_payload
2296
2297SYNOPSIS
2298--------------------------------------------------------------------------------------------
2299
2300
2301::
2302
2303 #include <rmr/rmr.h>
2304 extern rmr_mbuf_t* rmr_realloc_payload( rmr_mbuf_t* msg, int new_len, int copy, int clone );
2305
2306
2307
2308DESCRIPTION
2309--------------------------------------------------------------------------------------------
2310
2311The rmr_realloc_payload function will return a pointer to an
2312RMR message buffer struct (rmr_mbuf_t) which has a payload
2313large enough to accomodate *new_len* bytes. If necessary, the
2314underlying payload is reallocated, and the bytes from the
2315original payload are copied if the *copy* parameter is true
2316(1). If the message passed in has a payload large enough,
2317there is no additional memory allocation and copying.
2318
2319Cloning The Message Buffer
E. Scott Daniels117030c2020-04-10 17:17:02 -04002320~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002321
2322This function can also be used to generate a separate copy of
2323the original message, with the desired payload size, without
2324destroying the original message buffer or the original
2325payload. A standalone copy is made only when the *clone*
2326parameter is true (1). When cloning, the payload is copied to
2327the cloned message **only** if the *copy* parameter is true.
2328
2329Message Buffer Metadata
E. Scott Daniels117030c2020-04-10 17:17:02 -04002330~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002331
2332The metadata in the original message buffer (message type,
2333subscription ID, and payload length) will be preserved if the
2334*copy* parameter is true. When this parameter is not true
2335(0), then these values are set to the uninitialised value
2336(-1) for type and ID, and the length is set to 0.
2337
2338RETURN VALUE
2339--------------------------------------------------------------------------------------------
2340
2341The rmr_realloc_payload function returns a pointer to the
2342message buffer with the payload which is large enough to hold
2343*new_len* bytes. If the *clone* option is true, this will be
2344a pointer to the newly cloned message buffer; the original
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002345message buffer pointer may still be used to reference that
E. Scott Daniels392168d2019-11-06 15:12:38 -05002346message. It is the calling application's responsibility to
2347free the memory associateed with both messages using the
2348rmr_free_msg() function.
2349
2350When the *clone* option is not used, it is still good
2351practice by the calling application to capture and use this
2352reference as it is possible that the message buffer, and not
2353just the payload buffer, was reallocated. In the event of an
2354error, a nil pointer will be returned and the value of
2355*errno* will be set to reflect the problem.
2356
2357ERRORS
2358--------------------------------------------------------------------------------------------
2359
2360These value of *errno* will reflect the error condition if a
2361nil pointer is returned:
2362
2363
2364
2365ENOMEM
2366
2367 Memory allocation of the new payload failed.
2368
2369
2370EINVAL
2371
2372 The pointer passed in was nil, or refrenced an invalid
2373 message, or the required length was not valid.
2374
2375
2376EXAMPLE
2377--------------------------------------------------------------------------------------------
2378
2379The following code bit illustrates how this function can be
2380used to reallocate a buffer for a return to sender
2381acknowledgement message which is larger than the message
2382received.
2383
2384
2385::
2386
2387 if( rmr_payload_size( msg ) < ack_sz ) { // received message too small for ack
2388 msg = rmr_realloc_payload( msg, ack_sz, 0, 0 ); // reallocate the message with a payload big enough
2389 if( msg == NULL ) {
2390 fprintf( stderr, "[ERR] realloc returned a nil pointer: %s\\n", strerror( errno ) );
2391 } else {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002392 // populate and send ack message
2393 }
E. Scott Daniels392168d2019-11-06 15:12:38 -05002394 }
2395
2396
2397
2398SEE ALSO
2399--------------------------------------------------------------------------------------------
2400
2401rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
2402rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2403rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2404rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
2405rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
2406
2407
2408NAME
2409--------------------------------------------------------------------------------------------
2410
2411rmr_rts_msg
2412
2413SYNOPSIS
2414--------------------------------------------------------------------------------------------
2415
2416
2417::
2418
2419 #include <rmr/rmr.h>
2420 rmr_mbuf_t* rmr_rts_msg( void* vctx, rmr_mbuf_t* msg );
2421
2422
2423
2424DESCRIPTION
2425--------------------------------------------------------------------------------------------
2426
2427The rmr_rts_msg function sends a message returning it to the
2428endpoint which sent the message rather than selecting an
2429endpoint based on the message type and routing table. Other
2430than this small difference, the behaviour is exactly the same
2431as rmr_send_msg.
2432
2433Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04002434~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002435
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002436The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05002437until one of three conditions occurs:
2438
2439
2440
24411.
2442
2443 The message is sent without error
2444
2445
24462.
2447
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002448 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002449
2450
24513.
2452
2453 The maximum number of retry loops has been attempted
2454
2455
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002456A retry loop consists of approximately 1000 send attempts
2457**without** any intervening calls to *sleep()* or *usleep().*
2458The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050024591000 send attempts is performed before returning to the user
2460application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002461initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05002462allowing the user application to completely disable retires
2463(set to 0), or to increase the number of retry loops.
2464
2465Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -04002466~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002467
2468The underlying transport mechanism used to send messages is
2469configured in *non-blocking* mode. This means that if a
2470message cannot be sent immediately the transport mechanism
2471will **not** pause with the assumption that the inability to
2472send will clear quickly (within a few milliseconds). This
2473means that when the retry loop is completely disabled (set to
24740), that the failure to accept a message for sending by the
2475underlying mechanisms (software or hardware) will be reported
2476immediately to the user application.
2477
2478It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002479mechanism being used, it is extremely likely that retry
2480conditions will happen during normal operations. These are
2481completely out of RMR's control, and there is nothing that
2482RMR can do to avoid or mitigate these other than by allowing
2483RMR to retry the send operation, and even then it is possible
2484(e.g., during connection reattempts), that a single retry
2485loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002486
2487PAYLOAD SIZE
2488--------------------------------------------------------------------------------------------
2489
2490When crafting a response based on a received message, the
2491user application must take care not to write more bytes to
2492the message payload than the allocated message has. In the
2493case of a received message, it is possible that the response
2494needs to be larger than the payload associated with the
2495inbound message. In order to use the return to sender
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002496function, the source information in the original message must
E. Scott Daniels392168d2019-11-06 15:12:38 -05002497be present in the response; information which cannot be added
2498to a message buffer allocated through the standard RMR
2499allocation function. To allocate a buffer with a larger
2500payload, and which retains the necessary sender data needed
2501by this function, the *rmr_realloc_payload()* function must
2502be used to extend the payload to a size suitable for the
2503response.
2504
2505RETURN VALUE
2506--------------------------------------------------------------------------------------------
2507
2508On success, a new message buffer, with an empty payload, is
2509returned for the application to use for the next send. The
2510state in this buffer will reflect the overall send operation
2511state and should be RMR_OK.
2512
2513If the state in the returned buffer is anything other than
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002514RMR_OK, the user application may need to attempt a
E. Scott Daniels392168d2019-11-06 15:12:38 -05002515retransmission of the message, or take other action depending
2516on the setting of errno as described below.
2517
E. Scott Daniels117030c2020-04-10 17:17:02 -04002518In the event of extreme failure, a nil pointer is returned.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002519In this case the value of errno might be of some use, for
2520documentation, but there will be little that the user
2521application can do other than to move on.
2522
2523ERRORS
2524--------------------------------------------------------------------------------------------
2525
2526The following values may be passed back in the *state* field
2527of the returned message buffer.
2528
2529
2530
2531RMR_ERR_BADARG
2532
2533 The message buffer pointer did not refer to a valid
2534 message.
2535
2536RMR_ERR_NOHDR
2537
2538 The header in the message buffer was not valid or
2539 corrupted.
2540
2541RMR_ERR_NOENDPT
2542
2543 The message type in the message buffer did not map to a
2544 known endpoint.
2545
2546RMR_ERR_SENDFAILED
2547
2548 The send failed; errno has the possible reason.
2549
2550
2551The following values may be assigned to errno on failure.
2552
2553
2554INVAL
2555
2556 Parameter(s) passed to the function were not valid, or the
2557 underlying message processing environment was unable to
2558 interpret the message.
2559
2560
2561ENOKEY
2562
2563 The header information in the message buffer was invalid.
2564
2565
2566ENXIO
2567
2568 No known endpoint for the message could be found.
2569
2570
2571EMSGSIZE
2572
2573 The underlying transport refused to accept the message
2574 because of a size value issue (message was not attempted
2575 to be sent).
2576
2577
2578EFAULT
2579
2580 The message referenced by the message buffer is corrupt
E. Scott Daniels117030c2020-04-10 17:17:02 -04002581 (nil pointer or bad internal length).
E. Scott Daniels392168d2019-11-06 15:12:38 -05002582
2583
2584EBADF
2585
2586 Internal RMR error; information provided to the message
2587 transport environment was not valid.
2588
2589
2590ENOTSUP
2591
2592 Sending was not supported by the underlying message
2593 transport.
2594
2595
2596EFSM
2597
2598 The device is not in a state that can accept the message.
2599
2600
2601EAGAIN
2602
2603 The device is not able to accept a message for sending.
2604 The user application should attempt to resend.
2605
2606
2607EINTR
2608
2609 The operation was interrupted by delivery of a signal
2610 before the message was sent.
2611
2612
2613ETIMEDOUT
2614
2615 The underlying message environment timed out during the
2616 send process.
2617
2618
2619ETERM
2620
2621 The underlying message environment is in a shutdown state.
2622
2623
2624EXAMPLE
2625--------------------------------------------------------------------------------------------
2626
2627
2628SEE ALSO
2629--------------------------------------------------------------------------------------------
2630
2631rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2632rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2633rmr_rcv_specific(3), rmr_ready(3), rmr_fib(3),
2634rmr_has_str(3), rmr_set_stimeout(3), rmr_tokenise(3),
2635rmr_mk_ring(3), rmr_ring_free(3)
2636
2637
2638NAME
2639--------------------------------------------------------------------------------------------
2640
2641rmr_send_msg
2642
2643SYNOPSIS
2644--------------------------------------------------------------------------------------------
2645
2646
2647::
2648
2649 #include <rmr/rmr.h>
2650 rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
2651
2652
2653
2654DESCRIPTION
2655--------------------------------------------------------------------------------------------
2656
2657The rmr_send_msg function accepts a message buffer from the
2658user application and attempts to send it. The destination of
2659the message is selected based on the message type specified
2660in the message buffer, and the matching information in the
2661routing tables which are currently in use by the RMR library.
2662This may actually result in the sending of the message to
2663multiple destinations which could degrade expected overall
2664performance of the user application. (Limiting excessive
2665sending of messages is the responsibility of the
2666application(s) responsible for building the routing table
2667used by the RMR library, and not the responsibility of the
2668library.)
2669
2670Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04002671~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002672
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002673The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05002674until one of three conditions occurs:
2675
2676
2677
26781.
2679
2680 The message is sent without error
2681
2682
26832.
2684
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002685 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002686
2687
26883.
2689
2690 The maximum number of retry loops has been attempted
2691
2692
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002693A retry loop consists of approximately 1000 send attempts
2694**without** any intervening calls to *sleep()* or *usleep().*
2695The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050026961000 send attempts is performed before returning to the user
2697application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002698initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05002699allowing the user application to completely disable retires
2700(set to 0), or to increase the number of retry loops.
2701
2702Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -04002703~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002704
2705The underlying transport mechanism used to send messages is
2706configured in *non-blocking* mode. This means that if a
2707message cannot be sent immediately the transport mechanism
2708will **not** pause with the assumption that the inability to
2709send will clear quickly (within a few milliseconds). This
2710means that when the retry loop is completely disabled (set to
27110), that the failure to accept a message for sending by the
2712underlying mechanisms (software or hardware) will be reported
2713immediately to the user application.
2714
2715It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002716mechanism being used, it is extremely likely that retry
2717conditions will happen during normal operations. These are
2718completely out of RMR's control, and there is nothing that
2719RMR can do to avoid or mitigate these other than by allowing
2720RMR to retry the send operation, and even then it is possible
2721(e.g., during connection reattempts), that a single retry
2722loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002723
2724RETURN VALUE
2725--------------------------------------------------------------------------------------------
2726
2727On success, a new message buffer, with an empty payload, is
2728returned for the application to use for the next send. The
2729state in this buffer will reflect the overall send operation
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002730state and will be RMR_OK when the send was successful.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002731
2732When the message cannot be successfully sent this function
2733will return the unsent (original) message buffer with the
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002734state set to indicate the reason for failure. The value of
2735*errno* may also be set to reflect a more detailed failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002736reason if it is known.
2737
E. Scott Daniels117030c2020-04-10 17:17:02 -04002738In the event of extreme failure, a nil pointer is returned.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002739In this case the value of errno might be of some use, for
2740documentation, but there will be little that the user
2741application can do other than to move on.
2742
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002743**CAUTION:** In some cases it is extremely likely that the
2744message returned by the send function does **not** reference
2745the same memory structure. Thus is important for the user
2746programme to capture the new pointer for future use or to be
2747passed to rmr_free(). If you are experiencing either double
2748free errors or segment faults in either rmr_free() or
2749rmr_send_msg(), ensure that the return value from this
2750function is being captured and used.
2751
E. Scott Daniels392168d2019-11-06 15:12:38 -05002752ERRORS
2753--------------------------------------------------------------------------------------------
2754
2755The following values may be passed back in the *state* field
2756of the returned message buffer.
2757
2758
2759
2760RMR_RETRY
2761
2762 The message could not be sent, but the underlying
2763 transport mechanism indicates that the failure is
2764 temporary. If the send operation is tried again it might
2765 be successful.
2766
2767RMR_SEND_FAILED
2768
2769 The send operation was not successful and the underlying
2770 transport mechanism indicates a permanent (hard) failure;
2771 retrying the send is not possible.
2772
2773RMR_ERR_BADARG
2774
2775 The message buffer pointer did not refer to a valid
2776 message.
2777
2778RMR_ERR_NOHDR
2779
2780 The header in the message buffer was not valid or
2781 corrupted.
2782
2783RMR_ERR_NOENDPT
2784
2785 The message type in the message buffer did not map to a
2786 known endpoint.
2787
2788
2789The following values may be assigned to errno on failure.
2790
2791
2792INVAL
2793
2794 Parameter(s) passed to the function were not valid, or the
2795 underlying message processing environment was unable to
2796 interpret the message.
2797
2798
2799ENOKEY
2800
2801 The header information in the message buffer was invalid.
2802
2803
2804ENXIO
2805
2806 No known endpoint for the message could be found.
2807
2808
2809EMSGSIZE
2810
2811 The underlying transport refused to accept the message
2812 because of a size value issue (message was not attempted
2813 to be sent).
2814
2815
2816EFAULT
2817
2818 The message referenced by the message buffer is corrupt
E. Scott Daniels117030c2020-04-10 17:17:02 -04002819 (nil pointer or bad internal length).
E. Scott Daniels392168d2019-11-06 15:12:38 -05002820
2821
2822EBADF
2823
2824 Internal RMR error; information provided to the message
2825 transport environment was not valid.
2826
2827
2828ENOTSUP
2829
2830 Sending was not supported by the underlying message
2831 transport.
2832
2833
2834EFSM
2835
2836 The device is not in a state that can accept the message.
2837
2838
2839EAGAIN
2840
2841 The device is not able to accept a message for sending.
2842 The user application should attempt to resend.
2843
2844
2845EINTR
2846
2847 The operation was interrupted by delivery of a signal
2848 before the message was sent.
2849
2850
2851ETIMEDOUT
2852
2853 The underlying message environment timed out during the
2854 send process.
2855
2856
2857ETERM
2858
2859 The underlying message environment is in a shutdown state.
2860
2861
2862EXAMPLE
2863--------------------------------------------------------------------------------------------
2864
2865The following is a simple example of how the rmr_send_msg
2866function is called. In this example, the send message buffer
2867is saved between calls and reused eliminating alloc/free
2868cycles.
2869
2870
2871::
2872
2873 static rmr_mbuf_t* send_msg = NULL; // message to send; reused on each call
2874 msg_t* send_pm; // payload for send
2875 msg_t* pm; // our message format in the received payload
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002876 if( send_msg == NULL ) {
2877 send_msg = rmr_alloc_msg( mr, MAX_SIZE ); // new buffer to send
2878 }
2879 // reference payload and fill in message type
E. Scott Daniels392168d2019-11-06 15:12:38 -05002880 pm = (msg_t*) send_msg->payload;
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002881 send_msg->mtype = MT_ANSWER;
2882 msg->len = generate_data( pm ); // something that fills the payload in
2883 msg = rmr_send_msg( mr, send_msg ); // ensure new pointer used after send
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002884 if( ! msg ) {
2885 return ERROR;
2886 } else {
2887 if( msg->state != RMR_OK ) {
2888 // check for RMR_ERR_RETRY, and resend if needed
2889 // else return error
2890 }
2891 }
2892 return OK;
E. Scott Daniels392168d2019-11-06 15:12:38 -05002893
2894
2895
2896SEE ALSO
2897--------------------------------------------------------------------------------------------
2898
2899rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2900rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2901rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
2902rmr_ring_free(3), rmr_torcv_rcv(3), rmr_wh_send_msg(3)
2903
2904
2905NAME
2906--------------------------------------------------------------------------------------------
2907
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002908rmr_set_fack
2909
2910SYNOPSIS
2911--------------------------------------------------------------------------------------------
2912
2913
2914::
2915
2916 #include <rmr/rmr.h>
2917 void rmr_set_fack( void* vctx );
2918
2919
2920
2921DESCRIPTION
2922--------------------------------------------------------------------------------------------
2923
2924The rmr_set_fack function enables *fast TCP acknowledgements*
2925if the underlying transport library supports it. This might
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002926be useful for applications which must send messages at a
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002927maximum rate.
2928
2929RETURN VALUE
2930--------------------------------------------------------------------------------------------
2931
2932There is no return value.
2933
2934ERRORS
2935--------------------------------------------------------------------------------------------
2936
2937This function does not generate any errors.
2938
2939SEE ALSO
2940--------------------------------------------------------------------------------------------
2941
2942rmr_init(3),
2943
2944
2945NAME
2946--------------------------------------------------------------------------------------------
2947
E. Scott Daniels392168d2019-11-06 15:12:38 -05002948rmr_set_stimeout
2949
2950SYNOPSIS
2951--------------------------------------------------------------------------------------------
2952
2953
2954::
2955
2956 #include <rmr/rmr.h>
2957 rmr_mbuf_t* rmr_set_stimeout( void* vctx, int rloops );
2958
2959
2960
2961DESCRIPTION
2962--------------------------------------------------------------------------------------------
2963
2964The rmr_set_stimeout function sets the configuration for how
2965RMr will retry message send operations which complete with
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002966either a *timeout* or *again* completion value. (Send
E. Scott Daniels392168d2019-11-06 15:12:38 -05002967operations include all of the possible message send
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002968functions: *rmr_send_msg(), rmr_call(), rmr_rts_msg()* and
2969*rmr_wh_send_msg().* The *rloops* parameter sets the maximum
2970number of retry loops that will be attempted before giving up
2971and returning the unsuccessful state to the user application.
2972Each retry loop is approximately 1000 attempts, and RMr does
2973**not** invoke any sleep function between retries in the
2974loop; a small, 1 mu-sec, sleep is executed between loop sets
2975if the *rloops* value is greater than 1.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002976
2977
2978Disabling Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04002979~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05002980
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002981By default, the send operations will execute with an *rloop*
2982setting of 1; each send operation will attempt to resend the
2983message approximately 1000 times before giving up. If the
E. Scott Daniels392168d2019-11-06 15:12:38 -05002984user application does not want to have send operations retry
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002985when the underlying transport mechanism indicates *timeout*
2986or *again,* the application should invoke this function and
2987pass a value of 0 (zero) for *rloops.* With this setting, all
2988RMr send operations will attempt a send operation only
2989**once,** returning immediately to the caller with the state
E. Scott Daniels392168d2019-11-06 15:12:38 -05002990of that single attempt.
2991
2992RETURN VALUE
2993--------------------------------------------------------------------------------------------
2994
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002995This function returns a -1 to indicate that the *rloops*
2996value could not be set, and the value *RMR_OK* to indicate
E. Scott Daniels392168d2019-11-06 15:12:38 -05002997success.
2998
2999ERRORS
3000--------------------------------------------------------------------------------------------
3001
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05003002Currently errno is **not** set by this function; the only
3003cause of a failure is an invalid context (*vctx*) pointer.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003004
3005EXAMPLE
3006--------------------------------------------------------------------------------------------
3007
3008The following is a simple example of how the rmr_set_stimeout
3009function is called.
3010
3011
3012::
3013
3014 #define NO_FLAGS 0
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003015 char* port = "43086"; // port for message router listen
3016 int max_size = 4096; // max message size for default allocations
3017 void* mr_context; // message router context
E. Scott Daniels392168d2019-11-06 15:12:38 -05003018 mr_context = rmr_init( port, max_size, NO_FLAGS );
3019 if( mr_context != NULL ) {
3020 rmr_set_stimeout( mr_context, 0 ); // turn off retries
3021 }
3022
3023
3024
3025SEE ALSO
3026--------------------------------------------------------------------------------------------
3027
3028rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3029rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3030rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
3031rmr_ring_free(3), rmr_send_msg(3), rmr_torcv_rcv(3),
3032rmr_wh_send_msg(3)
3033
3034
3035NAME
3036--------------------------------------------------------------------------------------------
3037
3038rmr_set_trace
3039
3040SYNOPSIS
3041--------------------------------------------------------------------------------------------
3042
3043
3044::
3045
3046 #include <rmr/rmr.h>
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003047 int rmr_set_trace( rmr_mbuf_t* mbuf, unsigned char* data, int len )
E. Scott Daniels392168d2019-11-06 15:12:38 -05003048
3049
3050
3051DESCRIPTION
3052--------------------------------------------------------------------------------------------
3053
3054The rmr_set_trace function will copy len bytes from data into
3055the trace portion of mbuf. If the trace area of mbuf is not
3056the correct size, the message buffer will be reallocated to
3057ensure that enough space is available for the trace data.
3058
3059RETURN VALUE
3060--------------------------------------------------------------------------------------------
3061
3062The rmr_set_trace function returns the number of bytes
3063successfully copied to the message. If 0 is returned either
3064the message pointer was nil, or the size in the parameters
3065was <= 0.
3066
3067SEE ALSO
3068--------------------------------------------------------------------------------------------
3069
3070rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
3071rmr_bytes2payload(3), rmr_call(3), rmr_free_msg(3),
3072rmr_get_rcvfd(3), rmr_get_meid(3), rmr_get_trace(3),
3073rmr_get_trlen(3), rmr_init(3), rmr_init_trace(3),
3074rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
3075rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
3076rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
3077rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
3078rmr_wh_open(3), rmr_wh_send_msg(3)
3079
3080
3081NAME
3082--------------------------------------------------------------------------------------------
3083
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003084rmr_set_vlevel
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003085
3086SYNOPSIS
3087--------------------------------------------------------------------------------------------
3088
3089
3090::
3091
3092 #include <rmr/rmr.h>
3093 #include <rmr/rmr_logging.h>
3094 void rmr_set_vlevel( int new_level )
3095
3096
3097
3098DESCRIPTION
3099--------------------------------------------------------------------------------------------
3100
3101The rmr_set_vlevel allows the user programme to set the
3102verbosity level which is used to determine the messages RMR
3103writes to standard error. The new_vlevel value must be one of
3104the following constants which have the indicated meanings:
3105
3106
3107RMR_VL_OFF
3108
3109 Turns off all message writing. This includes the stats and
3110 debugging messages generated by the route collector thread
3111 which are normally affected only by the externally managed
3112 verbose level file (and related environment variable).
3113
3114
3115RMR_VL_CRIT
3116
3117 Write only messages of critical importance. From the point
3118 of view of RMR, when a critical proper behaviour of the
3119 library cannot be expected or guaranteed.
3120
3121RMR_VL_ERR
3122
3123 Include error messages in the output. An error is an event
3124 from which RMR has no means to recover. Continued proper
3125 execution is likely except where the affected connection
3126 and/or component mentioned in the error is concerned.
3127
3128RMR_VL_WARN
3129
3130 Include warning messages in the output. A warning
3131 indicates an event which is not considered to be normal,
3132 but is expected and continued acceptable behaviour of the
3133 system is assured.
3134
3135RMR_VL_INFO
3136
3137 Include informational messagees in the output.
3138 Informational messages include some diagnostic information
3139 which explain the activities of RMR.
3140
3141RMR_VL_DEBUG
3142
3143 Include all debugging messages in the output. Debugging
3144 must have also been enabled during the build as a
3145 precaution to accidentally enabling this level of output
3146 as it can grossly affect performance.
3147
3148
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003149Generally RMR does not write messages to the standard error
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003150device from *critical path* functions, therefore it is
3151usually not harmful to enable a verbosity level of either
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003152RMR_VL_CRIT or RMR_VL_ERR.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003153
3154Messages written from the route table collection thread are
3155still governed by the value placed into the verbose level
3156control file (see the man page for rmr_init()); those
3157messages are affected only when logging is completely
3158disabled by passing RMR_VL_OFF to this function.
3159
3160The verbosity level can also be set via an environment
3161variable prior to the start of the RMR based application. The
3162environment variable is read only during initialisation; if
3163the programme must change the value during execution, this
3164function must be used. The default value, if this function is
3165never called, and the environment variable is not present, is
3166RMR_VL_ERR.
3167
3168SEE ALSO
3169--------------------------------------------------------------------------------------------
3170
3171rmr_init(3)
3172
3173
3174NAME
3175--------------------------------------------------------------------------------------------
3176
E. Scott Daniels392168d2019-11-06 15:12:38 -05003177rmr_str2meid
3178
3179SYNOPSIS
3180--------------------------------------------------------------------------------------------
3181
3182
3183::
3184
3185 #include <rmr/rmr.h>
3186 int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
3187
3188
3189
3190DESCRIPTION
3191--------------------------------------------------------------------------------------------
3192
3193The rmr_str2meid function will copy the string pointed to by
E. Scott Daniels190665f2019-12-09 09:05:22 -05003194src to the managed entity ID (meid) field in the given
E. Scott Daniels392168d2019-11-06 15:12:38 -05003195message. The field is a fixed length, gated by the constant
3196RMR_MAX_MEID and if string length is larger than this value,
3197then **nothing** will be copied. (Note, this differs slightly
3198from the behaviour of the lrmr_bytes2meid() function.)
3199
3200RETURN VALUE
3201--------------------------------------------------------------------------------------------
3202
3203On success, the value RMR_OK is returned. If the string
3204cannot be copied to the message, the return value will be one
3205of the errors listed below.
3206
3207ERRORS
3208--------------------------------------------------------------------------------------------
3209
3210If the return value is not RMR_OK, then it will be set to one
3211of the values below.
3212
3213
3214
3215RMR_ERR_BADARG
3216
3217 The message, or an internal portion of the message, was
3218 corrupted or the pointer was invalid.
3219
3220
3221RMR_ERR_OVERFLOW
3222
3223 The length passed in was larger than the maximum length of
3224 the field; only a portion of the source bytes were copied.
3225
3226
3227EXAMPLE
3228--------------------------------------------------------------------------------------------
3229
3230
3231SEE ALSO
3232--------------------------------------------------------------------------------------------
3233
3234rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3235rmr_get_meid(3), rmr_get_rcvfd(3), rmr_payload_size(3),
3236rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3237rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3238rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3239rmr_bytes2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
3240
3241
3242NAME
3243--------------------------------------------------------------------------------------------
3244
3245rmr_str2xact
3246
3247SYNOPSIS
3248--------------------------------------------------------------------------------------------
3249
3250
3251::
3252
3253 #include <rmr/rmr.h>
3254 int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
3255
3256
3257
3258DESCRIPTION
3259--------------------------------------------------------------------------------------------
3260
3261The rmr_str2xact function will copy the string pointed to by
3262src to the transaction ID (xaction) field in the given
3263message. The field is a fixed length, gated by the constant
3264RMR_MAX_XID and if string length is larger than this value,
3265then **nothing** will be copied. (Note, this differs slightly
3266from the behaviour of the lrmr_bytes2xact() function.)
3267
3268
3269RETURN VALUE
3270--------------------------------------------------------------------------------------------
3271
3272On success, the value RMR_OK is returned. If the string
3273cannot be copied to the message, the return value will be
3274one of the errors listed below.
3275
3276ERRORS
3277--------------------------------------------------------------------------------------------
3278
3279If the return value is not RMR_OK, then it will be set to
3280one of the values below.
3281
3282
3283RMR_ERR_BADARG
3284
3285 The message, or an internal portion of the message, was
3286 corrupted or the pointer was invalid.
3287
3288
3289RMR_ERR_OVERFLOW
3290
3291 The length passed in was larger than the maximum length of
3292 the field; only a portion of the source bytes were copied.
3293
3294
3295EXAMPLE
3296--------------------------------------------------------------------------------------------
3297
3298
3299SEE ALSO
3300--------------------------------------------------------------------------------------------
3301
3302rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_bytes2xact(3),
3303rmr_call(3), rmr_free_msg(3), rmr_get_meid(3),
3304rmr_get_rcvfd(3), rmr_get_xact(3), rmr_payload_size(3),
3305rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3306rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3307rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3308rmr_str2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
3309
3310
3311NAME
3312--------------------------------------------------------------------------------------------
3313
3314RMR support functions
3315
3316SYNOPSIS
3317--------------------------------------------------------------------------------------------
3318
3319
3320::
3321
3322 #include <rmr/rmr.h>
3323 #include <rmr/ring_inline.h>
3324 char* rmr_fib( char* fname );
3325 int rmr_has_str( char const* buf, char const* str, char sep, int max );
3326 int rmr_tokenise( char* buf, char** tokens, int max, char sep );
3327 void* rmr_mk_ring( int size );
3328 void rmr_ring_free( void* vr );
3329 static inline void* rmr_ring_extract( void* vr )
3330 static inline int rmr_ring_insert( void* vr, void* new_data )
3331
3332
3333
3334DESCRIPTION
3335--------------------------------------------------------------------------------------------
3336
3337These functions support the RMR library, and are made
3338available to user applications as some (e.g. route table
3339generators) might need and/or want to make use of them. The
3340rmr_fib function accepts a file name and reads the entire
3341file into a single buffer. The intent is to provide an easy
3342way to load a static route table without a lot of buffered
3343I/O hoops.
3344
3345The rmr_has_str function accepts a *buffer* containing a set
3346of delimited tokens (e.g. foo,bar,goo) and returns true if
3347the target string, *str,* matches one of the tokens. The
3348*sep* parameter provides the separation character in the
3349buffer (e.g a comma) and *max* indicates the maximum number
3350of tokens to split the buffer into before checking.
3351
3352The rmr_tokenise function is a simple tokeniser which splits
3353*buf* into tokens at each occurrence of *sep*. Multiple
3354occurrences of the separator character (e.g. a,,b) result in
3355a nil token. Pointers to the tokens are placed into the
3356*tokens* array provided by the caller which is assumed to
3357have at least enough space for *max* entries.
3358
3359The rmr_mk_ring function creates a buffer ring with *size*
3360entries.
3361
3362The rmr_ring_free function accepts a pointer to a ring
3363context and frees the associated memory.
3364
3365The rmr_ring_insert and rmr_ring_extract functions are
3366provided as static inline functions via the
3367*rmr/ring_inline.h* header file. These functions both accept
3368the ring *context* returned by mk_ring, and either insert a
3369pointer at the next available slot (tail) or extract the data
3370at the head.
3371
3372RETURN VALUES
3373--------------------------------------------------------------------------------------------
3374
3375The following are the return values for each of these
3376functions.
3377
3378The rmr_fib function returns a pointer to the buffer
3379containing the contents of the file. The buffer is terminated
3380with a single nil character (0) making it a legitimate C
3381string. If the file was empty or nonexistent, a buffer with
3382an immediate nil character. If it is important to the calling
3383programme to know if the file was empty or did not exist, the
3384caller should use the system stat function call to make that
3385determination.
3386
3387The rmr_has_str function returns 1 if *buf* contains the
3388token referenced by &ita and false (0) if it does not. On
3389error, a -1 value is returned and errno is set accordingly.
3390
3391The rmr_tokenise function returns the actual number of token
3392pointers placed into *tokens*
3393
3394The rmr_mk_ring function returns a void pointer which is the
3395*context* for the ring.
3396
3397The rmr_ring_insert function returns 1 if the data was
3398successfully inserted into the ring, and 0 if the ring is
3399full and the pointer could not be deposited.
3400
3401The rmr_ring_extract will return the data which is at the
3402head of the ring, or NULL if the ring is empty.
3403
3404ERRORS
3405--------------------------------------------------------------------------------------------
3406
3407Not many of these functions set the value in errno, however
3408the value may be one of the following:
3409
3410
3411INVAL
3412
3413 Parameter(s) passed to the function were not valid.
3414
3415
3416EXAMPLE
3417--------------------------------------------------------------------------------------------
3418
3419
3420SEE ALSO
3421--------------------------------------------------------------------------------------------
3422
3423rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3424rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
3425rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
3426
3427
3428NAME
3429--------------------------------------------------------------------------------------------
3430
3431rmr_torcv_msg
3432
3433SYNOPSIS
3434--------------------------------------------------------------------------------------------
3435
3436
3437::
3438
3439 #include <rmr/rmr.h>
3440 rmr_mbuf_t* rmr_torcv_msg( void* vctx, rmr_mbuf_t* old_msg, int ms_to );
3441
3442
3443
3444DESCRIPTION
3445--------------------------------------------------------------------------------------------
3446
3447The rmr_torcv_msg function will pause for *ms_to*
3448milliseconds waiting for a message to arrive. If a message
3449arrives before the timeout expires the message buffer
3450returned will have a status of RMR_OK and the payload will
3451contain the data received. If the timeout expires before the
3452message is received, the status will have the value
3453RMR_ERR_TIMEOUT. When a received message is returned the
3454message buffer will also contain the message type and length
3455set by the sender. If messages were queued while waiting for
3456the response to a previous invocation of rmr_call, the oldest
3457message is removed from the queue and returned without delay.
3458
3459The *vctx* pointer is the pointer returned by the rmr_init
3460function. *Old_msg* is a pointer to a previously used message
3461buffer or NULL. The ability to reuse message buffers helps to
3462avoid alloc/free cycles in the user application. When no
3463buffer is available to supply, the receive function will
3464allocate one.
3465
3466RETURN VALUE
3467--------------------------------------------------------------------------------------------
3468
3469The function returns a pointer to the rmr_mbuf_t structure
3470which references the message information (state, length,
E. Scott Daniels117030c2020-04-10 17:17:02 -04003471payload), or a nil pointer in the case of an extreme error.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003472
3473ERRORS
3474--------------------------------------------------------------------------------------------
3475
3476The *state* field in the message buffer will be one of the
3477following:
3478
3479
3480
3481RMR_OK
3482
3483 The message buffer (payload) references the received data.
3484
3485
3486RMR_ERR_INITFAILED
3487
3488 The first call to this function must initialise an
3489 underlying system notification mechanism. On failure, this
3490 error is returned and errno will have the system error
3491 status set. If this function fails to intialise, the poll
3492 mechansim, it is likely that message receives will never
3493 be successful.
3494
3495
3496RMR_ERR_TIMEOUT
3497
3498 The timeout expired before a complete message was
3499 received. All other fields in the message buffer are not
3500 valid.
3501
3502
3503RMR_ERR_EMPTY
3504
3505 A message was received, but it had no payload. All other
3506 fields in the message buffer are not valid.
3507
3508
3509
3510
3511INVAL
3512
3513 Parameter(s) passed to the function were not valid.
3514
3515
3516EBADF
3517
3518 The underlying message transport is unable to process the
3519 request.
3520
3521
3522ENOTSUP
3523
3524 The underlying message transport is unable to process the
3525 request.
3526
3527
3528EFSM
3529
3530 The underlying message transport is unable to process the
3531 request.
3532
3533
3534EAGAIN
3535
3536 The underlying message transport is unable to process the
3537 request.
3538
3539
3540EINTR
3541
3542 The underlying message transport is unable to process the
3543 request.
3544
3545
3546ETIMEDOUT
3547
3548 The underlying message transport is unable to process the
3549 request.
3550
3551
3552ETERM
3553
3554 The underlying message transport is unable to process the
3555 request.
3556
3557
3558EXAMPLE
3559--------------------------------------------------------------------------------------------
3560
3561
3562SEE ALSO
3563--------------------------------------------------------------------------------------------
3564
3565rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3566rmr_get_rcvfd(3), rmr_init(3), rmr_payload_size(3),
3567rmr_rcv_msg(3), rmr_send_msg(3), rmr_rcv_specific(3),
3568rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3569rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
3570
3571
3572NAME
3573--------------------------------------------------------------------------------------------
3574
3575rmr_trace_ref
3576
3577SYNOPSIS
3578--------------------------------------------------------------------------------------------
3579
3580
3581::
3582
3583 #include <rmr/rmr.h>
3584 int rmr_trace_ref( rmr_mbuf_t* mbuf, int* sizeptr )
3585
3586
3587
3588DESCRIPTION
3589--------------------------------------------------------------------------------------------
3590
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003591The rmr_trace_ref function returns a pointer to the trace
3592area in the message, and optionally populates the user
3593programme supplied size integer with the trace area size, if
3594*sizeptr* is not nil.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003595
3596RETURN VALUE
3597--------------------------------------------------------------------------------------------
3598
3599On success, a void pointer to the trace area of the message
3600is returned. A nil pointer is returned if the message has no
3601trace data area allocated, or if the message itself is
3602invalid.
3603
3604SEE ALSO
3605--------------------------------------------------------------------------------------------
3606
3607rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
3608rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
3609rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
3610rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
3611rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3612rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3613rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
3614rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
3615rmr_set_trace(3)
3616
3617
3618NAME
3619--------------------------------------------------------------------------------------------
3620
3621rmr_tralloc_msg
3622
3623SYNOPSIS
3624--------------------------------------------------------------------------------------------
3625
3626
3627::
3628
3629 #include <rmr/rmr.h>
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003630 rmr_mbuf_t* rmr_tralloc_msg( void* vctx, int size,
E. Scott Daniels392168d2019-11-06 15:12:38 -05003631 int trace_size, unsigned const char *tr_data );
3632
3633
3634
3635DESCRIPTION
3636--------------------------------------------------------------------------------------------
3637
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003638The rmr_tralloc_msg function is used to allocate a buffer
3639which the user programme can write into and then send through
3640the library. The buffer is allocated such that sending it
E. Scott Daniels392168d2019-11-06 15:12:38 -05003641requires no additional copying from the buffer as it passes
3642through the underlying transport mechanism.
3643
3644The *size* parameter is used to set the payload length in the
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003645message. If it is 0, then the default size supplied on the
E. Scott Daniels392168d2019-11-06 15:12:38 -05003646*rmr_init* call will be used. In addition to allocating the
3647payload, a space in the buffer is reserved for *trace* data
3648(tr_size bytes), and the bytes pointed to by *tr_data* are
3649copied into that portion of the message. The *vctx* parameter
3650is the void context pointer that was returned by the
3651*rmr_init* function.
3652
3653The pointer to the message buffer returned is a structure
3654which has some user application visible fields; the structure
3655is described in rmr.h, and is illustrated below.
3656
3657
3658::
3659
3660 typedef struct {
3661 int state;
3662 int mtype;
3663 int len;
3664 unsigned char* payload;
3665 unsigned char* xaction;
3666 } rmr_mbuf_t;
3667
3668
3669
3670
3671
3672state
3673
3674 Is the current buffer state. Following a call to
3675 rmr_send_msg the state indicates whether the buffer was
3676 successfully sent which determines exactly what the
3677 payload points to. If the send failed, the payload
3678 referenced by the buffer is the message that failed to
3679 send (allowing the application to attempt a
3680 retransmission). When the state is a_OK the buffer
3681 represents an empty buffer that the application may fill
3682 in in preparation to send.
3683
3684
3685mtype
3686
3687 When sending a message, the application is expected to set
3688 this field to the appropriate message type value (as
3689 determined by the user programme). Upon send this value
3690 determines how the a library will route the message. For a
3691 buffer which has been received, this field will contain
3692 the message type that was set by the sending application.
3693
3694
3695len
3696
3697 The application using a buffer to send a message is
3698 expected to set the length value to the actual number of
3699 bytes that it placed into the message. This is likely less
3700 than the total number of bytes that the message can carry.
3701 For a message buffer that is passed to the application as
3702 the result of a receive call, this will be the value that
3703 the sending application supplied and should indicate the
3704 number of bytes in the payload which are valid.
3705
3706
3707payload
3708
3709 The payload is a pointer to the actual received data. The
3710 user programme may read and write from/to the memory
3711 referenced by the payload up until the point in time that
3712 the buffer is used on a rmr_send, rmr_call or rmr_reply
3713 function call. Once the buffer has been passed back to a a
3714 library function the user programme should **NOT** make
3715 use of the payload pointer.
3716
3717
3718xaction
3719
3720 The *xaction* field is a pointer to a fixed sized area in
3721 the message into which the user may write a transaction
3722 ID. The ID is optional with the exception of when the user
3723 application uses the rmr_call function to send a message
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003724 and wait for the reply; the underlying processing expects
3725 that the matching reply message will also contain the same
3726 data in the *xaction* field.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003727
3728
3729RETURN VALUE
3730--------------------------------------------------------------------------------------------
3731
3732The function returns a pointer to a rmr_mbuf structure, or
3733NULL on error.
3734
3735ERRORS
3736--------------------------------------------------------------------------------------------
3737
3738
3739
3740ENOMEM
3741
3742 Unable to allocate memory.
3743
3744
3745SEE ALSO
3746--------------------------------------------------------------------------------------------
3747
3748rmr_alloc_msg(3), rmr_mbuf(3) rmr_call(3), rmr_free_msg(3),
3749rmr_init(3), rmr_init_trace(3), rmr_get_trace(3),
3750rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
3751rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3752rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3753rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
3754
3755
3756NAME
3757--------------------------------------------------------------------------------------------
3758
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003759rmr_wh_call
3760
3761SYNOPSIS
3762--------------------------------------------------------------------------------------------
3763
3764
3765::
3766
3767 #include <rmr/rmr.h>
3768 rmr_mbuf_t* rmr_wh_call( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg, int call_id, int max_wait )
3769
3770
3771
3772DESCRIPTION
3773--------------------------------------------------------------------------------------------
3774
3775The rmr_wh_call function accepts a message buffer (msg) from
3776the user application and attempts to send it using the
3777wormhole ID provided (whid). If the send is successful, the
3778call will block until either a response message is received,
3779or the max_wait number of milliseconds has passed. In order
3780for the response to be recognised as a response, the remote
3781process **must** use rmr_rts_msg() to send their response.
3782
3783Like *rmr_wh_send_msg,* this function attempts to send the
3784message directly to a process at the other end of a wormhole
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003785which was created with *rmr_wh_open().* When sending message
3786via wormholes, the normal RMR routing based on message type
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003787is ignored, and the caller may leave the message type
3788unspecified in the message buffer (unless it is needed by the
3789receiving process). The call_id parameter is a number in the
3790range of 2 through 255 and is used to identify the calling
3791thread in order to properly match a response message when it
3792arrives. Providing this value, and ensuring the proper
3793uniqueness, is the responsibility of the user application and
3794as such the ability to use the rmr_wh_call() function from
3795potentially non-threaded concurrent applications (such as
3796Go's goroutines) is possible.
3797
3798Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04003799~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003800
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003801The send operations in RMR will retry *soft* send failures
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003802until one of three conditions occurs:
3803
3804
3805
38061.
3807
3808 The message is sent without error
3809
3810
38112.
3812
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003813 The underlying transport reports a *hard* failure
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003814
3815
38163.
3817
3818 The maximum number of retry loops has been attempted
3819
3820
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003821A retry loop consists of approximately 1000 send attempts
3822**without** any intervening calls to *sleep()* or *usleep().*
3823The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels8633a0b2020-03-09 13:57:39 -040038241000 send attempts is performed before returning to the user
3825application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003826initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003827allowing the user application to completely disable retires
3828(set to 0), or to increase the number of retry loops.
3829
3830Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -04003831~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003832
3833The underlying transport mechanism used to send messages is
3834configured in *non-blocking* mode. This means that if a
3835message cannot be sent immediately the transport mechanism
3836will **not** pause with the assumption that the inability to
3837send will clear quickly (within a few milliseconds). This
3838means that when the retry loop is completely disabled (set to
38390), that the failure to accept a message for sending by the
3840underlying mechanisms (software or hardware) will be reported
3841immediately to the user application.
3842
3843It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003844mechanism being used, it is extremely likely that retry
3845conditions will happen during normal operations. These are
3846completely out of RMR's control, and there is nothing that
3847RMR can do to avoid or mitigate these other than by allowing
3848RMR to retry the send operation, and even then it is possible
3849(e.g., during connection reattempts), that a single retry
3850loop is not enough to guarantee a successful send.
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003851
3852RETURN VALUE
3853--------------------------------------------------------------------------------------------
3854
3855On success, new message buffer, with the payload containing
3856the response from the remote endpoint is returned. The state
3857in this buffer will reflect the overall send operation state
3858and should be RMR_OK.
3859
3860If a message is returned with a state which is anything other
3861than RMR_OK, the indication is that the send was not
3862successful. The user application must check the state and
3863determine the course of action. If the return value is NULL,
3864no message, the indication is that there was no response
3865received within the timeout (max_wait) period of time.
3866
3867ERRORS
3868--------------------------------------------------------------------------------------------
3869
3870The following values may be passed back in the *state* field
3871of the returned message buffer.
3872
3873
3874
3875RMR_ERR_WHID
3876
3877 The wormhole ID passed in was not associated with an open
3878 wormhole, or was out of range for a valid ID.
3879
3880RMR_ERR_NOWHOPEN
3881
3882 No wormholes exist, further attempt to validate the ID are
3883 skipped.
3884
3885RMR_ERR_BADARG
3886
3887 The message buffer pointer did not refer to a valid
3888 message.
3889
3890RMR_ERR_NOHDR
3891
3892 The header in the message buffer was not valid or
3893 corrupted.
3894
3895
3896EXAMPLE
3897--------------------------------------------------------------------------------------------
3898
3899The following is a simple example of how the a wormhole is
3900created (rmr_wh_open) and then how rmr_wh_send_msg function
3901is used to send messages. Some error checking is omitted for
3902clarity.
3903
3904
3905::
3906
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003907 #include <rmr/rmr.h> // system headers omitted for clarity
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003908 int main() {
3909 rmr_whid_t whid = -1; // wormhole id for sending
3910 void* mrc; //msg router context
3911 int i;
3912 rmr_mbuf_t* sbuf; // send buffer
3913 int count = 0;
E. Scott Daniels117030c2020-04-10 17:17:02 -04003914 int norm_msg_size = 1500; // most messages fit in this size
3915 mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003916 if( mrc == NULL ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003917 fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003918 exit( 1 );
3919 }
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003920 while( ! rmr_ready( mrc ) ) { // wait for routing table info
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003921 sleep( 1 );
3922 }
3923 sbuf = rmr_alloc_msg( mrc, 2048 );
3924 while( 1 ) {
3925 if( whid < 0 ) {
3926 whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003927 if( RMR_WH_CONNECTED( wh ) ) {
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003928 snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
3929 sbuf->len = strlen( sbuf->payload );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003930 sbuf = rmr_wh_call( mrc, whid, sbuf, 1000 ); // expect a response in 1s or less
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003931 if( sbuf != NULL && sbuf->state = RMR_OK ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003932 sprintf( stderr, "response: %s\\n", sbuf->payload ); // assume they sent a string
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003933 } else {
3934 sprintf( stderr, "response not received, or send error\\n" );
3935 }
3936 }
3937 }
3938 sleep( 5 );
3939 }
3940 }
3941
3942
3943
3944SEE ALSO
3945--------------------------------------------------------------------------------------------
3946
3947rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3948rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3949rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3950rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3951rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3),
3952rmr_wh_state(3)
3953
3954
3955NAME
3956--------------------------------------------------------------------------------------------
3957
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003958rmr_wh_close
E. Scott Daniels392168d2019-11-06 15:12:38 -05003959
3960SYNOPSIS
3961--------------------------------------------------------------------------------------------
3962
3963
3964::
3965
3966 #include <rmr/rmr.h>
3967 void rmr_close( void* vctx, rmr_whid_t whid )
3968
3969
3970
3971DESCRIPTION
3972--------------------------------------------------------------------------------------------
3973
3974The rmr_wh_close function closes the wormhole associated with
3975the wormhole id passed in. Future calls to rmr_wh_send_msg
3976with this ID will fail.
3977
3978The underlying TCP connection to the remote endpoint is
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003979**not** closed as this session may be required for regularly
3980routed messages (messages routed based on message type).
3981There is no way to force a TCP session to be closed at this
3982point in time.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003983
3984SEE ALSO
3985--------------------------------------------------------------------------------------------
3986
3987rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3988rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
3989rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3990rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3991rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
3992rmr_wh_send_msg(3)
3993
3994
3995NAME
3996--------------------------------------------------------------------------------------------
3997
3998rmr_wh_open
3999
4000SYNOPSIS
4001--------------------------------------------------------------------------------------------
4002
4003
4004::
4005
4006 #include <rmr/rmr.h>
4007 void* rmr_wh_open( void* vctx, char* target )
4008
4009
4010
4011DESCRIPTION
4012--------------------------------------------------------------------------------------------
4013
4014The rmr_wh_open function creates a direct link for sending, a
4015wormhole, to another RMr based process. Sending messages
4016through a wormhole requires that the connection be
4017established overtly by the user application (via this
4018function), and that the ID returned by rmr_wh_open be passed
4019to the rmr_wh_send_msg function.
4020
4021*Target* is the *name* or *IP-address* combination of the
4022processess that the wormhole should be connected to. *Vctx*
4023is the RMr void context pointer that was returned by the
4024rmr_init function.
4025
4026When invoked, this function immediatly attempts to connect to
4027the target process. If the connection cannot be established,
4028an error is returned to the caller, and no direct messages
4029can be sent to the target. Once a wormhole is connected, the
4030underlying transport mechanism (e.g. NNG) will provide
4031reconnects should the connection be lost, however the
4032handling of messages sent when a connection is broken is
4033undetermined as each underlying transport mechanism may
4034handle buffering and retries differently.
4035
4036RETURN VALUE
4037--------------------------------------------------------------------------------------------
4038
4039The rmr_wh_open function returns a type rmr_whid_t which must
4040be passed to the rmr_wh_send_msg function when sending a
4041message. The id may also be tested to determine success or
4042failure of the connection by using the RMR_WH_CONNECTED macro
4043and passing the ID as the parameter; a result of 1 indicates
4044that the connection was esablished and that the ID is valid.
4045
4046ERRORS
4047--------------------------------------------------------------------------------------------
4048
4049The following error values are specifically set by this RMR
4050function. In some cases the error message of a system call is
4051propagated up, and thus this list might be incomplete.
4052
4053
4054EINVAL
4055
4056 A parameter passed was not valid.
4057
4058EACCESS
4059
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004060 The user application does not have the ability to
E. Scott Daniels392168d2019-11-06 15:12:38 -05004061 establish a wormhole to the indicated target (or maybe any
4062 target).
4063
4064ECONNREFUSED
4065
4066 The connection was refused.
4067
4068
4069EXAMPLE
4070--------------------------------------------------------------------------------------------
4071
4072
4073::
4074
4075 void* rmc;
4076 rmr_whid_t wh;
4077 rmc = rmr_init( "43086", 4096, 0 ); // init context
4078 wh = rmr_wh_open( rmc, "localhost:6123" );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004079 if( !RMR_WH_CONNECTED( wh ) ) {
4080 fprintf( stderr, "unable to connect wormhole: %s\\n",
E. Scott Daniels392168d2019-11-06 15:12:38 -05004081 strerror( errno ) );
4082 }
4083
4084
4085
4086SEE ALSO
4087--------------------------------------------------------------------------------------------
4088
4089rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
4090rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
4091rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
4092rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004093rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_close(3),
4094rmr_wh_send_msg(3), rmr_wh_state(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -05004095
4096
4097NAME
4098--------------------------------------------------------------------------------------------
4099
4100rmr_wh_send_msg
4101
4102SYNOPSIS
4103--------------------------------------------------------------------------------------------
4104
4105
4106::
4107
4108 #include <rmr/rmr.h>
4109 rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t id, rmr_mbuf_t* msg );
4110
4111
4112
4113DESCRIPTION
4114--------------------------------------------------------------------------------------------
4115
4116The rmr_wh_send_msg function accepts a message buffer from
4117the user application and attempts to send it using the
4118wormhole ID provided (id). Unlike *rmr_send_msg,* this
4119function attempts to send the message directly to a process
4120at the other end of a wormhole which was created with
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004121*rmr_wh_open().* When sending message via wormholes, the
4122normal RMR routing based on message type is ignored, and the
E. Scott Daniels392168d2019-11-06 15:12:38 -05004123caller may leave the message type unspecified in the message
4124buffer (unless it is needed by the receiving process).
4125
4126The message buffer (msg) used to send is the same format as
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004127used for regular RMR send and reply to sender operations,
E. Scott Daniels392168d2019-11-06 15:12:38 -05004128thus any buffer allocated by these means, or calls to
4129*rmr_rcv_msg()* can be passed to this function.
4130
4131Retries
E. Scott Daniels117030c2020-04-10 17:17:02 -04004132~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05004133
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004134The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05004135until one of three conditions occurs:
4136
4137
4138
41391.
4140
4141 The message is sent without error
4142
4143
41442.
4145
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004146 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05004147
4148
41493.
4150
4151 The maximum number of retry loops has been attempted
4152
4153
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004154A retry loop consists of approximately 1000 send attempts
4155**without** any intervening calls to *sleep()* or *usleep().*
4156The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050041571000 send attempts is performed before returning to the user
4158application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004159initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05004160allowing the user application to completely disable retires
4161(set to 0), or to increase the number of retry loops.
4162
4163Transport Level Blocking
E. Scott Daniels117030c2020-04-10 17:17:02 -04004164~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E. Scott Daniels392168d2019-11-06 15:12:38 -05004165
4166The underlying transport mechanism used to send messages is
4167configured in *non-blocking* mode. This means that if a
4168message cannot be sent immediately the transport mechanism
4169will **not** pause with the assumption that the inability to
4170send will clear quickly (within a few milliseconds). This
4171means that when the retry loop is completely disabled (set to
41720), that the failure to accept a message for sending by the
4173underlying mechanisms (software or hardware) will be reported
4174immediately to the user application.
4175
4176It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004177mechanism being used, it is extremely likely that retry
4178conditions will happen during normal operations. These are
4179completely out of RMR's control, and there is nothing that
4180RMR can do to avoid or mitigate these other than by allowing
4181RMR to retry the send operation, and even then it is possible
4182(e.g., during connection reattempts), that a single retry
4183loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05004184
4185RETURN VALUE
4186--------------------------------------------------------------------------------------------
4187
4188On success, a new message buffer, with an empty payload, is
4189returned for the application to use for the next send. The
4190state in this buffer will reflect the overall send operation
4191state and should be RMR_OK.
4192
4193If the state in the returned buffer is anything other than
4194RMR_OK, the user application may need to attempt a
4195retransmission of the message, or take other action depending
4196on the setting of errno as described below.
4197
E. Scott Daniels117030c2020-04-10 17:17:02 -04004198In the event of extreme failure, a nil pointer is returned.
E. Scott Daniels392168d2019-11-06 15:12:38 -05004199In this case the value of errno might be of some use, for
4200documentation, but there will be little that the user
4201application can do other than to move on.
4202
4203ERRORS
4204--------------------------------------------------------------------------------------------
4205
4206The following values may be passed back in the *state* field
4207of the returned message buffer.
4208
4209
4210
4211RMR_ERR_WHID
4212
4213 The wormhole ID passed in was not associated with an open
4214 wormhole, or was out of range for a valid ID.
4215
4216RMR_ERR_NOWHOPEN
4217
4218 No wormholes exist, further attempt to validate the ID are
4219 skipped.
4220
4221RMR_ERR_BADARG
4222
4223 The message buffer pointer did not refer to a valid
4224 message.
4225
4226RMR_ERR_NOHDR
4227
4228 The header in the message buffer was not valid or
4229 corrupted.
4230
4231
4232The following values may be assigned to errno on failure.
4233
4234
4235INVAL
4236
4237 Parameter(s) passed to the function were not valid, or the
4238 underlying message processing environment was unable to
4239 interpret the message.
4240
4241
4242ENOKEY
4243
4244 The header information in the message buffer was invalid.
4245
4246
4247ENXIO
4248
4249 No known endpoint for the message could be found.
4250
4251
4252EMSGSIZE
4253
4254 The underlying transport refused to accept the message
4255 because of a size value issue (message was not attempted
4256 to be sent).
4257
4258
4259EFAULT
4260
4261 The message referenced by the message buffer is corrupt
E. Scott Daniels117030c2020-04-10 17:17:02 -04004262 (nil pointer or bad internal length).
E. Scott Daniels392168d2019-11-06 15:12:38 -05004263
4264
4265EBADF
4266
4267 Internal RMR error; information provided to the message
4268 transport environment was not valid.
4269
4270
4271ENOTSUP
4272
4273 Sending was not supported by the underlying message
4274 transport.
4275
4276
4277EFSM
4278
4279 The device is not in a state that can accept the message.
4280
4281
4282EAGAIN
4283
4284 The device is not able to accept a message for sending.
4285 The user application should attempt to resend.
4286
4287
4288EINTR
4289
4290 The operation was interrupted by delivery of a signal
4291 before the message was sent.
4292
4293
4294ETIMEDOUT
4295
4296 The underlying message environment timed out during the
4297 send process.
4298
4299
4300ETERM
4301
4302 The underlying message environment is in a shutdown state.
4303
4304
4305EXAMPLE
4306--------------------------------------------------------------------------------------------
4307
4308The following is a simple example of how the a wormhole is
4309created (rmr_wh_open) and then how rmr_wh_send_msg function
4310is used to send messages. Some error checking is omitted for
4311clarity.
4312
4313
4314::
4315
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004316 #include <rmr/rmr.h> // system headers omitted for clarity
E. Scott Daniels392168d2019-11-06 15:12:38 -05004317 int main() {
4318 rmr_whid_t whid = -1; // wormhole id for sending
4319 void* mrc; //msg router context
4320 int i;
4321 rmr_mbuf_t* sbuf; // send buffer
4322 int count = 0;
E. Scott Daniels117030c2020-04-10 17:17:02 -04004323 int norm_msg_size = 1500; // most msg fit in this size
4324 mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
E. Scott Daniels392168d2019-11-06 15:12:38 -05004325 if( mrc == NULL ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004326 fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
E. Scott Daniels392168d2019-11-06 15:12:38 -05004327 exit( 1 );
4328 }
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004329 while( ! rmr_ready( mrc ) ) { // wait for routing table info
E. Scott Daniels392168d2019-11-06 15:12:38 -05004330 sleep( 1 );
4331 }
4332 sbuf = rmr_alloc_msg( mrc, 2048 );
4333 while( 1 ) {
4334 if( whid < 0 ) {
4335 whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004336 if( RMR_WH_CONNECTED( wh ) ) {
E. Scott Daniels392168d2019-11-06 15:12:38 -05004337 snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
4338 sbuf->len = strlen( sbuf->payload );
4339 sbuf = rmr_wh_send_msg( mrc, whid, sbuf );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004340 }
4341 }
4342 sleep( 5 );
E. Scott Daniels392168d2019-11-06 15:12:38 -05004343 }
4344 }
4345
4346
4347
4348SEE ALSO
4349--------------------------------------------------------------------------------------------
4350
4351rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
4352rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
4353rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
4354rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004355rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3),
4356rmr_wh_state(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -05004357
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004358
4359NAME
4360--------------------------------------------------------------------------------------------
4361
4362rmr_wh_state
4363
4364SYNOPSIS
4365--------------------------------------------------------------------------------------------
4366
4367
4368::
4369
4370 #include <rmr/rmr.h>
4371 int rmr_wh_state( void* vctx, rmr_whid_t whid )
4372
4373
4374
4375DESCRIPTION
4376--------------------------------------------------------------------------------------------
4377
4378The rmr_wh_state function will return the current state of
4379the connection associated with the given wormhole (whid). The
4380return value indicates whether the connection is open
4381(RMR_OK), or closed (any other return value).
4382
4383When using some transport mechanisms (e.g. NNG), it may not
4384be possible for RMR to know the actual state and the
4385connection may always be reported as "open."
4386
4387RETURN
4388--------------------------------------------------------------------------------------------
4389
4390The following values are potential return values.
4391
4392
4393
4394RMR_OK
4395
4396 The wormhole ID is valid and the connection is "open."
4397
4398
4399RMR_ERR_WHID
4400
4401 THe wormhole ID passed into the function was not valid.
4402
4403
4404RMR_ERR_NOENDPT
4405
4406 The wormhole is not open (not connected).
4407
4408
4409RMR_ERR_BADARG
4410
4411 The context passed to the function was nil or invalid.
4412
4413
4414RMR_ERR_NOWHOPEN
4415
4416 Wormholes have not been initialised (no wormhole open call
4417 has been made).
4418
4419
4420
4421SEE ALSO
4422--------------------------------------------------------------------------------------------
4423
4424rmr_wh_open(3), rmr_wh_send_msg(3), rmr_wh_close(3)