blob: cc84a2c880238f685f6e781948cb2e1e37f5d277 [file] [log] [blame]
E. Scott Daniels392168d2019-11-06 15:12:38 -05001
2.. This work is licensed under a Creative Commons Attribution 4.0 International License.
3.. SPDX-License-Identifier: CC-BY-4.0
4.. CAUTION: this document is generated from source in doc/src/rtd.
5.. To make changes edit the source and recompile the document.
6.. Do NOT make changes directly to .rst or .md files.
7
8
9RMR User's Guide
10============================================================================================
11
Lott, Christopher (cl778h)fe6a8562020-04-06 15:05:22 -040012The RIC Message Router (RMR) is a library for peer-to-peer
13communication. Applications use the library to send and
14receive messages where the message routing and endpoint
15selection is based on the message type rather than DNS host
16name-IP port combinations.
17
18This document contains information that developers need to
19know to use the RMR library. Because the primary
20documentation for the RMR library is a collection of UNIX
21manpages (included in the development package, and available
22via the man command when installed), there is no separate
23"User's Guide." To provide something for the document
24scrapers to find, this is a collection of the RMR manual
25pages formatted directly from their source, which might be a
26bit ragged when combined into a single markup document. Read
27the manual pages :)
E. Scott Daniels392168d2019-11-06 15:12:38 -050028
29
30
31NAME
32--------------------------------------------------------------------------------------------
33
34rmr_alloc_msg
35
36SYNOPSIS
37--------------------------------------------------------------------------------------------
38
39
40::
41
42 #include <rmr/rmr.h>
43 rmr_mbuf_t* rmr_alloc_msg( void* ctx, int size );
44
45
46
47DESCRIPTION
48--------------------------------------------------------------------------------------------
49
50The rmr_alloc_msg function is used to allocate a buffer which
51the user programme can write into and then send through the
52RMR library. The buffer is allocated such that sending it
53requires no additional copying out of the buffer. If the
54value passed in size is 0, then the default size supplied on
55the *rmr_init* call will be used. The *ctx* parameter is the
56void context pointer that was returned by the *rmr_init*
57function.
58
59The pointer to the message buffer returned is a structure
60which has some user application visible fields; the structure
61is described in rmr.h, and is illustrated below.
62
63
64::
65
66 typedef struct {
67 int state;
68 int mtype;
69 int len;
70 unsigned char* payload;
71 unsigned char* xaction;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -040072 int sub_id;
73 int tp_state;
E. Scott Daniels392168d2019-11-06 15:12:38 -050074 } rmr_mbuf_t;
75
76
77
78
79
80state
81
82 Is the current buffer state. Following a call to
83 rmr_send_msg the state indicates whether the buffer was
84 successfully sent which determines exactly what the
85 payload points to. If the send failed, the payload
86 referenced by the buffer is the message that failed to
87 send (allowing the application to attempt a
88 retransmission). When the state is RMR_OK the buffer
89 represents an empty buffer that the application may fill
90 in in preparation to send.
91
92
93mtype
94
95 When sending a message, the application is expected to set
96 this field to the appropriate message type value (as
97 determined by the user programme). Upon send this value
98 determines how the RMR library will route the message. For
99 a buffer which has been received, this field will contain
100 the message type that was set by the sending application.
101
102
103len
104
105 The application using a buffer to send a message is
106 expected to set the length value to the actual number of
107 bytes that it placed into the message. This is likely less
108 than the total number of bytes that the message can carry.
109 For a message buffer that is passed to the application as
110 the result of a receive call, this will be the value that
111 the sending application supplied and should indicate the
112 number of bytes in the payload which are valid.
113
114
115payload
116
117 The payload is a pointer to the actual received data. The
118 user programme may read and write from/to the memory
119 referenced by the payload up until the point in time that
120 the buffer is used on a rmr_send, rmr_call or rmr_reply
121 function call. Once the buffer has been passed back to a
122 RMR library function the user programme should **NOT**
123 make use of the payload pointer.
124
125
126xaction
127
128 The *xaction* field is a pointer to a fixed sized area in
129 the message into which the user may write a transaction
130 ID. The ID is optional with the exception of when the user
131 application uses the rmr_call function to send a message
132 and wait for the reply; the underlying RMR processing
133 expects that the matching reply message will also contain
134 the same data in the *xaction* field.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500135
E. Scott Daniels392168d2019-11-06 15:12:38 -0500136
137sub_id
138
139 This value is the subscription ID. It, in combination with
140 the message type is used by rmr to determine the target
141 endpoint when sending a message. If the application to
142 application protocol does not warrant the use of a
143 subscription ID, the RMR constant RMR_VOID_SUBID should be
144 placed in this field. When an application is forwarding or
145 returning a buffer to the sender, it is the application's
146 responsibility to set/reset this value.
147
148
149tp_state
150
151 For C applications making use of RMR, the state of a
152 transport based failure will often be available via errno.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500153 However, some wrapper environments may not have direct
154 access to the C-lib errno value. RMR send and receive
155 operations will place the current value of errno into this
156 field which should make it available to wrapper functions.
157 User applications are strongly cautioned against relying
158 on the value of errno as some transport mechanisms may not
159 set this value on all calls. This value should also be
160 ignored any time the message status is RMR_OK.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500161
162
163RETURN VALUE
164--------------------------------------------------------------------------------------------
165
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500166The function returns a pointer to a rmr_mbuf structure, or
167NULL on error.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500168
169ERRORS
170--------------------------------------------------------------------------------------------
171
172
173
174ENOMEM
175
176 Unable to allocate memory.
177
178
179SEE ALSO
180--------------------------------------------------------------------------------------------
181
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -0500182rmr_tralloc_msg(3), rmr_call(3), rmr_free_msg(3),
183rmr_init(3), rmr_init_trace(3), rmr_get_trace(3),
184rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
185rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
186rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
187rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -0500188
189
190NAME
191--------------------------------------------------------------------------------------------
192
193rmr_bytes2meid
194
195SYNOPSIS
196--------------------------------------------------------------------------------------------
197
198
199::
200
201 #include <rmr/rmr.h>
202 int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
203
204
205
206DESCRIPTION
207--------------------------------------------------------------------------------------------
208
209The rmr_bytes2meid function will copy up to *len* butes from
E. Scott Daniels190665f2019-12-09 09:05:22 -0500210*src* to the managed entity ID (meid) field in the message.
211The field is a fixed length, gated by the constant
E. Scott Daniels392168d2019-11-06 15:12:38 -0500212RMR_MAX_MEID and if len is larger than this value, only
213RMR_MAX_MEID bytes will actually be copied.
214
215RETURN VALUE
216--------------------------------------------------------------------------------------------
217
218On success, the actual number of bytes copied is returned, or
219-1 to indicate a hard error. If the length is less than 0, or
220not the same as length passed in, errno is set to one of the
221errors described in the *Errors* section.
222
223ERRORS
224--------------------------------------------------------------------------------------------
225
226If the returned length does not match the length passed in,
227errno will be set to one of the following constants with the
228meaning listed below.
229
230
231
232EINVAL
233
234 The message, or an internal portion of the message, was
235 corrupted or the pointer was invalid.
236
237
238EOVERFLOW
239
240 The length passed in was larger than the maximum length of
241 the field; only a portion of the source bytes were copied.
242
243
244EXAMPLE
245--------------------------------------------------------------------------------------------
246
247
248SEE ALSO
249--------------------------------------------------------------------------------------------
250
251rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_call(3),
252rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_meid(3),
253rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
254rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
255rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
256rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
257rmr_wh_open(3), rmr_wh_send_msg(3)
258
259
260NAME
261--------------------------------------------------------------------------------------------
262
263rmr_bytes2payload
264
265SYNOPSIS
266--------------------------------------------------------------------------------------------
267
268
269::
270
271 #include <rmr/rmr.h>
272 void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char* src, int len )
273
274
275
276DESCRIPTION
277--------------------------------------------------------------------------------------------
278
279This is a convenience function as some wrapper languages
280might not have the ability to directly copy into the payload
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500281buffer. The bytes from *src* for the length given are copied
282to the payload. It is the caller's responsibility to ensure
283that the payload is large enough. Upon successfully copy, the
284len field in the message buffer is updated to reflect the
285number of bytes copied.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500286
287There is little error checking, and no error reporting.
288
289RETURN VALUE
290--------------------------------------------------------------------------------------------
291
292None.
293
294EXAMPLE
295--------------------------------------------------------------------------------------------
296
297
298SEE ALSO
299--------------------------------------------------------------------------------------------
300
301rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2payload(3),
302rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
303rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
304rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
305rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
306rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
307rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
308
309
310NAME
311--------------------------------------------------------------------------------------------
312
313rmr_bytes2xact
314
315SYNOPSIS
316--------------------------------------------------------------------------------------------
317
318
319::
320
321 #include <rmr/rmr.h>
322 int rmr_bytes2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
323
324
325
326DESCRIPTION
327--------------------------------------------------------------------------------------------
328
329The rmr_bytes2xact function will copy up to *len* butes from
330*src* to the transaction ID (xaction) field in the message.
331The field is a fixed length, gated by the constant
332RMR_MAX_XID and if len is larger than this value, only
333RMR_MAX_XID bytes will actually be copied.
334
335
336RETURN VALUE
337--------------------------------------------------------------------------------------------
338
339On success, the actual number of bytes copied is returned,
340or -1 to indicate a hard error. If the length is less than
3410, or not the same as length passed in, errno is set to
342one of the errors described in the *Errors* section.
343
344ERRORS
345--------------------------------------------------------------------------------------------
346
347If the returned length does not match the length passed
348in, errno will be set to one of the following constants
349with the meaning listed below.
350
351
352EINVAL
353
354 The message, or an internal portion of the message, was
355 corrupted or the pointer was invalid.
356
357
358EOVERFLOW
359
360 The length passed in was larger than the maximum length of
361 the field; only a portion of the source bytes were copied.
362
363
364EXAMPLE
365--------------------------------------------------------------------------------------------
366
367
368SEE ALSO
369--------------------------------------------------------------------------------------------
370
371rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_call(3),
372rmr_free_msg(3), rmr_get_meid(3), rmr_get_rcvfd(3),
373rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
374rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
375rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
376rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
377rmr_wh_open(3), rmr_wh_send_msg(3)
378
379
380NAME
381--------------------------------------------------------------------------------------------
382
383rmr_call
384
385SYNOPSIS
386--------------------------------------------------------------------------------------------
387
388
389::
390
391 #include <rmr/rmr.h>
392 extern rmr_mbuf_t* rmr_call( void* vctx, rmr_mbuf_t* msg );
393
394
395
396DESCRIPTION
397--------------------------------------------------------------------------------------------
398
399The rmr_call function sends the user application message to a
400remote endpoint, and waits for a corresponding response
401message before returning control to the user application. The
402user application supplies a completed message buffer, as it
403would for a rmr_send call, but unlike with the send, the
404buffer returned will have the response from the application
405that received the message.
406
407Messages which are received while waiting for the response
408are queued internally by RMR, and are returned to the user
409application when rmr_rcv_msg is invoked. These messages are
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400410returned in the order received, one per call to rmr_rcv_msg.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500411
412Call Timeout
413~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
414
415The rmr_call function implements a timeout failsafe to
416prevent, in most cases, the function from blocking forever.
417The timeout period is **not** based on time (calls to clock
418are deemed too expensive for a low latency system level
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400419library), but instead the period is based on the number of
E. Scott Daniels392168d2019-11-06 15:12:38 -0500420received messages which are not the response. Using a
421non-time mechanism for *timeout* prevents the async queue
422from filling (which would lead to message drops) in an
423environment where there is heavy message traffic.
424
425When the threshold number of messages have been queued
426without receiving a response message, control is returned to
427the user application and a NULL pointer is returned to
428indicate that no message was received to process. Currently
429the threshold is fixed at 20 messages, though in future
430versions of the library this might be extended to be a
431parameter which the user application may set.
432
433Retries
434~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
435
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400436The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -0500437until one of three conditions occurs:
438
439
440
4411.
442
443 The message is sent without error
444
445
4462.
447
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400448 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -0500449
450
4513.
452
453 The maximum number of retry loops has been attempted
454
455
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400456A retry loop consists of approximately 1000 send attempts
457**without** any intervening calls to *sleep()* or *usleep().*
458The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -05004591000 send attempts is performed before returning to the user
460application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400461initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -0500462allowing the user application to completely disable retires
463(set to 0), or to increase the number of retry loops.
464
465Transport Level Blocking
466~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
467
468The underlying transport mechanism used to send messages is
469configured in *non-blocking* mode. This means that if a
470message cannot be sent immediately the transport mechanism
471will **not** pause with the assumption that the inability to
472send will clear quickly (within a few milliseconds). This
473means that when the retry loop is completely disabled (set to
4740), that the failure to accept a message for sending by the
475underlying mechanisms (software or hardware) will be reported
476immediately to the user application.
477
478It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400479mechanism being used, it is extremely likely that retry
480conditions will happen during normal operations. These are
481completely out of RMR's control, and there is nothing that
482RMR can do to avoid or mitigate these other than by allowing
483RMR to retry the send operation, and even then it is possible
484(e.g., during connection reattempts), that a single retry
485loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500486
487RETURN VALUE
488--------------------------------------------------------------------------------------------
489
490The rmr_call function returns a pointer to a message buffer
491with the state set to reflect the overall state of call
492processing (see Errors below). In some cases a NULL pointer
493will be returned; when this is the case only *errno* will be
494available to describe the reason for failure.
495
496ERRORS
497--------------------------------------------------------------------------------------------
498
499These values are reflected in the state field of the returned
500message.
501
502
503
504RMR_OK
505
506 The call was successful and the message buffer references
507 the response message.
508
509
510RMR_ERR_CALLFAILED
511
512 The call failed and the value of *errno,* as described
513 below, should be checked for the specific reason.
514
515
516The global "variable" *errno* will be set to one of the
517following values if the overall call processing was not
518successful.
519
520
521
522ETIMEDOUT
523
524 Too many messages were queued before receiving the
525 expected response
526
527
528ENOBUFS
529
530 The queued message ring is full, messages were dropped
531
532
533EINVAL
534
535 A parameter was not valid
536
537
538EAGAIN
539
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400540 The underlying message system was interrupted or the
541 device was busy; the message was **not** sent, and the
542 user application should call this function with the
543 message again.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500544
545
546EXAMPLE
547--------------------------------------------------------------------------------------------
548
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400549The following code snippet shows one way of using the
550rmr_call function, and illustrates how the transaction ID
551must be set.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500552
553
554::
555
556 int retries_left = 5; // max retries on dev not available
557 int retry_delay = 50000; // retry delay (usec)
558 static rmr_mbuf_t* mbuf = NULL; // response msg
559 msg_t* pm; // private message (payload)
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400560 // get a send buffer and reference the payload
E. Scott Daniels392168d2019-11-06 15:12:38 -0500561 mbuf = rmr_alloc_msg( mr, RMR_MAX_RCV_BYTES );
562 pm = (msg_t*) mbuf->payload;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400563 // generate an xaction ID and fill in payload with data and msg type
E. Scott Daniels392168d2019-11-06 15:12:38 -0500564 snprintf( mbuf->xaction, RMR_MAX_XID, "%s", gen_xaction() );
565 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
566 mbuf->mtype = MT_REQ;
E. Scott Daniels392168d2019-11-06 15:12:38 -0500567 msg = rmr_call( mr, msg );
568 if( ! msg ) { // probably a timeout and no msg received
569 return NULL; // let errno trickle up
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400570 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500571 if( mbuf->state != RMR_OK ) {
572 while( retries_left-- > 0 && // loop as long as eagain
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400573 errno == EAGAIN &&
574 (msg = rmr_call( mr, msg )) != NULL &&
E. Scott Daniels392168d2019-11-06 15:12:38 -0500575 mbuf->state != RMR_OK ) {
576 usleep( retry_delay );
577 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500578 if( mbuf == NULL || mbuf->state != RMR_OK ) {
579 rmr_free_msg( mbuf ); // safe if nil
580 return NULL;
581 }
582 }
583 // do something with mbuf
584
585
586
587SEE ALSO
588--------------------------------------------------------------------------------------------
589
590rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
591rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
592rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
593rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
594rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
595
596
597NAME
598--------------------------------------------------------------------------------------------
599
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400600rmr_close
E. Scott Daniels392168d2019-11-06 15:12:38 -0500601
602SYNOPSIS
603--------------------------------------------------------------------------------------------
604
605
606::
607
608 #include <rmr/rmr.h>
609 void rmr_close( void* vctx )
610
611
612
613DESCRIPTION
614--------------------------------------------------------------------------------------------
615
616The rmr_close function closes the listen socket effectively
617cutting the application off. The route table listener is also
618stopped. Calls to rmr_rcv_msg() will fail with unpredictable
619error codes, and calls to rmr_send_msg(), rmr_call(), and
620rmr_rts_msg() will have unknown results.
621
622
623SEE ALSO
624--------------------------------------------------------------------------------------------
625
626rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
627rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
628rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
629rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
630rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
631rmr_wh_send_msg(3)
632
633
634NAME
635--------------------------------------------------------------------------------------------
636
637rmr_free_msg
638
639SYNOPSIS
640--------------------------------------------------------------------------------------------
641
642
643::
644
645 #include <rmr/rmr.h>
646 void rmr_free_msg( rmr_mbuf_t* mbuf );
647
648
649
650DESCRIPTION
651--------------------------------------------------------------------------------------------
652
653The message buffer is returned to the pool, or the associated
654memory is released depending on the needs of the underlying
655messaging system. This allows the user application to release
656a buffer that is not going to be used. It is safe to pass a
657nil pointer to this function, and doing so does not result in
658a change to the value of errrno.
659
660After calling, the user application should **not** use any of
661the pointers (transaction ID, or payload) which were
662available.
663
664SEE ALSO
665--------------------------------------------------------------------------------------------
666
667rmr_alloc_msg(3), rmr_call(3), rmr_init(3),
668rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
669rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
670rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
671rmr_ring_free(3)
672
673
674NAME
675--------------------------------------------------------------------------------------------
676
677rmr_get_meid
678
679SYNOPSIS
680--------------------------------------------------------------------------------------------
681
682
683::
684
685 #include <rmr/rmr.h>
686 char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest )
687
688
689
690DESCRIPTION
691--------------------------------------------------------------------------------------------
692
E. Scott Daniels190665f2019-12-09 09:05:22 -0500693The rmr_get_meid function will copy the managed entity ID
E. Scott Daniels392168d2019-11-06 15:12:38 -0500694(meid) field from the message into the *dest* buffer provided
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500695by the user. The buffer referenced by *dest* is assumed to be
696at least RMR_MAX_MEID bytes in length. If *dest* is NULL,
697then a buffer is allocated (the calling application is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500698expected to free when the buffer is no longer needed).
699
700RETURN VALUE
701--------------------------------------------------------------------------------------------
702
703On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500704*dest* was supplied, then this is just a pointer to the
705caller's buffer. If *dest* was NULL, this is a pointer to the
706allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500707returned and errno is set as described below.
708
709ERRORS
710--------------------------------------------------------------------------------------------
711
712If an error occurs, the value of the global variable errno
713will be set to one of the following with the indicated
714meaning.
715
716
717
718EINVAL
719
720 The message, or an internal portion of the message, was
721 corrupted or the pointer was invalid.
722
723
724ENOMEM
725
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500726 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -0500727 possible to allocate a buffer using malloc().
728
729
730SEE ALSO
731--------------------------------------------------------------------------------------------
732
733rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
734rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
735rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
736rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
737rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
738rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
739rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
740
741
742NAME
743--------------------------------------------------------------------------------------------
744
745rmr_get_rcvfd
746
747SYNOPSIS
748--------------------------------------------------------------------------------------------
749
750
751::
752
753 #include <rmr/rmr.h>
754 void* rmr_get_rcvfd( void* ctx )
755
756
757
758DESCRIPTION
759--------------------------------------------------------------------------------------------
760
761The rmr_get_rcvfd function returns a file descriptor which
762may be given to epoll_wait() by an application that wishes to
763use event poll in a single thread rather than block on the
764arrival of a message via calls to rmr_rcv_msg(). When
765epoll_wait() indicates that this file descriptor is ready, a
766call to rmr_rcv_msg() will not block as at least one message
767has been received.
768
769The context (ctx) pointer passed in is the pointer returned
770by the call to rmr_init().
771
E. Scott Daniels392168d2019-11-06 15:12:38 -0500772RETURN VALUE
773--------------------------------------------------------------------------------------------
774
775The rmr_get_rcvfd function returns a file descriptor greater
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400776or equal to 0 on success and -1 on error.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500777
778ERRORS
779--------------------------------------------------------------------------------------------
780
781The following error values are specifically set by this RMR
782function. In some cases the error message of a system call is
783propagated up, and thus this list might be incomplete.
784
785
786EINVAL
787
788 The use of this function is invalid in this environment.
789
790
791EXAMPLE
792--------------------------------------------------------------------------------------------
793
794The following short code bit illustrates the use of this
795function. Error checking has been omitted for clarity.
796
797
798::
799
800 #include <stdio.h>
801 #include <stdlib.h>
802 #include <sys/epoll.h>
803 #include <rmr/rmr.h>
804 int main() {
805 int rcv_fd; // pollable fd
806 void* mrc; //msg router context
807 struct epoll_event events[10]; // support 10 events to poll
808 struct epoll_event epe; // event definition for event to listen to
809 int ep_fd = -1;
810 rmr_mbuf_t* msg = NULL;
811 int nready;
812 int i;
E. Scott Daniels392168d2019-11-06 15:12:38 -0500813 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
814 rcv_fd = rmr_get_rcvfd( mrc );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400815 ep_fd = epoll_create1( 0 ); // initialise epoll environment
E. Scott Daniels392168d2019-11-06 15:12:38 -0500816 epe.events = EPOLLIN;
817 epe.data.fd = rcv_fd;
818 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
E. Scott Daniels392168d2019-11-06 15:12:38 -0500819 while( 1 ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -0400820 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
821 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
822 if( events[i].data.fd == rcv_fd ) { // RMR has something
E. Scott Daniels392168d2019-11-06 15:12:38 -0500823 msg = rmr_rcv_msg( mrc, msg );
824 if( msg ) {
825 // do something with msg
826 }
827 }
E. Scott Daniels392168d2019-11-06 15:12:38 -0500828 // check for other ready fds....
829 }
830 }
831 }
832
833
834
835SEE ALSO
836--------------------------------------------------------------------------------------------
837
838rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
839rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
840rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
841rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
842rmr_ring_free(3)
843
844
845NAME
846--------------------------------------------------------------------------------------------
847
848rmr_get_src
849
850SYNOPSIS
851--------------------------------------------------------------------------------------------
852
853
854::
855
856 #include <rmr/rmr.h>
857 unsigned char* rmr_get_src( rmr_mbuf_t* mbuf, unsigned char* dest )
858
859
860
861DESCRIPTION
862--------------------------------------------------------------------------------------------
863
864The rmr_get_src function will copy the *source* information
865from the message to a buffer (dest) supplied by the user. In
866an RMr message, the source is the sender's information that
867is used for return to sender function calls, and is generally
868the hostname and port in the form *name*. The source might be
869an IP address port combination; the data is populated by the
870sending process and the only requirement is that it be
871capable of being used to start a TCP session with the sender.
872
873The maximum size allowed by RMr is 64 bytes (including the
874nil string terminator), so the user must ensure that the
875destination buffer given is at least 64 bytes.
876
877RETURN VALUE
878--------------------------------------------------------------------------------------------
879
880On success, a pointer to the destination buffer is given as a
881convenience to the user programme. On failure, a nil pointer
882is returned and the value of errno is set.
883
884ERRORS
885--------------------------------------------------------------------------------------------
886
887If an error occurs, the value of the global variable errno
888will be set to one of the following with the indicated
889meaning.
890
891
892
893EINVAL
894
895 The message, or an internal portion of the message, was
896 corrupted or the pointer was invalid.
897
898
899SEE ALSO
900--------------------------------------------------------------------------------------------
901
902rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
903rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
904rmr_get_srcip(3), rmr_payload_size(3), rmr_send_msg(3),
905rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
906rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
907rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
908rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
909
910
911NAME
912--------------------------------------------------------------------------------------------
913
914rmr_get_srcip
915
916SYNOPSIS
917--------------------------------------------------------------------------------------------
918
919
920::
921
922 #include <rmr/rmr.h>
923 unsigned char* rmr_get_srcip( rmr_mbuf_t* mbuf, unsigned char* dest )
924
925
926
927DESCRIPTION
928--------------------------------------------------------------------------------------------
929
930The rmr_get_srcip function will copy the *source IP address*
931from the message to a buffer (dest) supplied by the user. In
932an RMr message, the source IP address is the sender's
933information that is used for return to sender function calls;
934this function makes it available to the user application. The
935address is maintained as IP:port where *IP* could be either
936an IPv6 or IPv4 address depending on what was provided by the
937sending application.
938
939The maximum size allowed by RMr is 64 bytes (including the
940nil string terminator), so the user must ensure that the
941destination buffer given is at least 64 bytes. The user
942application should use the RMr constant RMR_MAX_SRC to ensure
943that the buffer supplied is large enough, and to protect
944against future RMr enhancements which might increase the
945address buffer size requirement.
946
947RETURN VALUE
948--------------------------------------------------------------------------------------------
949
950On success, a pointer to the destination buffer is given as a
951convenience to the user programme. On failure, a nil pointer
952is returned and the value of errno is set.
953
954ERRORS
955--------------------------------------------------------------------------------------------
956
957If an error occurs, the value of the global variable errno
958will be set to one of the following with the indicated
959meaning.
960
961
962
963EINVAL
964
965 The message, or an internal portion of the message, was
966 corrupted or the pointer was invalid.
967
968
969SEE ALSO
970--------------------------------------------------------------------------------------------
971
972rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
973rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
974rmr_get_src(3), rmr_payload_size(3), rmr_send_msg(3),
975rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
976rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
977rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
978rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
979
980
981NAME
982--------------------------------------------------------------------------------------------
983
984rmr_get_trace
985
986SYNOPSIS
987--------------------------------------------------------------------------------------------
988
989
990::
991
992 #include <rmr/rmr.h>
993 int rmr_get_trace( rmr_mbuf_t* mbuf, unsigned char* dest, int size )
994
995
996
997DESCRIPTION
998--------------------------------------------------------------------------------------------
999
1000The rmr_get_trace function will copy the trace information
1001from the message into the user's allocated memory referenced
1002by dest. The size parameter is assumed to be the maximum
1003number of bytes which can be copied (size of the destination
1004buffer).
1005
1006RETURN VALUE
1007--------------------------------------------------------------------------------------------
1008
1009On success, the number of bytes actually copied is returned.
1010If the return value is 0, no bytes copied, then the reason
1011could be that the message pointer was nil, or the size
1012parameter was <= 0.
1013
1014SEE ALSO
1015--------------------------------------------------------------------------------------------
1016
1017rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
1018rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
1019rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
1020rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
1021rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1022rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1023rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1024rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
1025rmr_set_trace(3), rmr_trace_ref(3)
1026
1027
1028NAME
1029--------------------------------------------------------------------------------------------
1030
1031rmr_get_trlen
1032
1033SYNOPSIS
1034--------------------------------------------------------------------------------------------
1035
1036
1037::
1038
1039 #include <rmr/rmr.h>
1040 int rmr_get_trlen( rmr_mbuf_t* msg );
1041
1042
1043
1044DESCRIPTION
1045--------------------------------------------------------------------------------------------
1046
1047Given a message buffer, this function returns the amount of
1048space (bytes) that have been allocated for trace data. If no
1049trace data has been allocated, then 0 is returned.
1050
1051RETURN VALUE
1052--------------------------------------------------------------------------------------------
1053
1054The number of bytes allocated for trace information in the
1055given message.
1056
1057ERRORS
1058--------------------------------------------------------------------------------------------
1059
1060
1061
1062INVAL
1063
1064 Parameter(s) passed to the function were not valid.
1065
1066
1067SEE ALSO
1068--------------------------------------------------------------------------------------------
1069
1070rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1071rmr_get_trace(3), rmr_init(3), rmr_init_trace(3),
1072rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
1073rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1074rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
1075rmr_set_trace(3), rmr_tralloc_msg(3)
1076
1077
1078NAME
1079--------------------------------------------------------------------------------------------
1080
1081rmr_get_xact
1082
1083SYNOPSIS
1084--------------------------------------------------------------------------------------------
1085
1086
1087::
1088
1089 #include <rmr/rmr.h>
1090 char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest )
1091
1092
1093
1094DESCRIPTION
1095--------------------------------------------------------------------------------------------
1096
1097The rmr_get_xact function will copy the transaction field
1098from the message into the *dest* buffer provided by the user.
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001099The buffer referenced by *dest* is assumed to be at least
1100RMR_MAX_XID bytes in length. If *dest* is NULL, then a buffer
1101is allocated (the calling application is expected to free
1102when the buffer is no longer needed).
E. Scott Daniels392168d2019-11-06 15:12:38 -05001103
1104RETURN VALUE
1105--------------------------------------------------------------------------------------------
1106
1107On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001108*dest* was supplied, then this is just a pointer to the
1109caller's buffer. If *dest* was NULL, this is a pointer to the
1110allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -05001111returned and errno is set as described below.
1112
1113ERRORS
1114--------------------------------------------------------------------------------------------
1115
1116If an error occurs, the value of the global variable errno
1117will be set to one of the following with the indicated
1118meaning.
1119
1120
1121
1122EINVAL
1123
1124 The message, or an internal portion of the message, was
1125 corrupted or the pointer was invalid.
1126
1127
1128ENOMEM
1129
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001130 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -05001131 possible to allocate a buffer using malloc().
1132
1133
1134SEE ALSO
1135--------------------------------------------------------------------------------------------
1136
1137rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
1138rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
1139rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
1140rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1141rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1142rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1143rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
1144
1145
1146NAME
1147--------------------------------------------------------------------------------------------
1148
1149rmr_init
1150
1151SYNOPSIS
1152--------------------------------------------------------------------------------------------
1153
1154
1155::
1156
1157 #include <rmr/rmr.h>
1158 void* rmr_init( char* proto_port, int max_msg_size, int flags );
1159
1160
1161
1162DESCRIPTION
1163--------------------------------------------------------------------------------------------
1164
1165The rmr_init function prepares the environment for sending
1166and receiving messages. It does so by establishing a worker
1167thread (pthread) which subscribes to a route table generator
1168which provides the necessary routing information for the RMR
1169library to send messages.
1170
1171*Port* is used to listen for connection requests from other
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001172RMR based applications. The *max_msg_size* parameter is used
1173to allocate receive buffers and is the maximum message size
1174which the application expects to receive. This value is the
1175sum of **both** the maximum payload size **and** the maximum
1176trace data size. This value is also used as the default
1177message size when allocating message buffers. Messages
1178arriving which are longer than the given maximum will be
1179dropped without notification to the application. A warning is
1180written to standard error for the first message which is too
1181large on each connection.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001182
1183*Flags* allows for selection of some RMr options at the time
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001184of initialisation. These are set by ORing RMRFL constants
E. Scott Daniels392168d2019-11-06 15:12:38 -05001185from the RMr header file. Currently the following flags are
1186supported:
1187
1188
1189
1190RMRFL_NONE
1191
1192 No flags are set.
1193
1194
1195RMRFL_NOTHREAD
1196
1197 The route table collector thread is not to be started.
1198 This should only be used by the route table generator
1199 application if it is based on RMr.
1200
1201
1202RMRFL_MTCALL
1203
1204 Enable multi-threaded call support.
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001205
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001206
1207RMRFL_NOLOCK
1208
1209 Some underlying transport providers (e.g. SI95) enable
1210 locking to be turned off if the user application is single
1211 threaded, or otherwise can guarantee that RMR functions
1212 will not be invoked concurrently from different threads.
1213 Turning off locking can help make message receipt more
1214 efficient. If this flag is set when the underlying
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001215 transport does not support disabling locks, it will be
1216 ignored.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001217
1218
1219Multi-threaded Calling
1220~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1221
1222The support for an application to issue a *blocking call* by
1223the rmr_call() function was limited such that only user
1224applications which were operating in a single thread could
1225safely use the function. Further, timeouts were message count
1226based and not time unit based. Multi-threaded call support
1227adds the ability for a user application with multiple threads
E. Scott Danielsa1575da2020-01-24 16:00:11 -05001228to invoke a blocking call function with the guarantee that
E. Scott Daniels392168d2019-11-06 15:12:38 -05001229the correct response message is delivered to the thread. The
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001230additional support is implemented with the *rmr_mt_call()*
1231and *rmr_mt_rcv()* function calls.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001232
1233Multi-threaded call support requires the user application to
1234specifically enable it when RMr is initialised. This is
1235necessary because a second, dedicated, receiver thread must
1236be started, and requires all messages to be examined and
1237queued by this thread. The additional overhead is minimal,
1238queuing information is all in the RMr message header, but as
1239an additional process is necessary the user application must
1240"opt in" to this approach.
1241
1242
1243ENVIRONMENT
1244--------------------------------------------------------------------------------------------
1245
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001246As a part of the initialisation process rmr_init reads
1247environment variables to configure itself. The following
1248variables are used if found.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001249
1250
1251
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001252RMR_ASYNC_CONN
E. Scott Daniels392168d2019-11-06 15:12:38 -05001253
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001254 Allows the async connection mode to be turned off (by
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001255 setting the value to 0). When set to 1, or missing from
1256 the environment, RMR will invoke the connection interface
1257 in the transport mechanism using the non-blocking (async)
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001258 mode. This will likely result in many "soft failures"
1259 (retry) until the connection is established, but allows
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001260 the application to continue unimpeded should the
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001261 connection be slow to set up.
1262
1263
1264RMR_BIND_IF
1265
1266 This provides the interface that RMR will bind listen
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001267 ports to, allowing for a single interface to be used
1268 rather than listening across all interfaces. This should
1269 be the IP address assigned to the interface that RMR
1270 should listen on, and if not defined RMR will listen on
1271 all interfaces.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001272
1273
1274RMR_CTL_PORT
1275
1276 This variable defines the port that RMR should open for
1277 communications with Route Manager, and other RMR control
1278 applications. If not defined, the port 4561 is assumed.
1279
1280 Previously, the RMR_RTG_SVC (route table generator service
1281 port) was used to define this port. However, a future
1282 version of Route Manager will require RMR to connect and
1283 request tables, thus that variable is now used to supply
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001284 the Route Manager's well-known address and port.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001285
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001286 To maintain backwards compatibility with the older Route
1287 Manager versions, the presence of this variable in the
1288 environment will shift RMR's behaviour with respect to the
1289 default value used when RMR_RTG_SVC is **not** defined.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001290
1291 When RMR_CTL_PORT is **defined:** RMR assumes that Route
1292 Manager requires RMR to connect and request table updates
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001293 is made, and the default well-known address for Route
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001294 manager is used (routemgr:4561).
1295
1296 When RMR_CTL_PORT is **undefined:** RMR assumes that Route
1297 Manager will connect and push table updates, thus the
1298 default listen port (4561) is used.
1299
1300 To avoid any possible misinterpretation and/or incorrect
1301 assumptions on the part of RMR, it is recommended that
1302 both the RMR_CTL_PORT and RMR_RTG_SVC be defined. In the
1303 case where both variables are defined, RMR will behave
1304 exactly as is communicated with the variable's values.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001305
1306
1307RMR_RTG_SVC
1308
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001309 The value of this variable depends on the Route Manager in
1310 use.
1311
1312 When the Route Manager is expecting to connect to an xAPP
1313 and push route tables, this variable must indicate the
1314 port which RMR should use to listen for these connections.
1315
1316 When the Route Manager is expecting RMR to connect and
1317 request a table update during initialisation, the variable
1318 should be the host of the Route Manager process.
1319
1320 The RMR_CTL_PORT variable (added with the support of
1321 sending table update requests to Route manager), controls
1322 the behaviour if this variable is not set. See the
1323 description of that variable for details.
1324
1325
1326RMR_HR_LOG
1327
1328 By default RMR writes messages to standard error
1329 (incorrectly referred to as log messages) in human
1330 readable format. If this environment variable is set to 0,
1331 the format of standard error messages might be written in
1332 some format not easily read by humans. If missing, a value
1333 of 1 is assumed.
1334
1335
1336RMR_LOG_VLEVEL
1337
1338 This is a numeric value which corresponds to the verbosity
1339 level used to limit messages written to standard error.
1340 The lower the number the less chatty RMR functions are
1341 during execution. The following is the current
1342 relationship between the value set on this variable and
1343 the messages written:
1344
1345
13460
1347
1348 Off; no messages of any sort are written.
1349
1350
13511
1352
1353 Only critical messages are written (default if this
1354 variable does not exist)
1355
1356
13572
1358
1359 Errors and all messages written with a lower value.
1360
1361
13623
1363
1364 Warnings and all messages written with a lower value.
1365
1366
13674
1368
1369 Informational and all messages written with a lower
1370 value.
1371
1372
13735
1374
1375 Debugging mode -- all messages written, however this
1376 requires RMR to have been compiled with debugging
1377 support enabled.
1378
1379
1380
1381RMR_RTG_ISRAW
1382
1383 **Deprecated.** Should be set to 1 if the route table
1384 generator is sending "plain" messages (not using RMR to
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001385 send messages), 0 if the RTG is using RMR to send. The
1386 default is 1 as we don't expect the RTG to use RMR.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001387
1388 This variable is only recognised when using the NNG
1389 transport library as it is not possible to support NNG
1390 "raw" communications with other transport libraries. It is
1391 also necessary to match the value of this variable with
1392 the capabilities of the Route Manager; at some point in
1393 the future RMR will assume that all Route Manager messages
1394 will arrive via an RMR connection and will ignore this
1395 variable.
1396
1397RMR_SEED_RT
1398
1399 This is used to supply a static route table which can be
1400 used for debugging, testing, or if no route table
1401 generator process is being used to supply the route table.
1402 If not defined, no static table is used and RMR will not
1403 report *ready* until a table is received. The static route
1404 table may contain both the route table (between newrt
1405 start and end records), and the MEID map (between meid_map
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001406 start and end records).
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05001407
1408RMR_SRC_ID
1409
1410 This is either the name or IP address which is placed into
1411 outbound messages as the message source. This will used
1412 when an RMR based application uses the rmr_rts_msg()
1413 function to return a response to the sender. If not
1414 supplied RMR will use the hostname which in some container
1415 environments might not be routable.
1416
1417 The value of this variable is also used for Route Manager
1418 messages which are sent via an RMR connection.
1419
1420RMR_VCTL_FILE
1421
1422 This supplies the name of a verbosity control file. The
1423 core RMR functions do not produce messages unless there is
1424 a critical failure. However, the route table collection
1425 thread, not a part of the main message processing
1426 component, can write additional messages to standard
1427 error. If this variable is set, RMR will extract the
1428 verbosity level for these messages (0 is silent) from the
1429 first line of the file. Changes to the file are detected
1430 and thus the level can be changed dynamically, however RMR
1431 will only suss out this variable during initialisation, so
1432 it is impossible to enable verbosity after startup.
1433
1434RMR_WARNINGS
1435
1436 If set to 1, RMR will write some warnings which are
1437 non-performance impacting. If the variable is not defined,
1438 or set to 0, RMR will not write these additional warnings.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001439
1440
1441RETURN VALUE
1442--------------------------------------------------------------------------------------------
1443
1444The rmr_init function returns a void pointer (a contex if you
1445will) that is passed as the first parameter to nearly all
1446other RMR functions. If rmr_init is unable to properly
1447initialise the environment, NULL is returned and errno is set
1448to an appropriate value.
1449
1450ERRORS
1451--------------------------------------------------------------------------------------------
1452
1453The following error values are specifically set by this RMR
1454function. In some cases the error message of a system call is
1455propagated up, and thus this list might be incomplete.
1456
1457
1458ENOMEM
1459
1460 Unable to allocate memory.
1461
1462
1463EXAMPLE
1464--------------------------------------------------------------------------------------------
1465
1466
1467::
1468
1469 void* uh;
1470 rmr_mbuf* buf = NULL;
1471 uh = rmr_init( "43086", 4096, 0 );
1472 buf = rmr_rcv_msg( uh, buf );
1473
1474
1475
1476SEE ALSO
1477--------------------------------------------------------------------------------------------
1478
1479rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1480rmr_get_rcvfd(3), rmr_mt_call(3), rmr_mt_rcv(3),
1481rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
1482rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
1483rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
1484rmr_ring_free(3)
1485
1486
1487NAME
1488--------------------------------------------------------------------------------------------
1489
1490rmr_init_trace
1491
1492SYNOPSIS
1493--------------------------------------------------------------------------------------------
1494
1495
1496::
1497
1498 #include <rmr/rmr.h>
1499 void* rmr_init_trace( void* ctx )
1500
1501
1502
1503DESCRIPTION
1504--------------------------------------------------------------------------------------------
1505
1506The rmr_init_trace function establishes the default trace
1507space placed in each message buffer allocated with
1508rmr_alloc_msg(). If this function is never called, then no
1509trace space is allocated by default into any message buffer.
1510
1511Trace space allows the user application to pass some trace
1512token, or other data with the message, but outside of the
1513payload. Trace data may be added to any message with
1514rmr_set_trace(), and may be extracted from a message with
1515rmr_get_trace(). The number of bytes that a message contains
1516for/with trace data can be determined by invoking
1517rmr_get_trlen().
1518
1519This function may be safely called at any time during the
1520life of the user programme to (re)set the default trace space
1521reserved. If the user programme needs to allocate a message
1522with trace space of a different size than is allocated by
1523default, without fear of extra overhead of reallocating a
1524message later, the rmr_tralloc_msg() function can be used.
1525
1526RETURN VALUE
1527--------------------------------------------------------------------------------------------
1528
1529A value of 1 is returned on success, and 0 on failure. A
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001530failure indicates that the RMr context (a void pointer passed
1531to this function was not valid.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001532
1533SEE ALSO
1534--------------------------------------------------------------------------------------------
1535
1536rmr_alloc_msg(3), rmr_tr_alloc_msg(3), rmr_call(3),
1537rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_trace(3),
1538rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
1539rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1540rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1541rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
1542
1543
1544NAME
1545--------------------------------------------------------------------------------------------
1546
1547rmr_mt_call
1548
1549SYNOPSIS
1550--------------------------------------------------------------------------------------------
1551
1552
1553::
1554
1555 #include <rmr/rmr.h>
1556 extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* msg, int id, int timeout );
1557
1558
1559
1560DESCRIPTION
1561--------------------------------------------------------------------------------------------
1562
1563The rmr_mt_call function sends the user application message
1564to a remote endpoint, and waits for a corresponding response
1565message before returning control to the user application. The
1566user application supplies a completed message buffer, as it
1567would for a rmr_send_msg call, but unlike with a send, the
1568buffer returned will have the response from the application
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001569that received the message. The thread invoking the
1570*rmr_mt_call()* will block until a message arrives or until
E. Scott Daniels392168d2019-11-06 15:12:38 -05001571*timeout* milliseconds has passed; which ever comes first.
1572Using a timeout value of zero (0) will cause the thread to
1573block without a timeout.
1574
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001575The *id* supplied as the third parameter is an integer in the
1576range of 2 through 255 inclusive. This is a caller defined
1577"thread number" and is used to match the response message
1578with the correct user application thread. If the ID value is
1579not in the proper range, the attempt to make the call will
1580fail.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001581
1582Messages which are received while waiting for the response
1583are queued on a *normal* receive queue and will be delivered
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001584to the user application with the next invocation of
1585*rmr_mt_rcv()* or *rmr_rvv_msg().* by RMR, and are returned
E. Scott Daniels392168d2019-11-06 15:12:38 -05001586to the user application when rmr_rcv_msg is invoked. These
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001587messages are returned in the order received, one per call to
E. Scott Daniels392168d2019-11-06 15:12:38 -05001588rmr_rcv_msg.
1589
E. Scott Daniels392168d2019-11-06 15:12:38 -05001590The Transaction ID
1591~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1592
1593The user application is responsible for setting the value of
1594the transaction ID field before invoking *rmr_mt_call.* The
1595transaction ID is a RMR_MAX_XID byte field that is used to
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001596match the response message when it arrives. RMR will compare
E. Scott Daniels392168d2019-11-06 15:12:38 -05001597**all** of the bytes in the field, so the caller must ensure
1598that they are set correctly to avoid missing the response
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001599message. The application which returns the response message
E. Scott Daniels392168d2019-11-06 15:12:38 -05001600is also expected to ensure that the return buffer has the
1601matching transaction ID. This can be done transparently if
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001602the application uses the *rmr_rts_msg()* function and does
E. Scott Daniels392168d2019-11-06 15:12:38 -05001603not adjust the transaction ID.
1604
1605Retries
1606~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1607
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001608The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05001609until one of three conditions occurs:
1610
1611
1612
16131.
1614
1615 The message is sent without error
1616
1617
16182.
1619
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001620 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05001621
1622
16233.
1624
1625 The maximum number of retry loops has been attempted
1626
1627
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001628A retry loop consists of approximately 1000 send attempts
1629**without** any intervening calls to *sleep()* or *usleep().*
1630The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050016311000 send attempts is performed before returning to the user
1632application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001633initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05001634allowing the user application to completely disable retires
1635(set to 0), or to increase the number of retry loops.
1636
1637Transport Level Blocking
1638~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1639
1640The underlying transport mechanism used to send messages is
1641configured in *non-blocking* mode. This means that if a
1642message cannot be sent immediately the transport mechanism
1643will **not** pause with the assumption that the inability to
1644send will clear quickly (within a few milliseconds). This
1645means that when the retry loop is completely disabled (set to
16460), that the failure to accept a message for sending by the
1647underlying mechanisms (software or hardware) will be reported
1648immediately to the user application.
1649
1650It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001651mechanism being used, it is extremely likely that retry
1652conditions will happen during normal operations. These are
1653completely out of RMR's control, and there is nothing that
1654RMR can do to avoid or mitigate these other than by allowing
1655RMR to retry the send operation, and even then it is possible
1656(e.g., during connection reattempts), that a single retry
1657loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001658
1659RETURN VALUE
1660--------------------------------------------------------------------------------------------
1661
1662The rmr_mt_call function returns a pointer to a message
1663buffer with the state set to reflect the overall state of
1664call processing. If the state is RMR_OK then the buffer
1665contains the response message; otherwise the state indicates
1666the error encountered while attempting to send the message.
1667
1668If no response message is received when the timeout period
1669has expired, a nil pointer will be returned (NULL).
1670
1671ERRORS
1672--------------------------------------------------------------------------------------------
1673
1674These values are reflected in the state field of the returned
1675message.
1676
1677
1678
1679RMR_OK
1680
1681 The call was successful and the message buffer references
1682 the response message.
1683
1684
1685RMR_ERR_BADARG
1686
1687 An argument passed to the function was invalid.
1688
1689
1690RMR_ERR_CALLFAILED
1691
1692 The call failed and the value of *errno,* as described
1693 below, should be checked for the specific reason.
1694
1695
1696RMR_ERR_NOENDPT
1697
1698 An endpoint associated with the message type could not be
1699 found in the route table.
1700
1701
1702RMR_ERR_RETRY
1703
1704 The underlying transport mechanism was unable to accept
1705 the message for sending. The user application can retry
1706 the call operation if appropriate to do so.
1707
1708
1709The global "variable" *errno* will be set to one of the
1710following values if the overall call processing was not
1711successful.
1712
1713
1714
1715ETIMEDOUT
1716
1717 Too many messages were queued before receiving the
1718 expected response
1719
1720
1721ENOBUFS
1722
1723 The queued message ring is full, messages were dropped
1724
1725
1726EINVAL
1727
1728 A parameter was not valid
1729
1730
1731EAGAIN
1732
1733 The underlying message system wsa interrupted or the
1734 device was busy; the message was **not** sent, and user
1735 application should call this function with the message
1736 again.
1737
1738
1739EXAMPLE
1740--------------------------------------------------------------------------------------------
1741
1742The following code bit shows one way of using the rmr_mt_call
1743function, and illustrates how the transaction ID must be set.
1744
1745
1746::
1747
1748 int retries_left = 5; // max retries on dev not available
1749 static rmr_mbuf_t* mbuf = NULL; // response msg
1750 msg_t* pm; // private message (payload)
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001751 // get a send buffer and reference the payload
E. Scott Daniels392168d2019-11-06 15:12:38 -05001752 mbuf = rmr_alloc_msg( mr, RMR_MAX_RCV_BYTES );
1753 pm = (msg_t*) mbuf->payload;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001754 // generate an xaction ID and fill in payload with data and msg type
E. Scott Daniels392168d2019-11-06 15:12:38 -05001755 rmr_bytes2xact( mbuf, xid, RMR_MAX_XID );
1756 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
1757 mbuf->mtype = MT_USR_RESP;
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001758 msg = rmr_mt_call( mr, msg, my_id, 100 ); // wait up to 100ms
E. Scott Daniels392168d2019-11-06 15:12:38 -05001759 if( ! msg ) { // probably a timeout and no msg received
1760 return NULL; // let errno trickle up
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001761 }
E. Scott Daniels392168d2019-11-06 15:12:38 -05001762 if( mbuf->state != RMR_OK ) {
1763 while( retries_left-- > 0 && // loop as long as eagain
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001764 mbuf->state == RMR_ERR_RETRY &&
1765 (msg = rmr_mt_call( mr, msg )) != NULL &&
E. Scott Daniels392168d2019-11-06 15:12:38 -05001766 mbuf->state != RMR_OK ) {
1767 usleep( retry_delay );
1768 }
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001769
E. Scott Daniels392168d2019-11-06 15:12:38 -05001770 if( mbuf == NULL || mbuf->state != RMR_OK ) {
1771 rmr_free_msg( mbuf ); // safe if nil
1772 return NULL;
1773 }
1774 }
1775 // do something with mbuf
1776
1777
1778
1779SEE ALSO
1780--------------------------------------------------------------------------------------------
1781
1782rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
1783rmr_mt_rcv(3), rmr_payload_size(3), rmr_send_msg(3),
1784rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1785rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1786rmr_set_stimeout(3), rmr_tokenise(3), rmr_mk_ring(3),
1787rmr_ring_free(3)
1788
1789
1790NAME
1791--------------------------------------------------------------------------------------------
1792
1793rmr_mt_rcv
1794
1795SYNOPSIS
1796--------------------------------------------------------------------------------------------
1797
1798
1799::
1800
1801 #include <rmr/rmr.h>
1802 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
1803
1804
1805
1806DESCRIPTION
1807--------------------------------------------------------------------------------------------
1808
1809The rmr_mt_rcv function blocks until a message is received,
1810or the timeout period (milliseconds) has passed. The result
1811is an RMr message buffer which references a received message.
1812In the case of a timeout the state will be reflected in an
1813"empty buffer" (if old_msg was not nil, or simply with the
1814return of a nil pointer. If a timeout value of zero (0) is
1815given, then the function will block until the next message
1816received.
1817
1818The *vctx* pointer is the pointer returned by the rmr_init
1819function. *Old_msg* is a pointer to a previously used message
1820buffer or NULL. The ability to reuse message buffers helps to
1821avoid alloc/free cycles in the user application. When no
1822buffer is available to supply, the receive function will
1823allocate one.
1824
1825The *old_msg* parameter allows the user to pass a previously
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001826generated RMR message back to RMR for reuse. Optionally, the
E. Scott Daniels392168d2019-11-06 15:12:38 -05001827user application may pass a nil pointer if no reusable
1828message is available. When a timeout occurs, and old_msg was
1829not nil, the state will be returned by returning a pointer to
1830the old message with the state set.
1831
1832It is possible to use the *rmr_rcv_msg()* function instead of
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001833this function. Doing so might be advantageous if the user
E. Scott Daniels392168d2019-11-06 15:12:38 -05001834programme does not always start the multi-threaded mode and
1835the use of *rmr_rcv_msg()* would make the flow of the code
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04001836more simple. The advantages of using this function are the
E. Scott Daniels392168d2019-11-06 15:12:38 -05001837ability to set a timeout without using epoll, and a small
1838performance gain (if multi-threaded mode is enabled, and the
1839*rmr_rcv_msg()* function is used, it simply invokes this
1840function without a timeout value, thus there is the small
1841cost of a second call that results). Similarly, the
1842*rmr_torcv_msg()* call can be used when in multi-threaded
1843mode with the same "pass through" overhead to using this
1844function directly.
1845
E. Scott Daniels392168d2019-11-06 15:12:38 -05001846RETURN VALUE
1847--------------------------------------------------------------------------------------------
1848
1849When a message is received before the timeout period expires,
1850a pointer to the RMr message buffer which describes the
1851message is returned. This will, with a high probability, be a
1852different message buffer than *old_msg;* the user application
1853should not continue to use *old_msg* after it is passed to
1854this function.
1855
1856In the event of a timeout the return value will be the old
1857msg with the state set, or a nil pointer if no old message
1858was provided.
1859
1860ERRORS
1861--------------------------------------------------------------------------------------------
1862
1863The *state* field in the message buffer will be set to one of
1864the following values:
1865
1866
1867
1868RMR_OK
1869
1870 The message was received without error.
1871
1872
1873RMR_ERR_BADARG
1874
1875 A parameter passed to the function was not valid (e.g. a
1876 nil pointer). indicate either RMR_OK or RMR_ERR_EMPTY if
1877 an empty message was received.
1878
1879
1880RMR_ERR_EMPTY
1881
1882 The message received had no associated data. The length of
1883 the message will be 0.
1884
1885
1886RMR_ERR_NOTSUPP
1887
1888 The multi-threaded option was not enabled when RMr was
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001889 initialised. See the man page for *rmr_init()* for
E. Scott Daniels392168d2019-11-06 15:12:38 -05001890 details.
1891
1892
1893RMR_ERR_RCVFAILED
1894
1895 A hard error occurred preventing the receive from
1896 completing.
1897
1898When a nil pointer is returned, or any other state value was
1899set in the message buffer, errno will be set to one of the
1900following:
1901
1902
1903
1904INVAL
1905
1906 Parameter(s) passed to the function were not valid.
1907
1908
1909EBADF
1910
1911 The underlying message transport is unable to process the
1912 request.
1913
1914
1915ENOTSUP
1916
1917 The underlying message transport is unable to process the
1918 request.
1919
1920
1921EFSM
1922
1923 The underlying message transport is unable to process the
1924 request.
1925
1926
1927EAGAIN
1928
1929 The underlying message transport is unable to process the
1930 request.
1931
1932
1933EINTR
1934
1935 The underlying message transport is unable to process the
1936 request.
1937
1938
1939ETIMEDOUT
1940
1941 The underlying message transport is unable to process the
1942 request.
1943
1944
1945ETERM
1946
1947 The underlying message transport is unable to process the
1948 request.
1949
1950
1951EXAMPLE
1952--------------------------------------------------------------------------------------------
1953
1954
1955
1956::
1957
1958 rmr_mbuf_t* mbuf = NULL; // received msg
1959 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
1960 if( msg != NULL ) {
1961 switch( msg->state ) {
1962 case RMR_OK:
1963 printf( "got a good message\\n" );
1964 break;
1965 case RMR_ERR_EMPTY:
1966 printf( "received timed out\\n" );
1967 break;
1968 default:
1969 printf( "receive error: %d\\n", mbuf->state );
1970 break;
1971 }
1972 } else {
1973 printf( "receive timeout (nil)\\n" );
1974 }
1975
1976
1977
1978SEE ALSO
1979--------------------------------------------------------------------------------------------
1980
1981rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1982rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
1983rmr_mt_call(3), rmr_payload_size(3), rmr_send_msg(3),
1984rmr_torcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1985rmr_ready(3), rmr_ring_free(3), rmr_torcv_msg(3)
1986
1987
1988NAME
1989--------------------------------------------------------------------------------------------
1990
1991rmr_payload_size
1992
1993SYNOPSIS
1994--------------------------------------------------------------------------------------------
1995
1996
1997::
1998
1999 #include <rmr/rmr.h>
2000 int rmr_payload_size( rmr_mbuf_t* msg );
2001
2002
2003
2004DESCRIPTION
2005--------------------------------------------------------------------------------------------
2006
2007Given a message buffer, this function returns the amount of
2008space (bytes) available for the user application to consume
2009in the message payload. This is different than the message
2010length available as a field in the message buffer.
2011
2012RETURN VALUE
2013--------------------------------------------------------------------------------------------
2014
2015The number of bytes available in the payload.
2016
2017ERRORS
2018--------------------------------------------------------------------------------------------
2019
2020
2021
2022INVAL
2023
2024 Parameter(s) passed to the function were not valid.
2025
2026
2027SEE ALSO
2028--------------------------------------------------------------------------------------------
2029
2030rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2031rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2032rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
2033rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
2034
2035
2036NAME
2037--------------------------------------------------------------------------------------------
2038
2039rmr_rcv_msg
2040
2041SYNOPSIS
2042--------------------------------------------------------------------------------------------
2043
2044
2045::
2046
2047 #include <rmr/rmr.h>
2048 rmr_mbuf_t* rmr_rcv_msg( void* vctx, rmr_mbuf_t* old_msg );
2049
2050
2051
2052DESCRIPTION
2053--------------------------------------------------------------------------------------------
2054
2055The rmr_rcv_msg function blocks until a message is received,
2056returning the message to the caller via a pointer to a
2057rmr_mbuf_t structure type. If messages were queued while
2058waiting for the response to a previous invocation of
2059rmr_call, the oldest message is removed from the queue and
2060returned without delay.
2061
2062The *vctx* pointer is the pointer returned by the rmr_init
2063function. *Old_msg* is a pointer to a previously used message
2064buffer or NULL. The ability to reuse message buffers helps to
2065avoid alloc/free cycles in the user application. When no
2066buffer is available to supply, the receive function will
2067allocate one.
2068
2069RETURN VALUE
2070--------------------------------------------------------------------------------------------
2071
2072The function returns a pointer to the rmr_mbuf_t structure
2073which references the message information (state, length,
2074payload), or a NULL pointer in the case of an extreme error.
2075
2076ERRORS
2077--------------------------------------------------------------------------------------------
2078
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002079The *state* field in the message buffer will indicate RMR_OK
2080when the message receive process was successful and the
2081message can be used by the caller. Depending on the
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002082underlying transport mechanism, one of the following RMR
2083error stats may be returned:
2084
2085
2086
2087RMR_ERR_EMPTY
2088
2089 The message received had no payload, or was completely
2090 empty.
2091
2092
2093RMR_ERR_TIMEOUT
2094
2095 For some transport mechanisms, or if reading the receive
2096 queue from multiple threads, it is possible for one thread
2097 to find no data waiting when it queries the queue. When
2098 this state is reported, the message buffer does not
2099 contain message data and the user application should
2100 reinvoke the receive function.
2101
2102
2103When an RMR error state is reported, the underlying errno
2104value might provide more information. The following is a list
2105of possible values that might accompany the states listed
2106above:
2107
2108RMR_ERR_EMPTY if an empty message was received. If a nil
2109pointer is returned, or any other state value was set in the
2110message buffer, errno will be set to one of the following:
E. Scott Daniels392168d2019-11-06 15:12:38 -05002111
2112
2113
2114INVAL
2115
2116 Parameter(s) passed to the function were not valid.
2117
2118
2119EBADF
2120
2121 The underlying message transport is unable to process the
2122 request.
2123
2124
2125ENOTSUP
2126
2127 The underlying message transport is unable to process the
2128 request.
2129
2130
2131EFSM
2132
2133 The underlying message transport is unable to process the
2134 request.
2135
2136
2137EAGAIN
2138
2139 The underlying message transport is unable to process the
2140 request.
2141
2142
2143EINTR
2144
2145 The underlying message transport is unable to process the
2146 request.
2147
2148
2149ETIMEDOUT
2150
2151 The underlying message transport is unable to process the
2152 request.
2153
2154
2155ETERM
2156
2157 The underlying message transport is unable to process the
2158 request.
2159
2160
2161EXAMPLE
2162--------------------------------------------------------------------------------------------
2163
2164
2165SEE ALSO
2166--------------------------------------------------------------------------------------------
2167
2168rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
2169rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
2170rmr_payload_size(3), rmr_send_msg(3), rmr_torcv_msg(3),
2171rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2172rmr_ring_free(3), rmr_torcv_msg(3)
2173
2174
2175NAME
2176--------------------------------------------------------------------------------------------
2177
2178rmr_ready
2179
2180SYNOPSIS
2181--------------------------------------------------------------------------------------------
2182
2183
2184::
2185
2186 #include <rmr/rmr.h>
2187 int rmr_ready( void* vctx );
2188
2189
2190
2191DESCRIPTION
2192--------------------------------------------------------------------------------------------
2193
2194The rmr_ready function checks to see if a routing table has
2195been successfully received and installed. The return value
2196indicates the state of readiness.
2197
2198RETURN VALUE
2199--------------------------------------------------------------------------------------------
2200
2201A return value of 1 (true) indicates that the routing table
2202is in place and attempts to send messages can be made. When 0
2203is returned (false) the routing table has not been received
2204and thus attempts to send messages will fail with *no
2205endpoint* errors.
2206
2207SEE ALSO
2208--------------------------------------------------------------------------------------------
2209
2210rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2211rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2212rmr_rcv_specific(3), rmr_rts_msg(3), rmr_fib(3),
2213rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
2214rmr_ring_free(3)
2215
2216
2217NAME
2218--------------------------------------------------------------------------------------------
2219
2220rmr_realloc_payload
2221
2222SYNOPSIS
2223--------------------------------------------------------------------------------------------
2224
2225
2226::
2227
2228 #include <rmr/rmr.h>
2229 extern rmr_mbuf_t* rmr_realloc_payload( rmr_mbuf_t* msg, int new_len, int copy, int clone );
2230
2231
2232
2233DESCRIPTION
2234--------------------------------------------------------------------------------------------
2235
2236The rmr_realloc_payload function will return a pointer to an
2237RMR message buffer struct (rmr_mbuf_t) which has a payload
2238large enough to accomodate *new_len* bytes. If necessary, the
2239underlying payload is reallocated, and the bytes from the
2240original payload are copied if the *copy* parameter is true
2241(1). If the message passed in has a payload large enough,
2242there is no additional memory allocation and copying.
2243
2244Cloning The Message Buffer
2245~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2246
2247This function can also be used to generate a separate copy of
2248the original message, with the desired payload size, without
2249destroying the original message buffer or the original
2250payload. A standalone copy is made only when the *clone*
2251parameter is true (1). When cloning, the payload is copied to
2252the cloned message **only** if the *copy* parameter is true.
2253
2254Message Buffer Metadata
2255~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2256
2257The metadata in the original message buffer (message type,
2258subscription ID, and payload length) will be preserved if the
2259*copy* parameter is true. When this parameter is not true
2260(0), then these values are set to the uninitialised value
2261(-1) for type and ID, and the length is set to 0.
2262
2263RETURN VALUE
2264--------------------------------------------------------------------------------------------
2265
2266The rmr_realloc_payload function returns a pointer to the
2267message buffer with the payload which is large enough to hold
2268*new_len* bytes. If the *clone* option is true, this will be
2269a pointer to the newly cloned message buffer; the original
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002270message buffer pointer may still be used to reference that
E. Scott Daniels392168d2019-11-06 15:12:38 -05002271message. It is the calling application's responsibility to
2272free the memory associateed with both messages using the
2273rmr_free_msg() function.
2274
2275When the *clone* option is not used, it is still good
2276practice by the calling application to capture and use this
2277reference as it is possible that the message buffer, and not
2278just the payload buffer, was reallocated. In the event of an
2279error, a nil pointer will be returned and the value of
2280*errno* will be set to reflect the problem.
2281
2282ERRORS
2283--------------------------------------------------------------------------------------------
2284
2285These value of *errno* will reflect the error condition if a
2286nil pointer is returned:
2287
2288
2289
2290ENOMEM
2291
2292 Memory allocation of the new payload failed.
2293
2294
2295EINVAL
2296
2297 The pointer passed in was nil, or refrenced an invalid
2298 message, or the required length was not valid.
2299
2300
2301EXAMPLE
2302--------------------------------------------------------------------------------------------
2303
2304The following code bit illustrates how this function can be
2305used to reallocate a buffer for a return to sender
2306acknowledgement message which is larger than the message
2307received.
2308
2309
2310::
2311
2312 if( rmr_payload_size( msg ) < ack_sz ) { // received message too small for ack
2313 msg = rmr_realloc_payload( msg, ack_sz, 0, 0 ); // reallocate the message with a payload big enough
2314 if( msg == NULL ) {
2315 fprintf( stderr, "[ERR] realloc returned a nil pointer: %s\\n", strerror( errno ) );
2316 } else {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002317 // populate and send ack message
2318 }
E. Scott Daniels392168d2019-11-06 15:12:38 -05002319 }
2320
2321
2322
2323SEE ALSO
2324--------------------------------------------------------------------------------------------
2325
2326rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
2327rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2328rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2329rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
2330rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
2331
2332
2333NAME
2334--------------------------------------------------------------------------------------------
2335
2336rmr_rts_msg
2337
2338SYNOPSIS
2339--------------------------------------------------------------------------------------------
2340
2341
2342::
2343
2344 #include <rmr/rmr.h>
2345 rmr_mbuf_t* rmr_rts_msg( void* vctx, rmr_mbuf_t* msg );
2346
2347
2348
2349DESCRIPTION
2350--------------------------------------------------------------------------------------------
2351
2352The rmr_rts_msg function sends a message returning it to the
2353endpoint which sent the message rather than selecting an
2354endpoint based on the message type and routing table. Other
2355than this small difference, the behaviour is exactly the same
2356as rmr_send_msg.
2357
2358Retries
2359~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2360
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002361The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05002362until one of three conditions occurs:
2363
2364
2365
23661.
2367
2368 The message is sent without error
2369
2370
23712.
2372
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002373 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002374
2375
23763.
2377
2378 The maximum number of retry loops has been attempted
2379
2380
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002381A retry loop consists of approximately 1000 send attempts
2382**without** any intervening calls to *sleep()* or *usleep().*
2383The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050023841000 send attempts is performed before returning to the user
2385application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002386initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05002387allowing the user application to completely disable retires
2388(set to 0), or to increase the number of retry loops.
2389
2390Transport Level Blocking
2391~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2392
2393The underlying transport mechanism used to send messages is
2394configured in *non-blocking* mode. This means that if a
2395message cannot be sent immediately the transport mechanism
2396will **not** pause with the assumption that the inability to
2397send will clear quickly (within a few milliseconds). This
2398means that when the retry loop is completely disabled (set to
23990), that the failure to accept a message for sending by the
2400underlying mechanisms (software or hardware) will be reported
2401immediately to the user application.
2402
2403It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002404mechanism being used, it is extremely likely that retry
2405conditions will happen during normal operations. These are
2406completely out of RMR's control, and there is nothing that
2407RMR can do to avoid or mitigate these other than by allowing
2408RMR to retry the send operation, and even then it is possible
2409(e.g., during connection reattempts), that a single retry
2410loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002411
2412PAYLOAD SIZE
2413--------------------------------------------------------------------------------------------
2414
2415When crafting a response based on a received message, the
2416user application must take care not to write more bytes to
2417the message payload than the allocated message has. In the
2418case of a received message, it is possible that the response
2419needs to be larger than the payload associated with the
2420inbound message. In order to use the return to sender
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002421function, the source information in the original message must
E. Scott Daniels392168d2019-11-06 15:12:38 -05002422be present in the response; information which cannot be added
2423to a message buffer allocated through the standard RMR
2424allocation function. To allocate a buffer with a larger
2425payload, and which retains the necessary sender data needed
2426by this function, the *rmr_realloc_payload()* function must
2427be used to extend the payload to a size suitable for the
2428response.
2429
2430RETURN VALUE
2431--------------------------------------------------------------------------------------------
2432
2433On success, a new message buffer, with an empty payload, is
2434returned for the application to use for the next send. The
2435state in this buffer will reflect the overall send operation
2436state and should be RMR_OK.
2437
2438If the state in the returned buffer is anything other than
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002439RMR_OK, the user application may need to attempt a
E. Scott Daniels392168d2019-11-06 15:12:38 -05002440retransmission of the message, or take other action depending
2441on the setting of errno as described below.
2442
2443In the event of extreme failure, a NULL pointer is returned.
2444In this case the value of errno might be of some use, for
2445documentation, but there will be little that the user
2446application can do other than to move on.
2447
2448ERRORS
2449--------------------------------------------------------------------------------------------
2450
2451The following values may be passed back in the *state* field
2452of the returned message buffer.
2453
2454
2455
2456RMR_ERR_BADARG
2457
2458 The message buffer pointer did not refer to a valid
2459 message.
2460
2461RMR_ERR_NOHDR
2462
2463 The header in the message buffer was not valid or
2464 corrupted.
2465
2466RMR_ERR_NOENDPT
2467
2468 The message type in the message buffer did not map to a
2469 known endpoint.
2470
2471RMR_ERR_SENDFAILED
2472
2473 The send failed; errno has the possible reason.
2474
2475
2476The following values may be assigned to errno on failure.
2477
2478
2479INVAL
2480
2481 Parameter(s) passed to the function were not valid, or the
2482 underlying message processing environment was unable to
2483 interpret the message.
2484
2485
2486ENOKEY
2487
2488 The header information in the message buffer was invalid.
2489
2490
2491ENXIO
2492
2493 No known endpoint for the message could be found.
2494
2495
2496EMSGSIZE
2497
2498 The underlying transport refused to accept the message
2499 because of a size value issue (message was not attempted
2500 to be sent).
2501
2502
2503EFAULT
2504
2505 The message referenced by the message buffer is corrupt
2506 (NULL pointer or bad internal length).
2507
2508
2509EBADF
2510
2511 Internal RMR error; information provided to the message
2512 transport environment was not valid.
2513
2514
2515ENOTSUP
2516
2517 Sending was not supported by the underlying message
2518 transport.
2519
2520
2521EFSM
2522
2523 The device is not in a state that can accept the message.
2524
2525
2526EAGAIN
2527
2528 The device is not able to accept a message for sending.
2529 The user application should attempt to resend.
2530
2531
2532EINTR
2533
2534 The operation was interrupted by delivery of a signal
2535 before the message was sent.
2536
2537
2538ETIMEDOUT
2539
2540 The underlying message environment timed out during the
2541 send process.
2542
2543
2544ETERM
2545
2546 The underlying message environment is in a shutdown state.
2547
2548
2549EXAMPLE
2550--------------------------------------------------------------------------------------------
2551
2552
2553SEE ALSO
2554--------------------------------------------------------------------------------------------
2555
2556rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2557rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2558rmr_rcv_specific(3), rmr_ready(3), rmr_fib(3),
2559rmr_has_str(3), rmr_set_stimeout(3), rmr_tokenise(3),
2560rmr_mk_ring(3), rmr_ring_free(3)
2561
2562
2563NAME
2564--------------------------------------------------------------------------------------------
2565
2566rmr_send_msg
2567
2568SYNOPSIS
2569--------------------------------------------------------------------------------------------
2570
2571
2572::
2573
2574 #include <rmr/rmr.h>
2575 rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
2576
2577
2578
2579DESCRIPTION
2580--------------------------------------------------------------------------------------------
2581
2582The rmr_send_msg function accepts a message buffer from the
2583user application and attempts to send it. The destination of
2584the message is selected based on the message type specified
2585in the message buffer, and the matching information in the
2586routing tables which are currently in use by the RMR library.
2587This may actually result in the sending of the message to
2588multiple destinations which could degrade expected overall
2589performance of the user application. (Limiting excessive
2590sending of messages is the responsibility of the
2591application(s) responsible for building the routing table
2592used by the RMR library, and not the responsibility of the
2593library.)
2594
2595Retries
2596~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2597
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002598The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05002599until one of three conditions occurs:
2600
2601
2602
26031.
2604
2605 The message is sent without error
2606
2607
26082.
2609
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002610 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002611
2612
26133.
2614
2615 The maximum number of retry loops has been attempted
2616
2617
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002618A retry loop consists of approximately 1000 send attempts
2619**without** any intervening calls to *sleep()* or *usleep().*
2620The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050026211000 send attempts is performed before returning to the user
2622application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002623initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05002624allowing the user application to completely disable retires
2625(set to 0), or to increase the number of retry loops.
2626
2627Transport Level Blocking
2628~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2629
2630The underlying transport mechanism used to send messages is
2631configured in *non-blocking* mode. This means that if a
2632message cannot be sent immediately the transport mechanism
2633will **not** pause with the assumption that the inability to
2634send will clear quickly (within a few milliseconds). This
2635means that when the retry loop is completely disabled (set to
26360), that the failure to accept a message for sending by the
2637underlying mechanisms (software or hardware) will be reported
2638immediately to the user application.
2639
2640It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002641mechanism being used, it is extremely likely that retry
2642conditions will happen during normal operations. These are
2643completely out of RMR's control, and there is nothing that
2644RMR can do to avoid or mitigate these other than by allowing
2645RMR to retry the send operation, and even then it is possible
2646(e.g., during connection reattempts), that a single retry
2647loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002648
2649RETURN VALUE
2650--------------------------------------------------------------------------------------------
2651
2652On success, a new message buffer, with an empty payload, is
2653returned for the application to use for the next send. The
2654state in this buffer will reflect the overall send operation
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002655state and will be RMR_OK when the send was successful.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002656
2657When the message cannot be successfully sent this function
2658will return the unsent (original) message buffer with the
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002659state set to indicate the reason for failure. The value of
2660*errno* may also be set to reflect a more detailed failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002661reason if it is known.
2662
2663In the event of extreme failure, a NULL pointer is returned.
2664In this case the value of errno might be of some use, for
2665documentation, but there will be little that the user
2666application can do other than to move on.
2667
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002668**CAUTION:** In some cases it is extremely likely that the
2669message returned by the send function does **not** reference
2670the same memory structure. Thus is important for the user
2671programme to capture the new pointer for future use or to be
2672passed to rmr_free(). If you are experiencing either double
2673free errors or segment faults in either rmr_free() or
2674rmr_send_msg(), ensure that the return value from this
2675function is being captured and used.
2676
E. Scott Daniels392168d2019-11-06 15:12:38 -05002677ERRORS
2678--------------------------------------------------------------------------------------------
2679
2680The following values may be passed back in the *state* field
2681of the returned message buffer.
2682
2683
2684
2685RMR_RETRY
2686
2687 The message could not be sent, but the underlying
2688 transport mechanism indicates that the failure is
2689 temporary. If the send operation is tried again it might
2690 be successful.
2691
2692RMR_SEND_FAILED
2693
2694 The send operation was not successful and the underlying
2695 transport mechanism indicates a permanent (hard) failure;
2696 retrying the send is not possible.
2697
2698RMR_ERR_BADARG
2699
2700 The message buffer pointer did not refer to a valid
2701 message.
2702
2703RMR_ERR_NOHDR
2704
2705 The header in the message buffer was not valid or
2706 corrupted.
2707
2708RMR_ERR_NOENDPT
2709
2710 The message type in the message buffer did not map to a
2711 known endpoint.
2712
2713
2714The following values may be assigned to errno on failure.
2715
2716
2717INVAL
2718
2719 Parameter(s) passed to the function were not valid, or the
2720 underlying message processing environment was unable to
2721 interpret the message.
2722
2723
2724ENOKEY
2725
2726 The header information in the message buffer was invalid.
2727
2728
2729ENXIO
2730
2731 No known endpoint for the message could be found.
2732
2733
2734EMSGSIZE
2735
2736 The underlying transport refused to accept the message
2737 because of a size value issue (message was not attempted
2738 to be sent).
2739
2740
2741EFAULT
2742
2743 The message referenced by the message buffer is corrupt
2744 (NULL pointer or bad internal length).
2745
2746
2747EBADF
2748
2749 Internal RMR error; information provided to the message
2750 transport environment was not valid.
2751
2752
2753ENOTSUP
2754
2755 Sending was not supported by the underlying message
2756 transport.
2757
2758
2759EFSM
2760
2761 The device is not in a state that can accept the message.
2762
2763
2764EAGAIN
2765
2766 The device is not able to accept a message for sending.
2767 The user application should attempt to resend.
2768
2769
2770EINTR
2771
2772 The operation was interrupted by delivery of a signal
2773 before the message was sent.
2774
2775
2776ETIMEDOUT
2777
2778 The underlying message environment timed out during the
2779 send process.
2780
2781
2782ETERM
2783
2784 The underlying message environment is in a shutdown state.
2785
2786
2787EXAMPLE
2788--------------------------------------------------------------------------------------------
2789
2790The following is a simple example of how the rmr_send_msg
2791function is called. In this example, the send message buffer
2792is saved between calls and reused eliminating alloc/free
2793cycles.
2794
2795
2796::
2797
2798 static rmr_mbuf_t* send_msg = NULL; // message to send; reused on each call
2799 msg_t* send_pm; // payload for send
2800 msg_t* pm; // our message format in the received payload
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002801 if( send_msg == NULL ) {
2802 send_msg = rmr_alloc_msg( mr, MAX_SIZE ); // new buffer to send
2803 }
2804 // reference payload and fill in message type
E. Scott Daniels392168d2019-11-06 15:12:38 -05002805 pm = (msg_t*) send_msg->payload;
E. Scott Danielsa1575da2020-01-24 16:00:11 -05002806 send_msg->mtype = MT_ANSWER;
2807 msg->len = generate_data( pm ); // something that fills the payload in
2808 msg = rmr_send_msg( mr, send_msg ); // ensure new pointer used after send
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002809 if( ! msg ) {
2810 return ERROR;
2811 } else {
2812 if( msg->state != RMR_OK ) {
2813 // check for RMR_ERR_RETRY, and resend if needed
2814 // else return error
2815 }
2816 }
2817 return OK;
E. Scott Daniels392168d2019-11-06 15:12:38 -05002818
2819
2820
2821SEE ALSO
2822--------------------------------------------------------------------------------------------
2823
2824rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2825rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2826rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
2827rmr_ring_free(3), rmr_torcv_rcv(3), rmr_wh_send_msg(3)
2828
2829
2830NAME
2831--------------------------------------------------------------------------------------------
2832
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002833rmr_set_fack
2834
2835SYNOPSIS
2836--------------------------------------------------------------------------------------------
2837
2838
2839::
2840
2841 #include <rmr/rmr.h>
2842 void rmr_set_fack( void* vctx );
2843
2844
2845
2846DESCRIPTION
2847--------------------------------------------------------------------------------------------
2848
2849The rmr_set_fack function enables *fast TCP acknowledgements*
2850if the underlying transport library supports it. This might
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002851be useful for applications which must send messages at a
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002852maximum rate.
2853
2854RETURN VALUE
2855--------------------------------------------------------------------------------------------
2856
2857There is no return value.
2858
2859ERRORS
2860--------------------------------------------------------------------------------------------
2861
2862This function does not generate any errors.
2863
2864SEE ALSO
2865--------------------------------------------------------------------------------------------
2866
2867rmr_init(3),
2868
2869
2870NAME
2871--------------------------------------------------------------------------------------------
2872
E. Scott Daniels392168d2019-11-06 15:12:38 -05002873rmr_set_stimeout
2874
2875SYNOPSIS
2876--------------------------------------------------------------------------------------------
2877
2878
2879::
2880
2881 #include <rmr/rmr.h>
2882 rmr_mbuf_t* rmr_set_stimeout( void* vctx, int rloops );
2883
2884
2885
2886DESCRIPTION
2887--------------------------------------------------------------------------------------------
2888
2889The rmr_set_stimeout function sets the configuration for how
2890RMr will retry message send operations which complete with
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002891either a *timeout* or *again* completion value. (Send
E. Scott Daniels392168d2019-11-06 15:12:38 -05002892operations include all of the possible message send
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002893functions: *rmr_send_msg(), rmr_call(), rmr_rts_msg()* and
2894*rmr_wh_send_msg().* The *rloops* parameter sets the maximum
2895number of retry loops that will be attempted before giving up
2896and returning the unsuccessful state to the user application.
2897Each retry loop is approximately 1000 attempts, and RMr does
2898**not** invoke any sleep function between retries in the
2899loop; a small, 1 mu-sec, sleep is executed between loop sets
2900if the *rloops* value is greater than 1.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002901
2902
2903Disabling Retries
2904~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2905
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002906By default, the send operations will execute with an *rloop*
2907setting of 1; each send operation will attempt to resend the
2908message approximately 1000 times before giving up. If the
E. Scott Daniels392168d2019-11-06 15:12:38 -05002909user application does not want to have send operations retry
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002910when the underlying transport mechanism indicates *timeout*
2911or *again,* the application should invoke this function and
2912pass a value of 0 (zero) for *rloops.* With this setting, all
2913RMr send operations will attempt a send operation only
2914**once,** returning immediately to the caller with the state
E. Scott Daniels392168d2019-11-06 15:12:38 -05002915of that single attempt.
2916
2917RETURN VALUE
2918--------------------------------------------------------------------------------------------
2919
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002920This function returns a -1 to indicate that the *rloops*
2921value could not be set, and the value *RMR_OK* to indicate
E. Scott Daniels392168d2019-11-06 15:12:38 -05002922success.
2923
2924ERRORS
2925--------------------------------------------------------------------------------------------
2926
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002927Currently errno is **not** set by this function; the only
2928cause of a failure is an invalid context (*vctx*) pointer.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002929
2930EXAMPLE
2931--------------------------------------------------------------------------------------------
2932
2933The following is a simple example of how the rmr_set_stimeout
2934function is called.
2935
2936
2937::
2938
2939 #define NO_FLAGS 0
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04002940 char* port = "43086"; // port for message router listen
2941 int max_size = 4096; // max message size for default allocations
2942 void* mr_context; // message router context
E. Scott Daniels392168d2019-11-06 15:12:38 -05002943 mr_context = rmr_init( port, max_size, NO_FLAGS );
2944 if( mr_context != NULL ) {
2945 rmr_set_stimeout( mr_context, 0 ); // turn off retries
2946 }
2947
2948
2949
2950SEE ALSO
2951--------------------------------------------------------------------------------------------
2952
2953rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2954rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2955rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
2956rmr_ring_free(3), rmr_send_msg(3), rmr_torcv_rcv(3),
2957rmr_wh_send_msg(3)
2958
2959
2960NAME
2961--------------------------------------------------------------------------------------------
2962
2963rmr_set_trace
2964
2965SYNOPSIS
2966--------------------------------------------------------------------------------------------
2967
2968
2969::
2970
2971 #include <rmr/rmr.h>
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05002972 int rmr_set_trace( rmr_mbuf_t* mbuf, unsigned char* data, int len )
E. Scott Daniels392168d2019-11-06 15:12:38 -05002973
2974
2975
2976DESCRIPTION
2977--------------------------------------------------------------------------------------------
2978
2979The rmr_set_trace function will copy len bytes from data into
2980the trace portion of mbuf. If the trace area of mbuf is not
2981the correct size, the message buffer will be reallocated to
2982ensure that enough space is available for the trace data.
2983
2984RETURN VALUE
2985--------------------------------------------------------------------------------------------
2986
2987The rmr_set_trace function returns the number of bytes
2988successfully copied to the message. If 0 is returned either
2989the message pointer was nil, or the size in the parameters
2990was <= 0.
2991
2992SEE ALSO
2993--------------------------------------------------------------------------------------------
2994
2995rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
2996rmr_bytes2payload(3), rmr_call(3), rmr_free_msg(3),
2997rmr_get_rcvfd(3), rmr_get_meid(3), rmr_get_trace(3),
2998rmr_get_trlen(3), rmr_init(3), rmr_init_trace(3),
2999rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
3000rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
3001rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
3002rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
3003rmr_wh_open(3), rmr_wh_send_msg(3)
3004
3005
3006NAME
3007--------------------------------------------------------------------------------------------
3008
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003009rmr_set_vlevel
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003010
3011SYNOPSIS
3012--------------------------------------------------------------------------------------------
3013
3014
3015::
3016
3017 #include <rmr/rmr.h>
3018 #include <rmr/rmr_logging.h>
3019 void rmr_set_vlevel( int new_level )
3020
3021
3022
3023DESCRIPTION
3024--------------------------------------------------------------------------------------------
3025
3026The rmr_set_vlevel allows the user programme to set the
3027verbosity level which is used to determine the messages RMR
3028writes to standard error. The new_vlevel value must be one of
3029the following constants which have the indicated meanings:
3030
3031
3032RMR_VL_OFF
3033
3034 Turns off all message writing. This includes the stats and
3035 debugging messages generated by the route collector thread
3036 which are normally affected only by the externally managed
3037 verbose level file (and related environment variable).
3038
3039
3040RMR_VL_CRIT
3041
3042 Write only messages of critical importance. From the point
3043 of view of RMR, when a critical proper behaviour of the
3044 library cannot be expected or guaranteed.
3045
3046RMR_VL_ERR
3047
3048 Include error messages in the output. An error is an event
3049 from which RMR has no means to recover. Continued proper
3050 execution is likely except where the affected connection
3051 and/or component mentioned in the error is concerned.
3052
3053RMR_VL_WARN
3054
3055 Include warning messages in the output. A warning
3056 indicates an event which is not considered to be normal,
3057 but is expected and continued acceptable behaviour of the
3058 system is assured.
3059
3060RMR_VL_INFO
3061
3062 Include informational messagees in the output.
3063 Informational messages include some diagnostic information
3064 which explain the activities of RMR.
3065
3066RMR_VL_DEBUG
3067
3068 Include all debugging messages in the output. Debugging
3069 must have also been enabled during the build as a
3070 precaution to accidentally enabling this level of output
3071 as it can grossly affect performance.
3072
3073
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003074Generally RMR does not write messages to the standard error
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003075device from *critical path* functions, therefore it is
3076usually not harmful to enable a verbosity level of either
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003077RMR_VL_CRIT or RMR_VL_ERR.
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05003078
3079Messages written from the route table collection thread are
3080still governed by the value placed into the verbose level
3081control file (see the man page for rmr_init()); those
3082messages are affected only when logging is completely
3083disabled by passing RMR_VL_OFF to this function.
3084
3085The verbosity level can also be set via an environment
3086variable prior to the start of the RMR based application. The
3087environment variable is read only during initialisation; if
3088the programme must change the value during execution, this
3089function must be used. The default value, if this function is
3090never called, and the environment variable is not present, is
3091RMR_VL_ERR.
3092
3093SEE ALSO
3094--------------------------------------------------------------------------------------------
3095
3096rmr_init(3)
3097
3098
3099NAME
3100--------------------------------------------------------------------------------------------
3101
E. Scott Daniels392168d2019-11-06 15:12:38 -05003102rmr_str2meid
3103
3104SYNOPSIS
3105--------------------------------------------------------------------------------------------
3106
3107
3108::
3109
3110 #include <rmr/rmr.h>
3111 int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
3112
3113
3114
3115DESCRIPTION
3116--------------------------------------------------------------------------------------------
3117
3118The rmr_str2meid function will copy the string pointed to by
E. Scott Daniels190665f2019-12-09 09:05:22 -05003119src to the managed entity ID (meid) field in the given
E. Scott Daniels392168d2019-11-06 15:12:38 -05003120message. The field is a fixed length, gated by the constant
3121RMR_MAX_MEID and if string length is larger than this value,
3122then **nothing** will be copied. (Note, this differs slightly
3123from the behaviour of the lrmr_bytes2meid() function.)
3124
3125RETURN VALUE
3126--------------------------------------------------------------------------------------------
3127
3128On success, the value RMR_OK is returned. If the string
3129cannot be copied to the message, the return value will be one
3130of the errors listed below.
3131
3132ERRORS
3133--------------------------------------------------------------------------------------------
3134
3135If the return value is not RMR_OK, then it will be set to one
3136of the values below.
3137
3138
3139
3140RMR_ERR_BADARG
3141
3142 The message, or an internal portion of the message, was
3143 corrupted or the pointer was invalid.
3144
3145
3146RMR_ERR_OVERFLOW
3147
3148 The length passed in was larger than the maximum length of
3149 the field; only a portion of the source bytes were copied.
3150
3151
3152EXAMPLE
3153--------------------------------------------------------------------------------------------
3154
3155
3156SEE ALSO
3157--------------------------------------------------------------------------------------------
3158
3159rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3160rmr_get_meid(3), rmr_get_rcvfd(3), rmr_payload_size(3),
3161rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3162rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3163rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3164rmr_bytes2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
3165
3166
3167NAME
3168--------------------------------------------------------------------------------------------
3169
3170rmr_str2xact
3171
3172SYNOPSIS
3173--------------------------------------------------------------------------------------------
3174
3175
3176::
3177
3178 #include <rmr/rmr.h>
3179 int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
3180
3181
3182
3183DESCRIPTION
3184--------------------------------------------------------------------------------------------
3185
3186The rmr_str2xact function will copy the string pointed to by
3187src to the transaction ID (xaction) field in the given
3188message. The field is a fixed length, gated by the constant
3189RMR_MAX_XID and if string length is larger than this value,
3190then **nothing** will be copied. (Note, this differs slightly
3191from the behaviour of the lrmr_bytes2xact() function.)
3192
3193
3194RETURN VALUE
3195--------------------------------------------------------------------------------------------
3196
3197On success, the value RMR_OK is returned. If the string
3198cannot be copied to the message, the return value will be
3199one of the errors listed below.
3200
3201ERRORS
3202--------------------------------------------------------------------------------------------
3203
3204If the return value is not RMR_OK, then it will be set to
3205one of the values below.
3206
3207
3208RMR_ERR_BADARG
3209
3210 The message, or an internal portion of the message, was
3211 corrupted or the pointer was invalid.
3212
3213
3214RMR_ERR_OVERFLOW
3215
3216 The length passed in was larger than the maximum length of
3217 the field; only a portion of the source bytes were copied.
3218
3219
3220EXAMPLE
3221--------------------------------------------------------------------------------------------
3222
3223
3224SEE ALSO
3225--------------------------------------------------------------------------------------------
3226
3227rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_bytes2xact(3),
3228rmr_call(3), rmr_free_msg(3), rmr_get_meid(3),
3229rmr_get_rcvfd(3), rmr_get_xact(3), rmr_payload_size(3),
3230rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3231rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3232rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3233rmr_str2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
3234
3235
3236NAME
3237--------------------------------------------------------------------------------------------
3238
3239RMR support functions
3240
3241SYNOPSIS
3242--------------------------------------------------------------------------------------------
3243
3244
3245::
3246
3247 #include <rmr/rmr.h>
3248 #include <rmr/ring_inline.h>
3249 char* rmr_fib( char* fname );
3250 int rmr_has_str( char const* buf, char const* str, char sep, int max );
3251 int rmr_tokenise( char* buf, char** tokens, int max, char sep );
3252 void* rmr_mk_ring( int size );
3253 void rmr_ring_free( void* vr );
3254 static inline void* rmr_ring_extract( void* vr )
3255 static inline int rmr_ring_insert( void* vr, void* new_data )
3256
3257
3258
3259DESCRIPTION
3260--------------------------------------------------------------------------------------------
3261
3262These functions support the RMR library, and are made
3263available to user applications as some (e.g. route table
3264generators) might need and/or want to make use of them. The
3265rmr_fib function accepts a file name and reads the entire
3266file into a single buffer. The intent is to provide an easy
3267way to load a static route table without a lot of buffered
3268I/O hoops.
3269
3270The rmr_has_str function accepts a *buffer* containing a set
3271of delimited tokens (e.g. foo,bar,goo) and returns true if
3272the target string, *str,* matches one of the tokens. The
3273*sep* parameter provides the separation character in the
3274buffer (e.g a comma) and *max* indicates the maximum number
3275of tokens to split the buffer into before checking.
3276
3277The rmr_tokenise function is a simple tokeniser which splits
3278*buf* into tokens at each occurrence of *sep*. Multiple
3279occurrences of the separator character (e.g. a,,b) result in
3280a nil token. Pointers to the tokens are placed into the
3281*tokens* array provided by the caller which is assumed to
3282have at least enough space for *max* entries.
3283
3284The rmr_mk_ring function creates a buffer ring with *size*
3285entries.
3286
3287The rmr_ring_free function accepts a pointer to a ring
3288context and frees the associated memory.
3289
3290The rmr_ring_insert and rmr_ring_extract functions are
3291provided as static inline functions via the
3292*rmr/ring_inline.h* header file. These functions both accept
3293the ring *context* returned by mk_ring, and either insert a
3294pointer at the next available slot (tail) or extract the data
3295at the head.
3296
3297RETURN VALUES
3298--------------------------------------------------------------------------------------------
3299
3300The following are the return values for each of these
3301functions.
3302
3303The rmr_fib function returns a pointer to the buffer
3304containing the contents of the file. The buffer is terminated
3305with a single nil character (0) making it a legitimate C
3306string. If the file was empty or nonexistent, a buffer with
3307an immediate nil character. If it is important to the calling
3308programme to know if the file was empty or did not exist, the
3309caller should use the system stat function call to make that
3310determination.
3311
3312The rmr_has_str function returns 1 if *buf* contains the
3313token referenced by &ita and false (0) if it does not. On
3314error, a -1 value is returned and errno is set accordingly.
3315
3316The rmr_tokenise function returns the actual number of token
3317pointers placed into *tokens*
3318
3319The rmr_mk_ring function returns a void pointer which is the
3320*context* for the ring.
3321
3322The rmr_ring_insert function returns 1 if the data was
3323successfully inserted into the ring, and 0 if the ring is
3324full and the pointer could not be deposited.
3325
3326The rmr_ring_extract will return the data which is at the
3327head of the ring, or NULL if the ring is empty.
3328
3329ERRORS
3330--------------------------------------------------------------------------------------------
3331
3332Not many of these functions set the value in errno, however
3333the value may be one of the following:
3334
3335
3336INVAL
3337
3338 Parameter(s) passed to the function were not valid.
3339
3340
3341EXAMPLE
3342--------------------------------------------------------------------------------------------
3343
3344
3345SEE ALSO
3346--------------------------------------------------------------------------------------------
3347
3348rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3349rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
3350rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
3351
3352
3353NAME
3354--------------------------------------------------------------------------------------------
3355
3356rmr_torcv_msg
3357
3358SYNOPSIS
3359--------------------------------------------------------------------------------------------
3360
3361
3362::
3363
3364 #include <rmr/rmr.h>
3365 rmr_mbuf_t* rmr_torcv_msg( void* vctx, rmr_mbuf_t* old_msg, int ms_to );
3366
3367
3368
3369DESCRIPTION
3370--------------------------------------------------------------------------------------------
3371
3372The rmr_torcv_msg function will pause for *ms_to*
3373milliseconds waiting for a message to arrive. If a message
3374arrives before the timeout expires the message buffer
3375returned will have a status of RMR_OK and the payload will
3376contain the data received. If the timeout expires before the
3377message is received, the status will have the value
3378RMR_ERR_TIMEOUT. When a received message is returned the
3379message buffer will also contain the message type and length
3380set by the sender. If messages were queued while waiting for
3381the response to a previous invocation of rmr_call, the oldest
3382message is removed from the queue and returned without delay.
3383
3384The *vctx* pointer is the pointer returned by the rmr_init
3385function. *Old_msg* is a pointer to a previously used message
3386buffer or NULL. The ability to reuse message buffers helps to
3387avoid alloc/free cycles in the user application. When no
3388buffer is available to supply, the receive function will
3389allocate one.
3390
3391RETURN VALUE
3392--------------------------------------------------------------------------------------------
3393
3394The function returns a pointer to the rmr_mbuf_t structure
3395which references the message information (state, length,
3396payload), or a NULL pointer in the case of an extreme error.
3397
3398ERRORS
3399--------------------------------------------------------------------------------------------
3400
3401The *state* field in the message buffer will be one of the
3402following:
3403
3404
3405
3406RMR_OK
3407
3408 The message buffer (payload) references the received data.
3409
3410
3411RMR_ERR_INITFAILED
3412
3413 The first call to this function must initialise an
3414 underlying system notification mechanism. On failure, this
3415 error is returned and errno will have the system error
3416 status set. If this function fails to intialise, the poll
3417 mechansim, it is likely that message receives will never
3418 be successful.
3419
3420
3421RMR_ERR_TIMEOUT
3422
3423 The timeout expired before a complete message was
3424 received. All other fields in the message buffer are not
3425 valid.
3426
3427
3428RMR_ERR_EMPTY
3429
3430 A message was received, but it had no payload. All other
3431 fields in the message buffer are not valid.
3432
3433
3434
3435
3436INVAL
3437
3438 Parameter(s) passed to the function were not valid.
3439
3440
3441EBADF
3442
3443 The underlying message transport is unable to process the
3444 request.
3445
3446
3447ENOTSUP
3448
3449 The underlying message transport is unable to process the
3450 request.
3451
3452
3453EFSM
3454
3455 The underlying message transport is unable to process the
3456 request.
3457
3458
3459EAGAIN
3460
3461 The underlying message transport is unable to process the
3462 request.
3463
3464
3465EINTR
3466
3467 The underlying message transport is unable to process the
3468 request.
3469
3470
3471ETIMEDOUT
3472
3473 The underlying message transport is unable to process the
3474 request.
3475
3476
3477ETERM
3478
3479 The underlying message transport is unable to process the
3480 request.
3481
3482
3483EXAMPLE
3484--------------------------------------------------------------------------------------------
3485
3486
3487SEE ALSO
3488--------------------------------------------------------------------------------------------
3489
3490rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3491rmr_get_rcvfd(3), rmr_init(3), rmr_payload_size(3),
3492rmr_rcv_msg(3), rmr_send_msg(3), rmr_rcv_specific(3),
3493rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3494rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
3495
3496
3497NAME
3498--------------------------------------------------------------------------------------------
3499
3500rmr_trace_ref
3501
3502SYNOPSIS
3503--------------------------------------------------------------------------------------------
3504
3505
3506::
3507
3508 #include <rmr/rmr.h>
3509 int rmr_trace_ref( rmr_mbuf_t* mbuf, int* sizeptr )
3510
3511
3512
3513DESCRIPTION
3514--------------------------------------------------------------------------------------------
3515
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003516The rmr_trace_ref function returns a pointer to the trace
3517area in the message, and optionally populates the user
3518programme supplied size integer with the trace area size, if
3519*sizeptr* is not nil.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003520
3521RETURN VALUE
3522--------------------------------------------------------------------------------------------
3523
3524On success, a void pointer to the trace area of the message
3525is returned. A nil pointer is returned if the message has no
3526trace data area allocated, or if the message itself is
3527invalid.
3528
3529SEE ALSO
3530--------------------------------------------------------------------------------------------
3531
3532rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
3533rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
3534rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
3535rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
3536rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3537rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3538rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
3539rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
3540rmr_set_trace(3)
3541
3542
3543NAME
3544--------------------------------------------------------------------------------------------
3545
3546rmr_tralloc_msg
3547
3548SYNOPSIS
3549--------------------------------------------------------------------------------------------
3550
3551
3552::
3553
3554 #include <rmr/rmr.h>
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003555 rmr_mbuf_t* rmr_tralloc_msg( void* vctx, int size,
E. Scott Daniels392168d2019-11-06 15:12:38 -05003556 int trace_size, unsigned const char *tr_data );
3557
3558
3559
3560DESCRIPTION
3561--------------------------------------------------------------------------------------------
3562
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003563The rmr_tralloc_msg function is used to allocate a buffer
3564which the user programme can write into and then send through
3565the library. The buffer is allocated such that sending it
E. Scott Daniels392168d2019-11-06 15:12:38 -05003566requires no additional copying from the buffer as it passes
3567through the underlying transport mechanism.
3568
3569The *size* parameter is used to set the payload length in the
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003570message. If it is 0, then the default size supplied on the
E. Scott Daniels392168d2019-11-06 15:12:38 -05003571*rmr_init* call will be used. In addition to allocating the
3572payload, a space in the buffer is reserved for *trace* data
3573(tr_size bytes), and the bytes pointed to by *tr_data* are
3574copied into that portion of the message. The *vctx* parameter
3575is the void context pointer that was returned by the
3576*rmr_init* function.
3577
3578The pointer to the message buffer returned is a structure
3579which has some user application visible fields; the structure
3580is described in rmr.h, and is illustrated below.
3581
3582
3583::
3584
3585 typedef struct {
3586 int state;
3587 int mtype;
3588 int len;
3589 unsigned char* payload;
3590 unsigned char* xaction;
3591 } rmr_mbuf_t;
3592
3593
3594
3595
3596
3597state
3598
3599 Is the current buffer state. Following a call to
3600 rmr_send_msg the state indicates whether the buffer was
3601 successfully sent which determines exactly what the
3602 payload points to. If the send failed, the payload
3603 referenced by the buffer is the message that failed to
3604 send (allowing the application to attempt a
3605 retransmission). When the state is a_OK the buffer
3606 represents an empty buffer that the application may fill
3607 in in preparation to send.
3608
3609
3610mtype
3611
3612 When sending a message, the application is expected to set
3613 this field to the appropriate message type value (as
3614 determined by the user programme). Upon send this value
3615 determines how the a library will route the message. For a
3616 buffer which has been received, this field will contain
3617 the message type that was set by the sending application.
3618
3619
3620len
3621
3622 The application using a buffer to send a message is
3623 expected to set the length value to the actual number of
3624 bytes that it placed into the message. This is likely less
3625 than the total number of bytes that the message can carry.
3626 For a message buffer that is passed to the application as
3627 the result of a receive call, this will be the value that
3628 the sending application supplied and should indicate the
3629 number of bytes in the payload which are valid.
3630
3631
3632payload
3633
3634 The payload is a pointer to the actual received data. The
3635 user programme may read and write from/to the memory
3636 referenced by the payload up until the point in time that
3637 the buffer is used on a rmr_send, rmr_call or rmr_reply
3638 function call. Once the buffer has been passed back to a a
3639 library function the user programme should **NOT** make
3640 use of the payload pointer.
3641
3642
3643xaction
3644
3645 The *xaction* field is a pointer to a fixed sized area in
3646 the message into which the user may write a transaction
3647 ID. The ID is optional with the exception of when the user
3648 application uses the rmr_call function to send a message
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003649 and wait for the reply; the underlying processing expects
3650 that the matching reply message will also contain the same
3651 data in the *xaction* field.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003652
3653
3654RETURN VALUE
3655--------------------------------------------------------------------------------------------
3656
3657The function returns a pointer to a rmr_mbuf structure, or
3658NULL on error.
3659
3660ERRORS
3661--------------------------------------------------------------------------------------------
3662
3663
3664
3665ENOMEM
3666
3667 Unable to allocate memory.
3668
3669
3670SEE ALSO
3671--------------------------------------------------------------------------------------------
3672
3673rmr_alloc_msg(3), rmr_mbuf(3) rmr_call(3), rmr_free_msg(3),
3674rmr_init(3), rmr_init_trace(3), rmr_get_trace(3),
3675rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
3676rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3677rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3678rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
3679
3680
3681NAME
3682--------------------------------------------------------------------------------------------
3683
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003684rmr_wh_call
3685
3686SYNOPSIS
3687--------------------------------------------------------------------------------------------
3688
3689
3690::
3691
3692 #include <rmr/rmr.h>
3693 rmr_mbuf_t* rmr_wh_call( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg, int call_id, int max_wait )
3694
3695
3696
3697DESCRIPTION
3698--------------------------------------------------------------------------------------------
3699
3700The rmr_wh_call function accepts a message buffer (msg) from
3701the user application and attempts to send it using the
3702wormhole ID provided (whid). If the send is successful, the
3703call will block until either a response message is received,
3704or the max_wait number of milliseconds has passed. In order
3705for the response to be recognised as a response, the remote
3706process **must** use rmr_rts_msg() to send their response.
3707
3708Like *rmr_wh_send_msg,* this function attempts to send the
3709message directly to a process at the other end of a wormhole
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003710which was created with *rmr_wh_open().* When sending message
3711via wormholes, the normal RMR routing based on message type
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003712is ignored, and the caller may leave the message type
3713unspecified in the message buffer (unless it is needed by the
3714receiving process). The call_id parameter is a number in the
3715range of 2 through 255 and is used to identify the calling
3716thread in order to properly match a response message when it
3717arrives. Providing this value, and ensuring the proper
3718uniqueness, is the responsibility of the user application and
3719as such the ability to use the rmr_wh_call() function from
3720potentially non-threaded concurrent applications (such as
3721Go's goroutines) is possible.
3722
3723Retries
3724~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3725
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003726The send operations in RMR will retry *soft* send failures
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003727until one of three conditions occurs:
3728
3729
3730
37311.
3732
3733 The message is sent without error
3734
3735
37362.
3737
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003738 The underlying transport reports a *hard* failure
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003739
3740
37413.
3742
3743 The maximum number of retry loops has been attempted
3744
3745
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003746A retry loop consists of approximately 1000 send attempts
3747**without** any intervening calls to *sleep()* or *usleep().*
3748The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels8633a0b2020-03-09 13:57:39 -040037491000 send attempts is performed before returning to the user
3750application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003751initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003752allowing the user application to completely disable retires
3753(set to 0), or to increase the number of retry loops.
3754
3755Transport Level Blocking
3756~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3757
3758The underlying transport mechanism used to send messages is
3759configured in *non-blocking* mode. This means that if a
3760message cannot be sent immediately the transport mechanism
3761will **not** pause with the assumption that the inability to
3762send will clear quickly (within a few milliseconds). This
3763means that when the retry loop is completely disabled (set to
37640), that the failure to accept a message for sending by the
3765underlying mechanisms (software or hardware) will be reported
3766immediately to the user application.
3767
3768It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003769mechanism being used, it is extremely likely that retry
3770conditions will happen during normal operations. These are
3771completely out of RMR's control, and there is nothing that
3772RMR can do to avoid or mitigate these other than by allowing
3773RMR to retry the send operation, and even then it is possible
3774(e.g., during connection reattempts), that a single retry
3775loop is not enough to guarantee a successful send.
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003776
3777RETURN VALUE
3778--------------------------------------------------------------------------------------------
3779
3780On success, new message buffer, with the payload containing
3781the response from the remote endpoint is returned. The state
3782in this buffer will reflect the overall send operation state
3783and should be RMR_OK.
3784
3785If a message is returned with a state which is anything other
3786than RMR_OK, the indication is that the send was not
3787successful. The user application must check the state and
3788determine the course of action. If the return value is NULL,
3789no message, the indication is that there was no response
3790received within the timeout (max_wait) period of time.
3791
3792ERRORS
3793--------------------------------------------------------------------------------------------
3794
3795The following values may be passed back in the *state* field
3796of the returned message buffer.
3797
3798
3799
3800RMR_ERR_WHID
3801
3802 The wormhole ID passed in was not associated with an open
3803 wormhole, or was out of range for a valid ID.
3804
3805RMR_ERR_NOWHOPEN
3806
3807 No wormholes exist, further attempt to validate the ID are
3808 skipped.
3809
3810RMR_ERR_BADARG
3811
3812 The message buffer pointer did not refer to a valid
3813 message.
3814
3815RMR_ERR_NOHDR
3816
3817 The header in the message buffer was not valid or
3818 corrupted.
3819
3820
3821EXAMPLE
3822--------------------------------------------------------------------------------------------
3823
3824The following is a simple example of how the a wormhole is
3825created (rmr_wh_open) and then how rmr_wh_send_msg function
3826is used to send messages. Some error checking is omitted for
3827clarity.
3828
3829
3830::
3831
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003832 #include <rmr/rmr.h> // system headers omitted for clarity
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003833 int main() {
3834 rmr_whid_t whid = -1; // wormhole id for sending
3835 void* mrc; //msg router context
3836 int i;
3837 rmr_mbuf_t* sbuf; // send buffer
3838 int count = 0;
3839 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
3840 if( mrc == NULL ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003841 fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003842 exit( 1 );
3843 }
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003844 while( ! rmr_ready( mrc ) ) { // wait for routing table info
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003845 sleep( 1 );
3846 }
3847 sbuf = rmr_alloc_msg( mrc, 2048 );
3848 while( 1 ) {
3849 if( whid < 0 ) {
3850 whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003851 if( RMR_WH_CONNECTED( wh ) ) {
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003852 snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
3853 sbuf->len = strlen( sbuf->payload );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003854 sbuf = rmr_wh_call( mrc, whid, sbuf, 1000 ); // expect a response in 1s or less
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003855 if( sbuf != NULL && sbuf->state = RMR_OK ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003856 sprintf( stderr, "response: %s\\n", sbuf->payload ); // assume they sent a string
E. Scott Daniels8633a0b2020-03-09 13:57:39 -04003857 } else {
3858 sprintf( stderr, "response not received, or send error\\n" );
3859 }
3860 }
3861 }
3862 sleep( 5 );
3863 }
3864 }
3865
3866
3867
3868SEE ALSO
3869--------------------------------------------------------------------------------------------
3870
3871rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3872rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3873rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3874rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3875rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3),
3876rmr_wh_state(3)
3877
3878
3879NAME
3880--------------------------------------------------------------------------------------------
3881
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003882rmr_wh_close
E. Scott Daniels392168d2019-11-06 15:12:38 -05003883
3884SYNOPSIS
3885--------------------------------------------------------------------------------------------
3886
3887
3888::
3889
3890 #include <rmr/rmr.h>
3891 void rmr_close( void* vctx, rmr_whid_t whid )
3892
3893
3894
3895DESCRIPTION
3896--------------------------------------------------------------------------------------------
3897
3898The rmr_wh_close function closes the wormhole associated with
3899the wormhole id passed in. Future calls to rmr_wh_send_msg
3900with this ID will fail.
3901
3902The underlying TCP connection to the remote endpoint is
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003903**not** closed as this session may be required for regularly
3904routed messages (messages routed based on message type).
3905There is no way to force a TCP session to be closed at this
3906point in time.
E. Scott Daniels392168d2019-11-06 15:12:38 -05003907
3908SEE ALSO
3909--------------------------------------------------------------------------------------------
3910
3911rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3912rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
3913rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3914rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3915rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
3916rmr_wh_send_msg(3)
3917
3918
3919NAME
3920--------------------------------------------------------------------------------------------
3921
3922rmr_wh_open
3923
3924SYNOPSIS
3925--------------------------------------------------------------------------------------------
3926
3927
3928::
3929
3930 #include <rmr/rmr.h>
3931 void* rmr_wh_open( void* vctx, char* target )
3932
3933
3934
3935DESCRIPTION
3936--------------------------------------------------------------------------------------------
3937
3938The rmr_wh_open function creates a direct link for sending, a
3939wormhole, to another RMr based process. Sending messages
3940through a wormhole requires that the connection be
3941established overtly by the user application (via this
3942function), and that the ID returned by rmr_wh_open be passed
3943to the rmr_wh_send_msg function.
3944
3945*Target* is the *name* or *IP-address* combination of the
3946processess that the wormhole should be connected to. *Vctx*
3947is the RMr void context pointer that was returned by the
3948rmr_init function.
3949
3950When invoked, this function immediatly attempts to connect to
3951the target process. If the connection cannot be established,
3952an error is returned to the caller, and no direct messages
3953can be sent to the target. Once a wormhole is connected, the
3954underlying transport mechanism (e.g. NNG) will provide
3955reconnects should the connection be lost, however the
3956handling of messages sent when a connection is broken is
3957undetermined as each underlying transport mechanism may
3958handle buffering and retries differently.
3959
3960RETURN VALUE
3961--------------------------------------------------------------------------------------------
3962
3963The rmr_wh_open function returns a type rmr_whid_t which must
3964be passed to the rmr_wh_send_msg function when sending a
3965message. The id may also be tested to determine success or
3966failure of the connection by using the RMR_WH_CONNECTED macro
3967and passing the ID as the parameter; a result of 1 indicates
3968that the connection was esablished and that the ID is valid.
3969
3970ERRORS
3971--------------------------------------------------------------------------------------------
3972
3973The following error values are specifically set by this RMR
3974function. In some cases the error message of a system call is
3975propagated up, and thus this list might be incomplete.
3976
3977
3978EINVAL
3979
3980 A parameter passed was not valid.
3981
3982EACCESS
3983
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04003984 The user application does not have the ability to
E. Scott Daniels392168d2019-11-06 15:12:38 -05003985 establish a wormhole to the indicated target (or maybe any
3986 target).
3987
3988ECONNREFUSED
3989
3990 The connection was refused.
3991
3992
3993EXAMPLE
3994--------------------------------------------------------------------------------------------
3995
3996
3997::
3998
3999 void* rmc;
4000 rmr_whid_t wh;
4001 rmc = rmr_init( "43086", 4096, 0 ); // init context
4002 wh = rmr_wh_open( rmc, "localhost:6123" );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004003 if( !RMR_WH_CONNECTED( wh ) ) {
4004 fprintf( stderr, "unable to connect wormhole: %s\\n",
E. Scott Daniels392168d2019-11-06 15:12:38 -05004005 strerror( errno ) );
4006 }
4007
4008
4009
4010SEE ALSO
4011--------------------------------------------------------------------------------------------
4012
4013rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
4014rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
4015rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
4016rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004017rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_close(3),
4018rmr_wh_send_msg(3), rmr_wh_state(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -05004019
4020
4021NAME
4022--------------------------------------------------------------------------------------------
4023
4024rmr_wh_send_msg
4025
4026SYNOPSIS
4027--------------------------------------------------------------------------------------------
4028
4029
4030::
4031
4032 #include <rmr/rmr.h>
4033 rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t id, rmr_mbuf_t* msg );
4034
4035
4036
4037DESCRIPTION
4038--------------------------------------------------------------------------------------------
4039
4040The rmr_wh_send_msg function accepts a message buffer from
4041the user application and attempts to send it using the
4042wormhole ID provided (id). Unlike *rmr_send_msg,* this
4043function attempts to send the message directly to a process
4044at the other end of a wormhole which was created with
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004045*rmr_wh_open().* When sending message via wormholes, the
4046normal RMR routing based on message type is ignored, and the
E. Scott Daniels392168d2019-11-06 15:12:38 -05004047caller may leave the message type unspecified in the message
4048buffer (unless it is needed by the receiving process).
4049
4050The message buffer (msg) used to send is the same format as
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004051used for regular RMR send and reply to sender operations,
E. Scott Daniels392168d2019-11-06 15:12:38 -05004052thus any buffer allocated by these means, or calls to
4053*rmr_rcv_msg()* can be passed to this function.
4054
4055Retries
4056~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4057
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004058The send operations in RMR will retry *soft* send failures
E. Scott Daniels392168d2019-11-06 15:12:38 -05004059until one of three conditions occurs:
4060
4061
4062
40631.
4064
4065 The message is sent without error
4066
4067
40682.
4069
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004070 The underlying transport reports a *hard* failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05004071
4072
40733.
4074
4075 The maximum number of retry loops has been attempted
4076
4077
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004078A retry loop consists of approximately 1000 send attempts
4079**without** any intervening calls to *sleep()* or *usleep().*
4080The number of retry loops defaults to 1, thus a maximum of
E. Scott Daniels392168d2019-11-06 15:12:38 -050040811000 send attempts is performed before returning to the user
4082application. This value can be set at any point after RMr
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004083initialisation using the *rmr_set_stimeout()* function
E. Scott Daniels392168d2019-11-06 15:12:38 -05004084allowing the user application to completely disable retires
4085(set to 0), or to increase the number of retry loops.
4086
4087Transport Level Blocking
4088~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4089
4090The underlying transport mechanism used to send messages is
4091configured in *non-blocking* mode. This means that if a
4092message cannot be sent immediately the transport mechanism
4093will **not** pause with the assumption that the inability to
4094send will clear quickly (within a few milliseconds). This
4095means that when the retry loop is completely disabled (set to
40960), that the failure to accept a message for sending by the
4097underlying mechanisms (software or hardware) will be reported
4098immediately to the user application.
4099
4100It should be noted that depending on the underlying transport
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004101mechanism being used, it is extremely likely that retry
4102conditions will happen during normal operations. These are
4103completely out of RMR's control, and there is nothing that
4104RMR can do to avoid or mitigate these other than by allowing
4105RMR to retry the send operation, and even then it is possible
4106(e.g., during connection reattempts), that a single retry
4107loop is not enough to guarantee a successful send.
E. Scott Daniels392168d2019-11-06 15:12:38 -05004108
4109RETURN VALUE
4110--------------------------------------------------------------------------------------------
4111
4112On success, a new message buffer, with an empty payload, is
4113returned for the application to use for the next send. The
4114state in this buffer will reflect the overall send operation
4115state and should be RMR_OK.
4116
4117If the state in the returned buffer is anything other than
4118RMR_OK, the user application may need to attempt a
4119retransmission of the message, or take other action depending
4120on the setting of errno as described below.
4121
4122In the event of extreme failure, a NULL pointer is returned.
4123In this case the value of errno might be of some use, for
4124documentation, but there will be little that the user
4125application can do other than to move on.
4126
4127ERRORS
4128--------------------------------------------------------------------------------------------
4129
4130The following values may be passed back in the *state* field
4131of the returned message buffer.
4132
4133
4134
4135RMR_ERR_WHID
4136
4137 The wormhole ID passed in was not associated with an open
4138 wormhole, or was out of range for a valid ID.
4139
4140RMR_ERR_NOWHOPEN
4141
4142 No wormholes exist, further attempt to validate the ID are
4143 skipped.
4144
4145RMR_ERR_BADARG
4146
4147 The message buffer pointer did not refer to a valid
4148 message.
4149
4150RMR_ERR_NOHDR
4151
4152 The header in the message buffer was not valid or
4153 corrupted.
4154
4155
4156The following values may be assigned to errno on failure.
4157
4158
4159INVAL
4160
4161 Parameter(s) passed to the function were not valid, or the
4162 underlying message processing environment was unable to
4163 interpret the message.
4164
4165
4166ENOKEY
4167
4168 The header information in the message buffer was invalid.
4169
4170
4171ENXIO
4172
4173 No known endpoint for the message could be found.
4174
4175
4176EMSGSIZE
4177
4178 The underlying transport refused to accept the message
4179 because of a size value issue (message was not attempted
4180 to be sent).
4181
4182
4183EFAULT
4184
4185 The message referenced by the message buffer is corrupt
4186 (NULL pointer or bad internal length).
4187
4188
4189EBADF
4190
4191 Internal RMR error; information provided to the message
4192 transport environment was not valid.
4193
4194
4195ENOTSUP
4196
4197 Sending was not supported by the underlying message
4198 transport.
4199
4200
4201EFSM
4202
4203 The device is not in a state that can accept the message.
4204
4205
4206EAGAIN
4207
4208 The device is not able to accept a message for sending.
4209 The user application should attempt to resend.
4210
4211
4212EINTR
4213
4214 The operation was interrupted by delivery of a signal
4215 before the message was sent.
4216
4217
4218ETIMEDOUT
4219
4220 The underlying message environment timed out during the
4221 send process.
4222
4223
4224ETERM
4225
4226 The underlying message environment is in a shutdown state.
4227
4228
4229EXAMPLE
4230--------------------------------------------------------------------------------------------
4231
4232The following is a simple example of how the a wormhole is
4233created (rmr_wh_open) and then how rmr_wh_send_msg function
4234is used to send messages. Some error checking is omitted for
4235clarity.
4236
4237
4238::
4239
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004240 #include <rmr/rmr.h> // system headers omitted for clarity
E. Scott Daniels392168d2019-11-06 15:12:38 -05004241 int main() {
4242 rmr_whid_t whid = -1; // wormhole id for sending
4243 void* mrc; //msg router context
4244 int i;
4245 rmr_mbuf_t* sbuf; // send buffer
4246 int count = 0;
4247 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
4248 if( mrc == NULL ) {
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004249 fprintf( stderr, "[FAIL] unable to initialise RMR environment\\n" );
E. Scott Daniels392168d2019-11-06 15:12:38 -05004250 exit( 1 );
4251 }
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004252 while( ! rmr_ready( mrc ) ) { // wait for routing table info
E. Scott Daniels392168d2019-11-06 15:12:38 -05004253 sleep( 1 );
4254 }
4255 sbuf = rmr_alloc_msg( mrc, 2048 );
4256 while( 1 ) {
4257 if( whid < 0 ) {
4258 whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004259 if( RMR_WH_CONNECTED( wh ) ) {
E. Scott Daniels392168d2019-11-06 15:12:38 -05004260 snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
4261 sbuf->len = strlen( sbuf->payload );
4262 sbuf = rmr_wh_send_msg( mrc, whid, sbuf );
Lott, Christopher (cl778h)5157a972020-04-06 20:31:32 -04004263 }
4264 }
4265 sleep( 5 );
E. Scott Daniels392168d2019-11-06 15:12:38 -05004266 }
4267 }
4268
4269
4270
4271SEE ALSO
4272--------------------------------------------------------------------------------------------
4273
4274rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
4275rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
4276rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
4277rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004278rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3),
4279rmr_wh_state(3)
E. Scott Daniels392168d2019-11-06 15:12:38 -05004280
E. Scott Daniels4d1f9bf2020-03-06 12:29:28 -05004281
4282NAME
4283--------------------------------------------------------------------------------------------
4284
4285rmr_wh_state
4286
4287SYNOPSIS
4288--------------------------------------------------------------------------------------------
4289
4290
4291::
4292
4293 #include <rmr/rmr.h>
4294 int rmr_wh_state( void* vctx, rmr_whid_t whid )
4295
4296
4297
4298DESCRIPTION
4299--------------------------------------------------------------------------------------------
4300
4301The rmr_wh_state function will return the current state of
4302the connection associated with the given wormhole (whid). The
4303return value indicates whether the connection is open
4304(RMR_OK), or closed (any other return value).
4305
4306When using some transport mechanisms (e.g. NNG), it may not
4307be possible for RMR to know the actual state and the
4308connection may always be reported as "open."
4309
4310RETURN
4311--------------------------------------------------------------------------------------------
4312
4313The following values are potential return values.
4314
4315
4316
4317RMR_OK
4318
4319 The wormhole ID is valid and the connection is "open."
4320
4321
4322RMR_ERR_WHID
4323
4324 THe wormhole ID passed into the function was not valid.
4325
4326
4327RMR_ERR_NOENDPT
4328
4329 The wormhole is not open (not connected).
4330
4331
4332RMR_ERR_BADARG
4333
4334 The context passed to the function was nil or invalid.
4335
4336
4337RMR_ERR_NOWHOPEN
4338
4339 Wormholes have not been initialised (no wormhole open call
4340 has been made).
4341
4342
4343
4344SEE ALSO
4345--------------------------------------------------------------------------------------------
4346
4347rmr_wh_open(3), rmr_wh_send_msg(3), rmr_wh_close(3)