blob: ad62076622c6c9057876d6a89994d9ee68f26bba [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
12The RIC Message Router (RMR) is a library which applications
13use to send and receive messages where the message routing,
14endpoint selection, is based on the message type rather than
15on traditional DNS names or IP addresses. Because the user
16documentation for RMR is a collection of UNIX manpages
E. Scott Danielsb7a4b522019-11-07 15:35:17 -050017(included in the development package, and available via the
E. Scott Daniels392168d2019-11-06 15:12:38 -050018man command when installed), there is no separate "User's
E. Scott Danielsb7a4b522019-11-07 15:35:17 -050019Guide." To provide something for the document scrapers to
E. Scott Daniels392168d2019-11-06 15:12:38 -050020find, this is a collection of the RMR manual pages formatted
21directly from their source which might be a bit ragged when
22combined into a single markup document. Read the manual pages
23:)
24
25
26
27NAME
28--------------------------------------------------------------------------------------------
29
30rmr_alloc_msg
31
32SYNOPSIS
33--------------------------------------------------------------------------------------------
34
35
36::
37
38 #include <rmr/rmr.h>
39 rmr_mbuf_t* rmr_alloc_msg( void* ctx, int size );
40
41
42
43DESCRIPTION
44--------------------------------------------------------------------------------------------
45
46The rmr_alloc_msg function is used to allocate a buffer which
47the user programme can write into and then send through the
48RMR library. The buffer is allocated such that sending it
49requires no additional copying out of the buffer. If the
50value passed in size is 0, then the default size supplied on
51the *rmr_init* call will be used. The *ctx* parameter is the
52void context pointer that was returned by the *rmr_init*
53function.
54
55The pointer to the message buffer returned is a structure
56which has some user application visible fields; the structure
57is described in rmr.h, and is illustrated below.
58
59
60::
61
62 typedef struct {
63 int state;
64 int mtype;
65 int len;
66 unsigned char* payload;
67 unsigned char* xaction;
68 uint sub_id;
69 uint tp_state;
70 } rmr_mbuf_t;
71
72
73
74
75
76state
77
78 Is the current buffer state. Following a call to
79 rmr_send_msg the state indicates whether the buffer was
80 successfully sent which determines exactly what the
81 payload points to. If the send failed, the payload
82 referenced by the buffer is the message that failed to
83 send (allowing the application to attempt a
84 retransmission). When the state is RMR_OK the buffer
85 represents an empty buffer that the application may fill
86 in in preparation to send.
87
88
89mtype
90
91 When sending a message, the application is expected to set
92 this field to the appropriate message type value (as
93 determined by the user programme). Upon send this value
94 determines how the RMR library will route the message. For
95 a buffer which has been received, this field will contain
96 the message type that was set by the sending application.
97
98
99len
100
101 The application using a buffer to send a message is
102 expected to set the length value to the actual number of
103 bytes that it placed into the message. This is likely less
104 than the total number of bytes that the message can carry.
105 For a message buffer that is passed to the application as
106 the result of a receive call, this will be the value that
107 the sending application supplied and should indicate the
108 number of bytes in the payload which are valid.
109
110
111payload
112
113 The payload is a pointer to the actual received data. The
114 user programme may read and write from/to the memory
115 referenced by the payload up until the point in time that
116 the buffer is used on a rmr_send, rmr_call or rmr_reply
117 function call. Once the buffer has been passed back to a
118 RMR library function the user programme should **NOT**
119 make use of the payload pointer.
120
121
122xaction
123
124 The *xaction* field is a pointer to a fixed sized area in
125 the message into which the user may write a transaction
126 ID. The ID is optional with the exception of when the user
127 application uses the rmr_call function to send a message
128 and wait for the reply; the underlying RMR processing
129 expects that the matching reply message will also contain
130 the same data in the *xaction* field.
131
132
133
134sub_id
135
136 This value is the subscription ID. It, in combination with
137 the message type is used by rmr to determine the target
138 endpoint when sending a message. If the application to
139 application protocol does not warrant the use of a
140 subscription ID, the RMR constant RMR_VOID_SUBID should be
141 placed in this field. When an application is forwarding or
142 returning a buffer to the sender, it is the application's
143 responsibility to set/reset this value.
144
145
146tp_state
147
148 For C applications making use of RMR, the state of a
149 transport based failure will often be available via errno.
150 However, some wrapper environments may not have direct access
151 to the C-lib errno value. RMR send and receive operations
152 will place the current value of errno into this field which
153 should make it available to wrapper functions. User
154 applications are strongly cautioned against relying on the
155 value of errno as some transport mechanisms may not set this
156 value on all calls. This value should also be ignored any
157 time the message status is RMR_OK.
158
159
160RETURN VALUE
161--------------------------------------------------------------------------------------------
162
163The function returns a pointer to a rmr_mbuf structure, or NULL
164on error.
165
166ERRORS
167--------------------------------------------------------------------------------------------
168
169
170
171ENOMEM
172
173 Unable to allocate memory.
174
175
176SEE ALSO
177--------------------------------------------------------------------------------------------
178
179rmr_tralloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
180rmr_init_trace(3), rmr_get_trace(3), rmr_get_trlen(3),
181rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
182rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), rmr_fib(3),
183rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
184rmr_ring_free(3), rmr_set_trace(3)
185
186
187NAME
188--------------------------------------------------------------------------------------------
189
190rmr_bytes2meid
191
192SYNOPSIS
193--------------------------------------------------------------------------------------------
194
195
196::
197
198 #include <rmr/rmr.h>
199 int rmr_bytes2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
200
201
202
203DESCRIPTION
204--------------------------------------------------------------------------------------------
205
206The rmr_bytes2meid function will copy up to *len* butes from
E. Scott Daniels190665f2019-12-09 09:05:22 -0500207*src* to the managed entity ID (meid) field in the message.
208The field is a fixed length, gated by the constant
E. Scott Daniels392168d2019-11-06 15:12:38 -0500209RMR_MAX_MEID and if len is larger than this value, only
210RMR_MAX_MEID bytes will actually be copied.
211
212RETURN VALUE
213--------------------------------------------------------------------------------------------
214
215On success, the actual number of bytes copied is returned, or
216-1 to indicate a hard error. If the length is less than 0, or
217not the same as length passed in, errno is set to one of the
218errors described in the *Errors* section.
219
220ERRORS
221--------------------------------------------------------------------------------------------
222
223If the returned length does not match the length passed in,
224errno will be set to one of the following constants with the
225meaning listed below.
226
227
228
229EINVAL
230
231 The message, or an internal portion of the message, was
232 corrupted or the pointer was invalid.
233
234
235EOVERFLOW
236
237 The length passed in was larger than the maximum length of
238 the field; only a portion of the source bytes were copied.
239
240
241EXAMPLE
242--------------------------------------------------------------------------------------------
243
244
245SEE ALSO
246--------------------------------------------------------------------------------------------
247
248rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_call(3),
249rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_meid(3),
250rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
251rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
252rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
253rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
254rmr_wh_open(3), rmr_wh_send_msg(3)
255
256
257NAME
258--------------------------------------------------------------------------------------------
259
260rmr_bytes2payload
261
262SYNOPSIS
263--------------------------------------------------------------------------------------------
264
265
266::
267
268 #include <rmr/rmr.h>
269 void rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char* src, int len )
270
271
272
273DESCRIPTION
274--------------------------------------------------------------------------------------------
275
276This is a convenience function as some wrapper languages
277might not have the ability to directly copy into the payload
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500278buffer. The bytes from *src* for the length given are copied
279to the payload. It is the caller's responsibility to ensure
280that the payload is large enough. Upon successfully copy, the
281len field in the message buffer is updated to reflect the
282number of bytes copied.
E. Scott Daniels392168d2019-11-06 15:12:38 -0500283
284There is little error checking, and no error reporting.
285
286RETURN VALUE
287--------------------------------------------------------------------------------------------
288
289None.
290
291EXAMPLE
292--------------------------------------------------------------------------------------------
293
294
295SEE ALSO
296--------------------------------------------------------------------------------------------
297
298rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2payload(3),
299rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
300rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
301rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
302rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
303rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
304rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
305
306
307NAME
308--------------------------------------------------------------------------------------------
309
310rmr_bytes2xact
311
312SYNOPSIS
313--------------------------------------------------------------------------------------------
314
315
316::
317
318 #include <rmr/rmr.h>
319 int rmr_bytes2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
320
321
322
323DESCRIPTION
324--------------------------------------------------------------------------------------------
325
326The rmr_bytes2xact function will copy up to *len* butes from
327*src* to the transaction ID (xaction) field in the message.
328The field is a fixed length, gated by the constant
329RMR_MAX_XID and if len is larger than this value, only
330RMR_MAX_XID bytes will actually be copied.
331
332
333RETURN VALUE
334--------------------------------------------------------------------------------------------
335
336On success, the actual number of bytes copied is returned,
337or -1 to indicate a hard error. If the length is less than
3380, or not the same as length passed in, errno is set to
339one of the errors described in the *Errors* section.
340
341ERRORS
342--------------------------------------------------------------------------------------------
343
344If the returned length does not match the length passed
345in, errno will be set to one of the following constants
346with the meaning listed below.
347
348
349EINVAL
350
351 The message, or an internal portion of the message, was
352 corrupted or the pointer was invalid.
353
354
355EOVERFLOW
356
357 The length passed in was larger than the maximum length of
358 the field; only a portion of the source bytes were copied.
359
360
361EXAMPLE
362--------------------------------------------------------------------------------------------
363
364
365SEE ALSO
366--------------------------------------------------------------------------------------------
367
368rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_call(3),
369rmr_free_msg(3), rmr_get_meid(3), rmr_get_rcvfd(3),
370rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
371rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
372rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
373rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
374rmr_wh_open(3), rmr_wh_send_msg(3)
375
376
377NAME
378--------------------------------------------------------------------------------------------
379
380rmr_call
381
382SYNOPSIS
383--------------------------------------------------------------------------------------------
384
385
386::
387
388 #include <rmr/rmr.h>
389 extern rmr_mbuf_t* rmr_call( void* vctx, rmr_mbuf_t* msg );
390
391
392
393DESCRIPTION
394--------------------------------------------------------------------------------------------
395
396The rmr_call function sends the user application message to a
397remote endpoint, and waits for a corresponding response
398message before returning control to the user application. The
399user application supplies a completed message buffer, as it
400would for a rmr_send call, but unlike with the send, the
401buffer returned will have the response from the application
402that received the message.
403
404Messages which are received while waiting for the response
405are queued internally by RMR, and are returned to the user
406application when rmr_rcv_msg is invoked. These messages are
407returned in th order received, one per call to rmr_rcv_msg.
408
409Call Timeout
410~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
411
412The rmr_call function implements a timeout failsafe to
413prevent, in most cases, the function from blocking forever.
414The timeout period is **not** based on time (calls to clock
415are deemed too expensive for a low latency system level
416library, but instead the period is based on the number of
417received messages which are not the response. Using a
418non-time mechanism for *timeout* prevents the async queue
419from filling (which would lead to message drops) in an
420environment where there is heavy message traffic.
421
422When the threshold number of messages have been queued
423without receiving a response message, control is returned to
424the user application and a NULL pointer is returned to
425indicate that no message was received to process. Currently
426the threshold is fixed at 20 messages, though in future
427versions of the library this might be extended to be a
428parameter which the user application may set.
429
430Retries
431~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
432
433The send operations in RMr will retry *soft* send failures
434until one of three conditions occurs:
435
436
437
4381.
439
440 The message is sent without error
441
442
4432.
444
445 The underlying transport reports a * hard * failure
446
447
4483.
449
450 The maximum number of retry loops has been attempted
451
452
453A retry loop consists of approximately 1000 send attemps **
454without** any intervening calls to * sleep() * or * usleep().
455* The number of retry loops defaults to 1, thus a maximum of
4561000 send attempts is performed before returning to the user
457application. This value can be set at any point after RMr
458initialisation using the * rmr_set_stimeout() * function
459allowing the user application to completely disable retires
460(set to 0), or to increase the number of retry loops.
461
462Transport Level Blocking
463~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
464
465The underlying transport mechanism used to send messages is
466configured in *non-blocking* mode. This means that if a
467message cannot be sent immediately the transport mechanism
468will **not** pause with the assumption that the inability to
469send will clear quickly (within a few milliseconds). This
470means that when the retry loop is completely disabled (set to
4710), that the failure to accept a message for sending by the
472underlying mechanisms (software or hardware) will be reported
473immediately to the user application.
474
475It should be noted that depending on the underlying transport
476mechanism being used, it is extremly possible that during
477normal operations that retry conditions are very likely to
478happen. These are completely out of RMr's control, and there
479is nothing that RMr can do to avoid or midigate these other
480than by allowing RMr to retry the send operation, and even
481then it is possible (e.g. during connection reattempts), that
482a single retry loop is not enough to guarentee a successful
483send.
484
485RETURN VALUE
486--------------------------------------------------------------------------------------------
487
488The rmr_call function returns a pointer to a message buffer
489with the state set to reflect the overall state of call
490processing (see Errors below). In some cases a NULL pointer
491will be returned; when this is the case only *errno* will be
492available to describe the reason for failure.
493
494ERRORS
495--------------------------------------------------------------------------------------------
496
497These values are reflected in the state field of the returned
498message.
499
500
501
502RMR_OK
503
504 The call was successful and the message buffer references
505 the response message.
506
507
508RMR_ERR_CALLFAILED
509
510 The call failed and the value of *errno,* as described
511 below, should be checked for the specific reason.
512
513
514The global "variable" *errno* will be set to one of the
515following values if the overall call processing was not
516successful.
517
518
519
520ETIMEDOUT
521
522 Too many messages were queued before receiving the
523 expected response
524
525
526ENOBUFS
527
528 The queued message ring is full, messages were dropped
529
530
531EINVAL
532
533 A parameter was not valid
534
535
536EAGAIN
537
538 The underlying message system wsa interrupted or the
539 device was busy; the message was **not** sent, and user
540 application should call this function with the message
541 again.
542
543
544EXAMPLE
545--------------------------------------------------------------------------------------------
546
547The following code bit shows one way of using the rmr_call
548function, and illustrates how the transaction ID must be set.
549
550
551::
552
553 int retries_left = 5; // max retries on dev not available
554 int retry_delay = 50000; // retry delay (usec)
555 static rmr_mbuf_t* mbuf = NULL; // response msg
556 msg_t* pm; // private message (payload)
557 m// get a send buffer and reference the payload
558 mbuf = rmr_alloc_msg( mr, RMR_MAX_RCV_BYTES );
559 pm = (msg_t*) mbuf->payload;
560 p// generate an xaction ID and fill in payload with data and msg type
561 snprintf( mbuf->xaction, RMR_MAX_XID, "%s", gen_xaction() );
562 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
563 mbuf->mtype = MT_REQ;
564
565 msg = rmr_call( mr, msg );
566 if( ! msg ) { // probably a timeout and no msg received
567 return NULL; // let errno trickle up
568 }
569 if( mbuf->state != RMR_OK ) {
570 while( retries_left-- > 0 && // loop as long as eagain
571 errno == EAGAIN &&
572 (msg = rmr_call( mr, msg )) != NULL &&
573 mbuf->state != RMR_OK ) {
574 usleep( retry_delay );
575 }
576
577 if( mbuf == NULL || mbuf->state != RMR_OK ) {
578 rmr_free_msg( mbuf ); // safe if nil
579 return NULL;
580 }
581 }
582 // do something with mbuf
583
584
585
586SEE ALSO
587--------------------------------------------------------------------------------------------
588
589rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
590rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
591rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
592rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
593rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
594
595
596NAME
597--------------------------------------------------------------------------------------------
598
599rmr_wh_open
600
601SYNOPSIS
602--------------------------------------------------------------------------------------------
603
604
605::
606
607 #include <rmr/rmr.h>
608 void rmr_close( void* vctx )
609
610
611
612DESCRIPTION
613--------------------------------------------------------------------------------------------
614
615The rmr_close function closes the listen socket effectively
616cutting the application off. The route table listener is also
617stopped. Calls to rmr_rcv_msg() will fail with unpredictable
618error codes, and calls to rmr_send_msg(), rmr_call(), and
619rmr_rts_msg() will have unknown results.
620
621
622SEE ALSO
623--------------------------------------------------------------------------------------------
624
625rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
626rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
627rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
628rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
629rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
630rmr_wh_send_msg(3)
631
632
633NAME
634--------------------------------------------------------------------------------------------
635
636rmr_free_msg
637
638SYNOPSIS
639--------------------------------------------------------------------------------------------
640
641
642::
643
644 #include <rmr/rmr.h>
645 void rmr_free_msg( rmr_mbuf_t* mbuf );
646
647
648
649DESCRIPTION
650--------------------------------------------------------------------------------------------
651
652The message buffer is returned to the pool, or the associated
653memory is released depending on the needs of the underlying
654messaging system. This allows the user application to release
655a buffer that is not going to be used. It is safe to pass a
656nil pointer to this function, and doing so does not result in
657a change to the value of errrno.
658
659After calling, the user application should **not** use any of
660the pointers (transaction ID, or payload) which were
661available.
662
663SEE ALSO
664--------------------------------------------------------------------------------------------
665
666rmr_alloc_msg(3), rmr_call(3), rmr_init(3),
667rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
668rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
669rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
670rmr_ring_free(3)
671
672
673NAME
674--------------------------------------------------------------------------------------------
675
676rmr_get_meid
677
678SYNOPSIS
679--------------------------------------------------------------------------------------------
680
681
682::
683
684 #include <rmr/rmr.h>
685 char* rmr_get_meid( rmr_mbuf_t* mbuf, unsigned char* dest )
686
687
688
689DESCRIPTION
690--------------------------------------------------------------------------------------------
691
E. Scott Daniels190665f2019-12-09 09:05:22 -0500692The rmr_get_meid function will copy the managed entity ID
E. Scott Daniels392168d2019-11-06 15:12:38 -0500693(meid) field from the message into the *dest* buffer provided
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500694by the user. The buffer referenced by *dest* is assumed to be
695at least RMR_MAX_MEID bytes in length. If *dest* is NULL,
696then a buffer is allocated (the calling application is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500697expected to free when the buffer is no longer needed).
698
699RETURN VALUE
700--------------------------------------------------------------------------------------------
701
702On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500703*dest* was supplied, then this is just a pointer to the
704caller's buffer. If *dest* was NULL, this is a pointer to the
705allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -0500706returned and errno is set as described below.
707
708ERRORS
709--------------------------------------------------------------------------------------------
710
711If an error occurs, the value of the global variable errno
712will be set to one of the following with the indicated
713meaning.
714
715
716
717EINVAL
718
719 The message, or an internal portion of the message, was
720 corrupted or the pointer was invalid.
721
722
723ENOMEM
724
E. Scott Danielsb7a4b522019-11-07 15:35:17 -0500725 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -0500726 possible to allocate a buffer using malloc().
727
728
729SEE ALSO
730--------------------------------------------------------------------------------------------
731
732rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
733rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
734rmr_get_xact(3), rmr_payload_size(3), rmr_send_msg(3),
735rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
736rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
737rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
738rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
739
740
741NAME
742--------------------------------------------------------------------------------------------
743
744rmr_get_rcvfd
745
746SYNOPSIS
747--------------------------------------------------------------------------------------------
748
749
750::
751
752 #include <rmr/rmr.h>
753 void* rmr_get_rcvfd( void* ctx )
754
755
756
757DESCRIPTION
758--------------------------------------------------------------------------------------------
759
760The rmr_get_rcvfd function returns a file descriptor which
761may be given to epoll_wait() by an application that wishes to
762use event poll in a single thread rather than block on the
763arrival of a message via calls to rmr_rcv_msg(). When
764epoll_wait() indicates that this file descriptor is ready, a
765call to rmr_rcv_msg() will not block as at least one message
766has been received.
767
768The context (ctx) pointer passed in is the pointer returned
769by the call to rmr_init().
770
771**NOTE:** There is no support for epoll in Nanomsg, thus his
772function is only supported when linking with the NNG version
773of RMr and the file descriptor returned when using the
774Nanomsg verfsion will always return an error.
775
776RETURN VALUE
777--------------------------------------------------------------------------------------------
778
779The rmr_get_rcvfd function returns a file descriptor greater
780or equal to 0 on success and -1 on error. If this function is
781called from a user application linked against the Nanomsg RMr
782library, calls will always return -1 with errno set to
783EINVAL.
784
785ERRORS
786--------------------------------------------------------------------------------------------
787
788The following error values are specifically set by this RMR
789function. In some cases the error message of a system call is
790propagated up, and thus this list might be incomplete.
791
792
793EINVAL
794
795 The use of this function is invalid in this environment.
796
797
798EXAMPLE
799--------------------------------------------------------------------------------------------
800
801The following short code bit illustrates the use of this
802function. Error checking has been omitted for clarity.
803
804
805::
806
807 #include <stdio.h>
808 #include <stdlib.h>
809 #include <sys/epoll.h>
810 #include <rmr/rmr.h>
811 int main() {
812 int rcv_fd; // pollable fd
813 void* mrc; //msg router context
814 struct epoll_event events[10]; // support 10 events to poll
815 struct epoll_event epe; // event definition for event to listen to
816 int ep_fd = -1;
817 rmr_mbuf_t* msg = NULL;
818 int nready;
819 int i;
820
821 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
822 rcv_fd = rmr_get_rcvfd( mrc );
823
824 rep_fd = epoll_create1( 0 ); _ B ,// initialise epoll environment
825 epe.events = EPOLLIN;
826 epe.data.fd = rcv_fd;
827 epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ); // add our info to the mix
828
829 while( 1 ) {
830 nready = epoll_wait( ep_fd, events, 10, -1 ); // -1 == block forever (no timeout)
831 for( i = 0; i < nready && i < 10; i++ ) { // loop through to find what is ready
832 if( events[i].data.fd == rcv_fd ) { // RMr has something
833 msg = rmr_rcv_msg( mrc, msg );
834 if( msg ) {
835 // do something with msg
836 }
837 }
838
839 // check for other ready fds....
840 }
841 }
842 }
843
844
845
846SEE ALSO
847--------------------------------------------------------------------------------------------
848
849rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
850rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
851rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
852rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
853rmr_ring_free(3)
854
855
856NAME
857--------------------------------------------------------------------------------------------
858
859rmr_get_src
860
861SYNOPSIS
862--------------------------------------------------------------------------------------------
863
864
865::
866
867 #include <rmr/rmr.h>
868 unsigned char* rmr_get_src( rmr_mbuf_t* mbuf, unsigned char* dest )
869
870
871
872DESCRIPTION
873--------------------------------------------------------------------------------------------
874
875The rmr_get_src function will copy the *source* information
876from the message to a buffer (dest) supplied by the user. In
877an RMr message, the source is the sender's information that
878is used for return to sender function calls, and is generally
879the hostname and port in the form *name*. The source might be
880an IP address port combination; the data is populated by the
881sending process and the only requirement is that it be
882capable of being used to start a TCP session with the sender.
883
884The maximum size allowed by RMr is 64 bytes (including the
885nil string terminator), so the user must ensure that the
886destination buffer given is at least 64 bytes.
887
888RETURN VALUE
889--------------------------------------------------------------------------------------------
890
891On success, a pointer to the destination buffer is given as a
892convenience to the user programme. On failure, a nil pointer
893is returned and the value of errno is set.
894
895ERRORS
896--------------------------------------------------------------------------------------------
897
898If an error occurs, the value of the global variable errno
899will be set to one of the following with the indicated
900meaning.
901
902
903
904EINVAL
905
906 The message, or an internal portion of the message, was
907 corrupted or the pointer was invalid.
908
909
910SEE ALSO
911--------------------------------------------------------------------------------------------
912
913rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
914rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
915rmr_get_srcip(3), rmr_payload_size(3), rmr_send_msg(3),
916rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
917rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
918rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
919rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
920
921
922NAME
923--------------------------------------------------------------------------------------------
924
925rmr_get_srcip
926
927SYNOPSIS
928--------------------------------------------------------------------------------------------
929
930
931::
932
933 #include <rmr/rmr.h>
934 unsigned char* rmr_get_srcip( rmr_mbuf_t* mbuf, unsigned char* dest )
935
936
937
938DESCRIPTION
939--------------------------------------------------------------------------------------------
940
941The rmr_get_srcip function will copy the *source IP address*
942from the message to a buffer (dest) supplied by the user. In
943an RMr message, the source IP address is the sender's
944information that is used for return to sender function calls;
945this function makes it available to the user application. The
946address is maintained as IP:port where *IP* could be either
947an IPv6 or IPv4 address depending on what was provided by the
948sending application.
949
950The maximum size allowed by RMr is 64 bytes (including the
951nil string terminator), so the user must ensure that the
952destination buffer given is at least 64 bytes. The user
953application should use the RMr constant RMR_MAX_SRC to ensure
954that the buffer supplied is large enough, and to protect
955against future RMr enhancements which might increase the
956address buffer size requirement.
957
958RETURN VALUE
959--------------------------------------------------------------------------------------------
960
961On success, a pointer to the destination buffer is given as a
962convenience to the user programme. On failure, a nil pointer
963is returned and the value of errno is set.
964
965ERRORS
966--------------------------------------------------------------------------------------------
967
968If an error occurs, the value of the global variable errno
969will be set to one of the following with the indicated
970meaning.
971
972
973
974EINVAL
975
976 The message, or an internal portion of the message, was
977 corrupted or the pointer was invalid.
978
979
980SEE ALSO
981--------------------------------------------------------------------------------------------
982
983rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
984rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
985rmr_get_src(3), rmr_payload_size(3), rmr_send_msg(3),
986rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
987rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
988rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
989rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
990
991
992NAME
993--------------------------------------------------------------------------------------------
994
995rmr_get_trace
996
997SYNOPSIS
998--------------------------------------------------------------------------------------------
999
1000
1001::
1002
1003 #include <rmr/rmr.h>
1004 int rmr_get_trace( rmr_mbuf_t* mbuf, unsigned char* dest, int size )
1005
1006
1007
1008DESCRIPTION
1009--------------------------------------------------------------------------------------------
1010
1011The rmr_get_trace function will copy the trace information
1012from the message into the user's allocated memory referenced
1013by dest. The size parameter is assumed to be the maximum
1014number of bytes which can be copied (size of the destination
1015buffer).
1016
1017RETURN VALUE
1018--------------------------------------------------------------------------------------------
1019
1020On success, the number of bytes actually copied is returned.
1021If the return value is 0, no bytes copied, then the reason
1022could be that the message pointer was nil, or the size
1023parameter was <= 0.
1024
1025SEE ALSO
1026--------------------------------------------------------------------------------------------
1027
1028rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
1029rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
1030rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
1031rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
1032rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1033rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1034rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1035rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
1036rmr_set_trace(3), rmr_trace_ref(3)
1037
1038
1039NAME
1040--------------------------------------------------------------------------------------------
1041
1042rmr_get_trlen
1043
1044SYNOPSIS
1045--------------------------------------------------------------------------------------------
1046
1047
1048::
1049
1050 #include <rmr/rmr.h>
1051 int rmr_get_trlen( rmr_mbuf_t* msg );
1052
1053
1054
1055DESCRIPTION
1056--------------------------------------------------------------------------------------------
1057
1058Given a message buffer, this function returns the amount of
1059space (bytes) that have been allocated for trace data. If no
1060trace data has been allocated, then 0 is returned.
1061
1062RETURN VALUE
1063--------------------------------------------------------------------------------------------
1064
1065The number of bytes allocated for trace information in the
1066given message.
1067
1068ERRORS
1069--------------------------------------------------------------------------------------------
1070
1071
1072
1073INVAL
1074
1075 Parameter(s) passed to the function were not valid.
1076
1077
1078SEE ALSO
1079--------------------------------------------------------------------------------------------
1080
1081rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1082rmr_get_trace(3), rmr_init(3), rmr_init_trace(3),
1083rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
1084rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1085rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
1086rmr_set_trace(3), rmr_tralloc_msg(3)
1087
1088
1089NAME
1090--------------------------------------------------------------------------------------------
1091
1092rmr_get_xact
1093
1094SYNOPSIS
1095--------------------------------------------------------------------------------------------
1096
1097
1098::
1099
1100 #include <rmr/rmr.h>
1101 char* rmr_get_xact( rmr_mbuf_t* mbuf, unsigned char* dest )
1102
1103
1104
1105DESCRIPTION
1106--------------------------------------------------------------------------------------------
1107
1108The rmr_get_xact function will copy the transaction field
1109from the message into the *dest* buffer provided by the user.
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001110The buffer referenced by *dest* is assumed to be at least
1111RMR_MAX_XID bytes in length. If *dest* is NULL, then a buffer
1112is allocated (the calling application is expected to free
1113when the buffer is no longer needed).
E. Scott Daniels392168d2019-11-06 15:12:38 -05001114
1115RETURN VALUE
1116--------------------------------------------------------------------------------------------
1117
1118On success, a pointer to the extracted string is returned. If
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001119*dest* was supplied, then this is just a pointer to the
1120caller's buffer. If *dest* was NULL, this is a pointer to the
1121allocated buffer. If an error occurs, a nil pointer is
E. Scott Daniels392168d2019-11-06 15:12:38 -05001122returned and errno is set as described below.
1123
1124ERRORS
1125--------------------------------------------------------------------------------------------
1126
1127If an error occurs, the value of the global variable errno
1128will be set to one of the following with the indicated
1129meaning.
1130
1131
1132
1133EINVAL
1134
1135 The message, or an internal portion of the message, was
1136 corrupted or the pointer was invalid.
1137
1138
1139ENOMEM
1140
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001141 A nil pointer was passed for *dest,* however it was not
E. Scott Daniels392168d2019-11-06 15:12:38 -05001142 possible to allocate a buffer using malloc().
1143
1144
1145SEE ALSO
1146--------------------------------------------------------------------------------------------
1147
1148rmr_alloc_msg(3), rmr_bytes2xact(3), rmr_bytes2meid(3),
1149rmr_call(3), rmr_free_msg(3), rmr_get_rcvfd(3),
1150rmr_get_meid(3), rmr_payload_size(3), rmr_send_msg(3),
1151rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1152rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1153rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
1154rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3)
1155
1156
1157NAME
1158--------------------------------------------------------------------------------------------
1159
1160rmr_init
1161
1162SYNOPSIS
1163--------------------------------------------------------------------------------------------
1164
1165
1166::
1167
1168 #include <rmr/rmr.h>
1169 void* rmr_init( char* proto_port, int max_msg_size, int flags );
1170
1171
1172
1173DESCRIPTION
1174--------------------------------------------------------------------------------------------
1175
1176The rmr_init function prepares the environment for sending
1177and receiving messages. It does so by establishing a worker
1178thread (pthread) which subscribes to a route table generator
1179which provides the necessary routing information for the RMR
1180library to send messages.
1181
1182*Port* is used to listen for connection requests from other
1183RMR based applications. The value of *max_msg_size* will be
1184used when allocating zero copy send buffers which must be
1185allocated, possibly, prior to the application knowing the
1186actual size of a specific message.
1187
1188*Flags* allows for selection of some RMr options at the time
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001189of initialisation. These are set by ORing RMRFL constants
E. Scott Daniels392168d2019-11-06 15:12:38 -05001190from the RMr header file. Currently the following flags are
1191supported:
1192
1193
1194
1195RMRFL_NONE
1196
1197 No flags are set.
1198
1199
1200RMRFL_NOTHREAD
1201
1202 The route table collector thread is not to be started.
1203 This should only be used by the route table generator
1204 application if it is based on RMr.
1205
1206
1207RMRFL_MTCALL
1208
1209 Enable multi-threaded call support.
1210
1211
1212Multi-threaded Calling
1213~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1214
1215The support for an application to issue a *blocking call* by
1216the rmr_call() function was limited such that only user
1217applications which were operating in a single thread could
1218safely use the function. Further, timeouts were message count
1219based and not time unit based. Multi-threaded call support
1220adds the ability for a user application with multiple threads
1221to invoke a blocking call function with the guarentee that
1222the correct response message is delivered to the thread. The
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001223additional support is implemented with the *rmr_mt_call()*
1224and *rmr_mt_rcv()* function calls.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001225
1226Multi-threaded call support requires the user application to
1227specifically enable it when RMr is initialised. This is
1228necessary because a second, dedicated, receiver thread must
1229be started, and requires all messages to be examined and
1230queued by this thread. The additional overhead is minimal,
1231queuing information is all in the RMr message header, but as
1232an additional process is necessary the user application must
1233"opt in" to this approach.
1234
1235
1236ENVIRONMENT
1237--------------------------------------------------------------------------------------------
1238
1239As a part of the initialisation process rmr_init will look
1240into the available environment variables to influence it's
1241setup. The following variables will be used when found.
1242
1243
1244
1245RMR_SEED_RT
1246
1247 Assumes this is the filename of the seed route table file
1248 to use. In normal situations, the library will wait for an
1249 update from the route table generator (expected within a
1250 few seconds of initialisation) before being able to send
1251 messages. However, in some situations where a bootstrap
1252 table is necessary, this is the means to supply it to the
1253 library.
1254
1255
1256RMR_RTG_SVC
1257
1258 The route table generator assumes that RMr is listening on
1259 a well known port (4561) by default, but this environment
1260 variable can be used to change the listening port if
1261 needed. The value of the variable is expected to be just
1262 the port.
1263
1264
1265RETURN VALUE
1266--------------------------------------------------------------------------------------------
1267
1268The rmr_init function returns a void pointer (a contex if you
1269will) that is passed as the first parameter to nearly all
1270other RMR functions. If rmr_init is unable to properly
1271initialise the environment, NULL is returned and errno is set
1272to an appropriate value.
1273
1274ERRORS
1275--------------------------------------------------------------------------------------------
1276
1277The following error values are specifically set by this RMR
1278function. In some cases the error message of a system call is
1279propagated up, and thus this list might be incomplete.
1280
1281
1282ENOMEM
1283
1284 Unable to allocate memory.
1285
1286
1287EXAMPLE
1288--------------------------------------------------------------------------------------------
1289
1290
1291::
1292
1293 void* uh;
1294 rmr_mbuf* buf = NULL;
1295 uh = rmr_init( "43086", 4096, 0 );
1296 buf = rmr_rcv_msg( uh, buf );
1297
1298
1299
1300SEE ALSO
1301--------------------------------------------------------------------------------------------
1302
1303rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1304rmr_get_rcvfd(3), rmr_mt_call(3), rmr_mt_rcv(3),
1305rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
1306rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
1307rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
1308rmr_ring_free(3)
1309
1310
1311NAME
1312--------------------------------------------------------------------------------------------
1313
1314rmr_init_trace
1315
1316SYNOPSIS
1317--------------------------------------------------------------------------------------------
1318
1319
1320::
1321
1322 #include <rmr/rmr.h>
1323 void* rmr_init_trace( void* ctx )
1324
1325
1326
1327DESCRIPTION
1328--------------------------------------------------------------------------------------------
1329
1330The rmr_init_trace function establishes the default trace
1331space placed in each message buffer allocated with
1332rmr_alloc_msg(). If this function is never called, then no
1333trace space is allocated by default into any message buffer.
1334
1335Trace space allows the user application to pass some trace
1336token, or other data with the message, but outside of the
1337payload. Trace data may be added to any message with
1338rmr_set_trace(), and may be extracted from a message with
1339rmr_get_trace(). The number of bytes that a message contains
1340for/with trace data can be determined by invoking
1341rmr_get_trlen().
1342
1343This function may be safely called at any time during the
1344life of the user programme to (re)set the default trace space
1345reserved. If the user programme needs to allocate a message
1346with trace space of a different size than is allocated by
1347default, without fear of extra overhead of reallocating a
1348message later, the rmr_tralloc_msg() function can be used.
1349
1350RETURN VALUE
1351--------------------------------------------------------------------------------------------
1352
1353A value of 1 is returned on success, and 0 on failure. A
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001354failure indicates that the RMr context (a void pointer passed
1355to this function was not valid.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001356
1357SEE ALSO
1358--------------------------------------------------------------------------------------------
1359
1360rmr_alloc_msg(3), rmr_tr_alloc_msg(3), rmr_call(3),
1361rmr_free_msg(3), rmr_get_rcvfd(3), rmr_get_trace(3),
1362rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
1363rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1364rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
1365rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
1366
1367
1368NAME
1369--------------------------------------------------------------------------------------------
1370
1371rmr_mt_call
1372
1373SYNOPSIS
1374--------------------------------------------------------------------------------------------
1375
1376
1377::
1378
1379 #include <rmr/rmr.h>
1380 extern rmr_mbuf_t* rmr_mt_call( void* vctx, rmr_mbuf_t* msg, int id, int timeout );
1381
1382
1383
1384DESCRIPTION
1385--------------------------------------------------------------------------------------------
1386
1387The rmr_mt_call function sends the user application message
1388to a remote endpoint, and waits for a corresponding response
1389message before returning control to the user application. The
1390user application supplies a completed message buffer, as it
1391would for a rmr_send_msg call, but unlike with a send, the
1392buffer returned will have the response from the application
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001393that received the message. The thread invoking the
1394*rmr_mt_call()* will block until a message arrives or until
E. Scott Daniels392168d2019-11-06 15:12:38 -05001395*timeout* milliseconds has passed; which ever comes first.
1396Using a timeout value of zero (0) will cause the thread to
1397block without a timeout.
1398
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001399The *id* supplied as the third parameter is an integer in the
1400range of 2 through 255 inclusive. This is a caller defined
1401"thread number" and is used to match the response message
1402with the correct user application thread. If the ID value is
1403not in the proper range, the attempt to make the call will
1404fail.
E. Scott Daniels392168d2019-11-06 15:12:38 -05001405
1406Messages which are received while waiting for the response
1407are queued on a *normal* receive queue and will be delivered
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001408to the user application with the next invocation of
1409*rmr_mt_rcv()* or *rmr_rvv_msg().* by RMR, and are returned
E. Scott Daniels392168d2019-11-06 15:12:38 -05001410to the user application when rmr_rcv_msg is invoked. These
1411messages are returned in th order received, one per call to
1412rmr_rcv_msg.
1413
1414NOTE: Currently the multi-threaded functions are supported
1415only when the NNG transport mechanism is being used. It will
1416not be possible to link a programme using the Nanomsg version
1417of the library when references to this function are present.
1418
1419The Transaction ID
1420~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1421
1422The user application is responsible for setting the value of
1423the transaction ID field before invoking *rmr_mt_call.* The
1424transaction ID is a RMR_MAX_XID byte field that is used to
1425match the response message when it arrives. RMr will compare
1426**all** of the bytes in the field, so the caller must ensure
1427that they are set correctly to avoid missing the response
1428message. (The application which returns the response message
1429is also expected to ensure that the return buffer has the
1430matching transaction ID. This can be done transparently if
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001431the application uses the *rmr_rts_msg()* function and does
E. Scott Daniels392168d2019-11-06 15:12:38 -05001432not adjust the transaction ID.
1433
1434Retries
1435~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1436
1437The send operations in RMr will retry *soft* send failures
1438until one of three conditions occurs:
1439
1440
1441
14421.
1443
1444 The message is sent without error
1445
1446
14472.
1448
1449 The underlying transport reports a * hard * failure
1450
1451
14523.
1453
1454 The maximum number of retry loops has been attempted
1455
1456
1457A retry loop consists of approximately 1000 send attemps **
1458without** any intervening calls to * sleep() * or * usleep().
1459* The number of retry loops defaults to 1, thus a maximum of
14601000 send attempts is performed before returning to the user
1461application. This value can be set at any point after RMr
1462initialisation using the * rmr_set_stimeout() * function
1463allowing the user application to completely disable retires
1464(set to 0), or to increase the number of retry loops.
1465
1466Transport Level Blocking
1467~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1468
1469The underlying transport mechanism used to send messages is
1470configured in *non-blocking* mode. This means that if a
1471message cannot be sent immediately the transport mechanism
1472will **not** pause with the assumption that the inability to
1473send will clear quickly (within a few milliseconds). This
1474means that when the retry loop is completely disabled (set to
14750), that the failure to accept a message for sending by the
1476underlying mechanisms (software or hardware) will be reported
1477immediately to the user application.
1478
1479It should be noted that depending on the underlying transport
1480mechanism being used, it is extremly possible that during
1481normal operations that retry conditions are very likely to
1482happen. These are completely out of RMr's control, and there
1483is nothing that RMr can do to avoid or midigate these other
1484than by allowing RMr to retry the send operation, and even
1485then it is possible (e.g. during connection reattempts), that
1486a single retry loop is not enough to guarentee a successful
1487send.
1488
1489RETURN VALUE
1490--------------------------------------------------------------------------------------------
1491
1492The rmr_mt_call function returns a pointer to a message
1493buffer with the state set to reflect the overall state of
1494call processing. If the state is RMR_OK then the buffer
1495contains the response message; otherwise the state indicates
1496the error encountered while attempting to send the message.
1497
1498If no response message is received when the timeout period
1499has expired, a nil pointer will be returned (NULL).
1500
1501ERRORS
1502--------------------------------------------------------------------------------------------
1503
1504These values are reflected in the state field of the returned
1505message.
1506
1507
1508
1509RMR_OK
1510
1511 The call was successful and the message buffer references
1512 the response message.
1513
1514
1515RMR_ERR_BADARG
1516
1517 An argument passed to the function was invalid.
1518
1519
1520RMR_ERR_CALLFAILED
1521
1522 The call failed and the value of *errno,* as described
1523 below, should be checked for the specific reason.
1524
1525
1526RMR_ERR_NOENDPT
1527
1528 An endpoint associated with the message type could not be
1529 found in the route table.
1530
1531
1532RMR_ERR_RETRY
1533
1534 The underlying transport mechanism was unable to accept
1535 the message for sending. The user application can retry
1536 the call operation if appropriate to do so.
1537
1538
1539The global "variable" *errno* will be set to one of the
1540following values if the overall call processing was not
1541successful.
1542
1543
1544
1545ETIMEDOUT
1546
1547 Too many messages were queued before receiving the
1548 expected response
1549
1550
1551ENOBUFS
1552
1553 The queued message ring is full, messages were dropped
1554
1555
1556EINVAL
1557
1558 A parameter was not valid
1559
1560
1561EAGAIN
1562
1563 The underlying message system wsa interrupted or the
1564 device was busy; the message was **not** sent, and user
1565 application should call this function with the message
1566 again.
1567
1568
1569EXAMPLE
1570--------------------------------------------------------------------------------------------
1571
1572The following code bit shows one way of using the rmr_mt_call
1573function, and illustrates how the transaction ID must be set.
1574
1575
1576::
1577
1578 int retries_left = 5; // max retries on dev not available
1579 static rmr_mbuf_t* mbuf = NULL; // response msg
1580 msg_t* pm; // private message (payload)
1581 m// get a send buffer and reference the payload
1582 mbuf = rmr_alloc_msg( mr, RMR_MAX_RCV_BYTES );
1583 pm = (msg_t*) mbuf->payload;
1584 p// generate an xaction ID and fill in payload with data and msg type
1585 rmr_bytes2xact( mbuf, xid, RMR_MAX_XID );
1586 snprintf( pm->req, sizeof( pm->req ), "{ \\"req\\": \\"num users\\"}" );
1587 mbuf->mtype = MT_USR_RESP;
1588
1589 msg = rmr_mt_call( mr, msg, my_id, 100 ); e :// wait up to 100ms
1590 if( ! msg ) { // probably a timeout and no msg received
1591 return NULL; // let errno trickle up
1592 }
1593 if( mbuf->state != RMR_OK ) {
1594 while( retries_left-- > 0 && // loop as long as eagain
1595 mbuf->state == RMR_ERR_RETRY &&
1596 (msg = rmr_mt_call( mr, msg )) != NULL &&
1597 mbuf->state != RMR_OK ) {
1598 usleep( retry_delay );
1599 }
1600
1601 if( mbuf == NULL || mbuf->state != RMR_OK ) {
1602 rmr_free_msg( mbuf ); // safe if nil
1603 return NULL;
1604 }
1605 }
1606 // do something with mbuf
1607
1608
1609
1610SEE ALSO
1611--------------------------------------------------------------------------------------------
1612
1613rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
1614rmr_mt_rcv(3), rmr_payload_size(3), rmr_send_msg(3),
1615rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1616rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1617rmr_set_stimeout(3), rmr_tokenise(3), rmr_mk_ring(3),
1618rmr_ring_free(3)
1619
1620
1621NAME
1622--------------------------------------------------------------------------------------------
1623
1624rmr_mt_rcv
1625
1626SYNOPSIS
1627--------------------------------------------------------------------------------------------
1628
1629
1630::
1631
1632 #include <rmr/rmr.h>
1633 rmr_mbuf_t* rmr_mt_rcv( void* vctx, rmr_mbuf_t* old_msg, int timeout );
1634
1635
1636
1637DESCRIPTION
1638--------------------------------------------------------------------------------------------
1639
1640The rmr_mt_rcv function blocks until a message is received,
1641or the timeout period (milliseconds) has passed. The result
1642is an RMr message buffer which references a received message.
1643In the case of a timeout the state will be reflected in an
1644"empty buffer" (if old_msg was not nil, or simply with the
1645return of a nil pointer. If a timeout value of zero (0) is
1646given, then the function will block until the next message
1647received.
1648
1649The *vctx* pointer is the pointer returned by the rmr_init
1650function. *Old_msg* is a pointer to a previously used message
1651buffer or NULL. The ability to reuse message buffers helps to
1652avoid alloc/free cycles in the user application. When no
1653buffer is available to supply, the receive function will
1654allocate one.
1655
1656The *old_msg* parameter allows the user to pass a previously
1657generated RMr message back to RMr for reuse. Optionally, the
1658user application may pass a nil pointer if no reusable
1659message is available. When a timeout occurs, and old_msg was
1660not nil, the state will be returned by returning a pointer to
1661the old message with the state set.
1662
1663It is possible to use the *rmr_rcv_msg()* function instead of
1664this function. Doing so might be advantagous if the user
1665programme does not always start the multi-threaded mode and
1666the use of *rmr_rcv_msg()* would make the flow of the code
1667more simple. The advantags of using this function are the
1668ability to set a timeout without using epoll, and a small
1669performance gain (if multi-threaded mode is enabled, and the
1670*rmr_rcv_msg()* function is used, it simply invokes this
1671function without a timeout value, thus there is the small
1672cost of a second call that results). Similarly, the
1673*rmr_torcv_msg()* call can be used when in multi-threaded
1674mode with the same "pass through" overhead to using this
1675function directly.
1676
1677NOTE: Currently the multi-threaded functions are supported
1678only when the NNG transport mechanism is being used. It will
1679not be possible to link a programme using the nanomsg version
1680of the library when references to this function are present.
1681
1682RETURN VALUE
1683--------------------------------------------------------------------------------------------
1684
1685When a message is received before the timeout period expires,
1686a pointer to the RMr message buffer which describes the
1687message is returned. This will, with a high probability, be a
1688different message buffer than *old_msg;* the user application
1689should not continue to use *old_msg* after it is passed to
1690this function.
1691
1692In the event of a timeout the return value will be the old
1693msg with the state set, or a nil pointer if no old message
1694was provided.
1695
1696ERRORS
1697--------------------------------------------------------------------------------------------
1698
1699The *state* field in the message buffer will be set to one of
1700the following values:
1701
1702
1703
1704RMR_OK
1705
1706 The message was received without error.
1707
1708
1709RMR_ERR_BADARG
1710
1711 A parameter passed to the function was not valid (e.g. a
1712 nil pointer). indicate either RMR_OK or RMR_ERR_EMPTY if
1713 an empty message was received.
1714
1715
1716RMR_ERR_EMPTY
1717
1718 The message received had no associated data. The length of
1719 the message will be 0.
1720
1721
1722RMR_ERR_NOTSUPP
1723
1724 The multi-threaded option was not enabled when RMr was
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05001725 initialised. See the man page for *rmr_init()* for
E. Scott Daniels392168d2019-11-06 15:12:38 -05001726 details.
1727
1728
1729RMR_ERR_RCVFAILED
1730
1731 A hard error occurred preventing the receive from
1732 completing.
1733
1734When a nil pointer is returned, or any other state value was
1735set in the message buffer, errno will be set to one of the
1736following:
1737
1738
1739
1740INVAL
1741
1742 Parameter(s) passed to the function were not valid.
1743
1744
1745EBADF
1746
1747 The underlying message transport is unable to process the
1748 request.
1749
1750
1751ENOTSUP
1752
1753 The underlying message transport is unable to process the
1754 request.
1755
1756
1757EFSM
1758
1759 The underlying message transport is unable to process the
1760 request.
1761
1762
1763EAGAIN
1764
1765 The underlying message transport is unable to process the
1766 request.
1767
1768
1769EINTR
1770
1771 The underlying message transport is unable to process the
1772 request.
1773
1774
1775ETIMEDOUT
1776
1777 The underlying message transport is unable to process the
1778 request.
1779
1780
1781ETERM
1782
1783 The underlying message transport is unable to process the
1784 request.
1785
1786
1787EXAMPLE
1788--------------------------------------------------------------------------------------------
1789
1790
1791
1792::
1793
1794 rmr_mbuf_t* mbuf = NULL; // received msg
1795 msg = rmr_mt_recv( mr, mbuf, 100 ); // wait up to 100ms
1796 if( msg != NULL ) {
1797 switch( msg->state ) {
1798 case RMR_OK:
1799 printf( "got a good message\\n" );
1800 break;
1801 case RMR_ERR_EMPTY:
1802 printf( "received timed out\\n" );
1803 break;
1804 default:
1805 printf( "receive error: %d\\n", mbuf->state );
1806 break;
1807 }
1808 } else {
1809 printf( "receive timeout (nil)\\n" );
1810 }
1811
1812
1813
1814SEE ALSO
1815--------------------------------------------------------------------------------------------
1816
1817rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1818rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
1819rmr_mt_call(3), rmr_payload_size(3), rmr_send_msg(3),
1820rmr_torcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
1821rmr_ready(3), rmr_ring_free(3), rmr_torcv_msg(3)
1822
1823
1824NAME
1825--------------------------------------------------------------------------------------------
1826
1827rmr_payload_size
1828
1829SYNOPSIS
1830--------------------------------------------------------------------------------------------
1831
1832
1833::
1834
1835 #include <rmr/rmr.h>
1836 int rmr_payload_size( rmr_mbuf_t* msg );
1837
1838
1839
1840DESCRIPTION
1841--------------------------------------------------------------------------------------------
1842
1843Given a message buffer, this function returns the amount of
1844space (bytes) available for the user application to consume
1845in the message payload. This is different than the message
1846length available as a field in the message buffer.
1847
1848RETURN VALUE
1849--------------------------------------------------------------------------------------------
1850
1851The number of bytes available in the payload.
1852
1853ERRORS
1854--------------------------------------------------------------------------------------------
1855
1856
1857
1858INVAL
1859
1860 Parameter(s) passed to the function were not valid.
1861
1862
1863SEE ALSO
1864--------------------------------------------------------------------------------------------
1865
1866rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
1867rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
1868rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
1869rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
1870
1871
1872NAME
1873--------------------------------------------------------------------------------------------
1874
1875rmr_rcv_msg
1876
1877SYNOPSIS
1878--------------------------------------------------------------------------------------------
1879
1880
1881::
1882
1883 #include <rmr/rmr.h>
1884 rmr_mbuf_t* rmr_rcv_msg( void* vctx, rmr_mbuf_t* old_msg );
1885
1886
1887
1888DESCRIPTION
1889--------------------------------------------------------------------------------------------
1890
1891The rmr_rcv_msg function blocks until a message is received,
1892returning the message to the caller via a pointer to a
1893rmr_mbuf_t structure type. If messages were queued while
1894waiting for the response to a previous invocation of
1895rmr_call, the oldest message is removed from the queue and
1896returned without delay.
1897
1898The *vctx* pointer is the pointer returned by the rmr_init
1899function. *Old_msg* is a pointer to a previously used message
1900buffer or NULL. The ability to reuse message buffers helps to
1901avoid alloc/free cycles in the user application. When no
1902buffer is available to supply, the receive function will
1903allocate one.
1904
1905RETURN VALUE
1906--------------------------------------------------------------------------------------------
1907
1908The function returns a pointer to the rmr_mbuf_t structure
1909which references the message information (state, length,
1910payload), or a NULL pointer in the case of an extreme error.
1911
1912ERRORS
1913--------------------------------------------------------------------------------------------
1914
1915The *state* field in the message buffer will indicate either
1916RMR_OK or RMR_ERR_EMPTY if an empty message was received. If
1917a nil pointer is returned, or any other state value was set
1918in the message buffer, errno will be set to one of the
1919following:
1920
1921
1922
1923INVAL
1924
1925 Parameter(s) passed to the function were not valid.
1926
1927
1928EBADF
1929
1930 The underlying message transport is unable to process the
1931 request.
1932
1933
1934ENOTSUP
1935
1936 The underlying message transport is unable to process the
1937 request.
1938
1939
1940EFSM
1941
1942 The underlying message transport is unable to process the
1943 request.
1944
1945
1946EAGAIN
1947
1948 The underlying message transport is unable to process the
1949 request.
1950
1951
1952EINTR
1953
1954 The underlying message transport is unable to process the
1955 request.
1956
1957
1958ETIMEDOUT
1959
1960 The underlying message transport is unable to process the
1961 request.
1962
1963
1964ETERM
1965
1966 The underlying message transport is unable to process the
1967 request.
1968
1969
1970EXAMPLE
1971--------------------------------------------------------------------------------------------
1972
1973
1974SEE ALSO
1975--------------------------------------------------------------------------------------------
1976
1977rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
1978rmr_get_rcvfd(3), rmr_init(3), rmr_mk_ring(3),
1979rmr_payload_size(3), rmr_send_msg(3), rmr_torcv_msg(3),
1980rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
1981rmr_ring_free(3), rmr_torcv_msg(3)
1982
1983
1984NAME
1985--------------------------------------------------------------------------------------------
1986
1987rmr_ready
1988
1989SYNOPSIS
1990--------------------------------------------------------------------------------------------
1991
1992
1993::
1994
1995 #include <rmr/rmr.h>
1996 int rmr_ready( void* vctx );
1997
1998
1999
2000DESCRIPTION
2001--------------------------------------------------------------------------------------------
2002
2003The rmr_ready function checks to see if a routing table has
2004been successfully received and installed. The return value
2005indicates the state of readiness.
2006
2007RETURN VALUE
2008--------------------------------------------------------------------------------------------
2009
2010A return value of 1 (true) indicates that the routing table
2011is in place and attempts to send messages can be made. When 0
2012is returned (false) the routing table has not been received
2013and thus attempts to send messages will fail with *no
2014endpoint* errors.
2015
2016SEE ALSO
2017--------------------------------------------------------------------------------------------
2018
2019rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2020rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2021rmr_rcv_specific(3), rmr_rts_msg(3), rmr_fib(3),
2022rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
2023rmr_ring_free(3)
2024
2025
2026NAME
2027--------------------------------------------------------------------------------------------
2028
2029rmr_realloc_payload
2030
2031SYNOPSIS
2032--------------------------------------------------------------------------------------------
2033
2034
2035::
2036
2037 #include <rmr/rmr.h>
2038 extern rmr_mbuf_t* rmr_realloc_payload( rmr_mbuf_t* msg, int new_len, int copy, int clone );
2039
2040
2041
2042DESCRIPTION
2043--------------------------------------------------------------------------------------------
2044
2045The rmr_realloc_payload function will return a pointer to an
2046RMR message buffer struct (rmr_mbuf_t) which has a payload
2047large enough to accomodate *new_len* bytes. If necessary, the
2048underlying payload is reallocated, and the bytes from the
2049original payload are copied if the *copy* parameter is true
2050(1). If the message passed in has a payload large enough,
2051there is no additional memory allocation and copying.
2052
2053Cloning The Message Buffer
2054~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2055
2056This function can also be used to generate a separate copy of
2057the original message, with the desired payload size, without
2058destroying the original message buffer or the original
2059payload. A standalone copy is made only when the *clone*
2060parameter is true (1). When cloning, the payload is copied to
2061the cloned message **only** if the *copy* parameter is true.
2062
2063Message Buffer Metadata
2064~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2065
2066The metadata in the original message buffer (message type,
2067subscription ID, and payload length) will be preserved if the
2068*copy* parameter is true. When this parameter is not true
2069(0), then these values are set to the uninitialised value
2070(-1) for type and ID, and the length is set to 0.
2071
2072RETURN VALUE
2073--------------------------------------------------------------------------------------------
2074
2075The rmr_realloc_payload function returns a pointer to the
2076message buffer with the payload which is large enough to hold
2077*new_len* bytes. If the *clone* option is true, this will be
2078a pointer to the newly cloned message buffer; the original
2079message buffer pointer may still be used to referenced that
2080message. It is the calling application's responsibility to
2081free the memory associateed with both messages using the
2082rmr_free_msg() function.
2083
2084When the *clone* option is not used, it is still good
2085practice by the calling application to capture and use this
2086reference as it is possible that the message buffer, and not
2087just the payload buffer, was reallocated. In the event of an
2088error, a nil pointer will be returned and the value of
2089*errno* will be set to reflect the problem.
2090
2091ERRORS
2092--------------------------------------------------------------------------------------------
2093
2094These value of *errno* will reflect the error condition if a
2095nil pointer is returned:
2096
2097
2098
2099ENOMEM
2100
2101 Memory allocation of the new payload failed.
2102
2103
2104EINVAL
2105
2106 The pointer passed in was nil, or refrenced an invalid
2107 message, or the required length was not valid.
2108
2109
2110EXAMPLE
2111--------------------------------------------------------------------------------------------
2112
2113The following code bit illustrates how this function can be
2114used to reallocate a buffer for a return to sender
2115acknowledgement message which is larger than the message
2116received.
2117
2118
2119::
2120
2121 if( rmr_payload_size( msg ) < ack_sz ) { // received message too small for ack
2122 msg = rmr_realloc_payload( msg, ack_sz, 0, 0 ); // reallocate the message with a payload big enough
2123 if( msg == NULL ) {
2124 fprintf( stderr, "[ERR] realloc returned a nil pointer: %s\\n", strerror( errno ) );
2125 } else {
2126 } e// populate and send ack message
2127 }}
2128 }
2129
2130
2131
2132SEE ALSO
2133--------------------------------------------------------------------------------------------
2134
2135rmr_alloc_msg(3), rmr_free_msg(3), rmr_init(3),
2136rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2137rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2138rmr_fib(3), rmr_has_str(3), rmr_set_stimeout(3),
2139rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
2140
2141
2142NAME
2143--------------------------------------------------------------------------------------------
2144
2145rmr_rts_msg
2146
2147SYNOPSIS
2148--------------------------------------------------------------------------------------------
2149
2150
2151::
2152
2153 #include <rmr/rmr.h>
2154 rmr_mbuf_t* rmr_rts_msg( void* vctx, rmr_mbuf_t* msg );
2155
2156
2157
2158DESCRIPTION
2159--------------------------------------------------------------------------------------------
2160
2161The rmr_rts_msg function sends a message returning it to the
2162endpoint which sent the message rather than selecting an
2163endpoint based on the message type and routing table. Other
2164than this small difference, the behaviour is exactly the same
2165as rmr_send_msg.
2166
2167Retries
2168~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2169
2170The send operations in RMr will retry *soft* send failures
2171until one of three conditions occurs:
2172
2173
2174
21751.
2176
2177 The message is sent without error
2178
2179
21802.
2181
2182 The underlying transport reports a * hard * failure
2183
2184
21853.
2186
2187 The maximum number of retry loops has been attempted
2188
2189
2190A retry loop consists of approximately 1000 send attemps **
2191without** any intervening calls to * sleep() * or * usleep().
2192* The number of retry loops defaults to 1, thus a maximum of
21931000 send attempts is performed before returning to the user
2194application. This value can be set at any point after RMr
2195initialisation using the * rmr_set_stimeout() * function
2196allowing the user application to completely disable retires
2197(set to 0), or to increase the number of retry loops.
2198
2199Transport Level Blocking
2200~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2201
2202The underlying transport mechanism used to send messages is
2203configured in *non-blocking* mode. This means that if a
2204message cannot be sent immediately the transport mechanism
2205will **not** pause with the assumption that the inability to
2206send will clear quickly (within a few milliseconds). This
2207means that when the retry loop is completely disabled (set to
22080), that the failure to accept a message for sending by the
2209underlying mechanisms (software or hardware) will be reported
2210immediately to the user application.
2211
2212It should be noted that depending on the underlying transport
2213mechanism being used, it is extremly possible that during
2214normal operations that retry conditions are very likely to
2215happen. These are completely out of RMr's control, and there
2216is nothing that RMr can do to avoid or midigate these other
2217than by allowing RMr to retry the send operation, and even
2218then it is possible (e.g. during connection reattempts), that
2219a single retry loop is not enough to guarentee a successful
2220send.
2221
2222PAYLOAD SIZE
2223--------------------------------------------------------------------------------------------
2224
2225When crafting a response based on a received message, the
2226user application must take care not to write more bytes to
2227the message payload than the allocated message has. In the
2228case of a received message, it is possible that the response
2229needs to be larger than the payload associated with the
2230inbound message. In order to use the return to sender
2231function, the source infomration in the orignal message must
2232be present in the response; information which cannot be added
2233to a message buffer allocated through the standard RMR
2234allocation function. To allocate a buffer with a larger
2235payload, and which retains the necessary sender data needed
2236by this function, the *rmr_realloc_payload()* function must
2237be used to extend the payload to a size suitable for the
2238response.
2239
2240RETURN VALUE
2241--------------------------------------------------------------------------------------------
2242
2243On success, a new message buffer, with an empty payload, is
2244returned for the application to use for the next send. The
2245state in this buffer will reflect the overall send operation
2246state and should be RMR_OK.
2247
2248If the state in the returned buffer is anything other than
2249UT_OK, the user application may need to attempt a
2250retransmission of the message, or take other action depending
2251on the setting of errno as described below.
2252
2253In the event of extreme failure, a NULL pointer is returned.
2254In this case the value of errno might be of some use, for
2255documentation, but there will be little that the user
2256application can do other than to move on.
2257
2258ERRORS
2259--------------------------------------------------------------------------------------------
2260
2261The following values may be passed back in the *state* field
2262of the returned message buffer.
2263
2264
2265
2266RMR_ERR_BADARG
2267
2268 The message buffer pointer did not refer to a valid
2269 message.
2270
2271RMR_ERR_NOHDR
2272
2273 The header in the message buffer was not valid or
2274 corrupted.
2275
2276RMR_ERR_NOENDPT
2277
2278 The message type in the message buffer did not map to a
2279 known endpoint.
2280
2281RMR_ERR_SENDFAILED
2282
2283 The send failed; errno has the possible reason.
2284
2285
2286The following values may be assigned to errno on failure.
2287
2288
2289INVAL
2290
2291 Parameter(s) passed to the function were not valid, or the
2292 underlying message processing environment was unable to
2293 interpret the message.
2294
2295
2296ENOKEY
2297
2298 The header information in the message buffer was invalid.
2299
2300
2301ENXIO
2302
2303 No known endpoint for the message could be found.
2304
2305
2306EMSGSIZE
2307
2308 The underlying transport refused to accept the message
2309 because of a size value issue (message was not attempted
2310 to be sent).
2311
2312
2313EFAULT
2314
2315 The message referenced by the message buffer is corrupt
2316 (NULL pointer or bad internal length).
2317
2318
2319EBADF
2320
2321 Internal RMR error; information provided to the message
2322 transport environment was not valid.
2323
2324
2325ENOTSUP
2326
2327 Sending was not supported by the underlying message
2328 transport.
2329
2330
2331EFSM
2332
2333 The device is not in a state that can accept the message.
2334
2335
2336EAGAIN
2337
2338 The device is not able to accept a message for sending.
2339 The user application should attempt to resend.
2340
2341
2342EINTR
2343
2344 The operation was interrupted by delivery of a signal
2345 before the message was sent.
2346
2347
2348ETIMEDOUT
2349
2350 The underlying message environment timed out during the
2351 send process.
2352
2353
2354ETERM
2355
2356 The underlying message environment is in a shutdown state.
2357
2358
2359EXAMPLE
2360--------------------------------------------------------------------------------------------
2361
2362
2363SEE ALSO
2364--------------------------------------------------------------------------------------------
2365
2366rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2367rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2368rmr_rcv_specific(3), rmr_ready(3), rmr_fib(3),
2369rmr_has_str(3), rmr_set_stimeout(3), rmr_tokenise(3),
2370rmr_mk_ring(3), rmr_ring_free(3)
2371
2372
2373NAME
2374--------------------------------------------------------------------------------------------
2375
2376rmr_send_msg
2377
2378SYNOPSIS
2379--------------------------------------------------------------------------------------------
2380
2381
2382::
2383
2384 #include <rmr/rmr.h>
2385 rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
2386
2387
2388
2389DESCRIPTION
2390--------------------------------------------------------------------------------------------
2391
2392The rmr_send_msg function accepts a message buffer from the
2393user application and attempts to send it. The destination of
2394the message is selected based on the message type specified
2395in the message buffer, and the matching information in the
2396routing tables which are currently in use by the RMR library.
2397This may actually result in the sending of the message to
2398multiple destinations which could degrade expected overall
2399performance of the user application. (Limiting excessive
2400sending of messages is the responsibility of the
2401application(s) responsible for building the routing table
2402used by the RMR library, and not the responsibility of the
2403library.)
2404
2405Retries
2406~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2407
2408The send operations in RMr will retry *soft* send failures
2409until one of three conditions occurs:
2410
2411
2412
24131.
2414
2415 The message is sent without error
2416
2417
24182.
2419
2420 The underlying transport reports a * hard * failure
2421
2422
24233.
2424
2425 The maximum number of retry loops has been attempted
2426
2427
2428A retry loop consists of approximately 1000 send attemps **
2429without** any intervening calls to * sleep() * or * usleep().
2430* The number of retry loops defaults to 1, thus a maximum of
24311000 send attempts is performed before returning to the user
2432application. This value can be set at any point after RMr
2433initialisation using the * rmr_set_stimeout() * function
2434allowing the user application to completely disable retires
2435(set to 0), or to increase the number of retry loops.
2436
2437Transport Level Blocking
2438~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2439
2440The underlying transport mechanism used to send messages is
2441configured in *non-blocking* mode. This means that if a
2442message cannot be sent immediately the transport mechanism
2443will **not** pause with the assumption that the inability to
2444send will clear quickly (within a few milliseconds). This
2445means that when the retry loop is completely disabled (set to
24460), that the failure to accept a message for sending by the
2447underlying mechanisms (software or hardware) will be reported
2448immediately to the user application.
2449
2450It should be noted that depending on the underlying transport
2451mechanism being used, it is extremly possible that during
2452normal operations that retry conditions are very likely to
2453happen. These are completely out of RMr's control, and there
2454is nothing that RMr can do to avoid or midigate these other
2455than by allowing RMr to retry the send operation, and even
2456then it is possible (e.g. during connection reattempts), that
2457a single retry loop is not enough to guarentee a successful
2458send.
2459
2460RETURN VALUE
2461--------------------------------------------------------------------------------------------
2462
2463On success, a new message buffer, with an empty payload, is
2464returned for the application to use for the next send. The
2465state in this buffer will reflect the overall send operation
2466state and should be RMR_OK.
2467
2468When the message cannot be successfully sent this function
2469will return the unsent (original) message buffer with the
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002470state set to indicate the reason for failure. The value of
2471*errno* may also be set to reflect a more detailed failure
E. Scott Daniels392168d2019-11-06 15:12:38 -05002472reason if it is known.
2473
2474In the event of extreme failure, a NULL pointer is returned.
2475In this case the value of errno might be of some use, for
2476documentation, but there will be little that the user
2477application can do other than to move on.
2478
2479ERRORS
2480--------------------------------------------------------------------------------------------
2481
2482The following values may be passed back in the *state* field
2483of the returned message buffer.
2484
2485
2486
2487RMR_RETRY
2488
2489 The message could not be sent, but the underlying
2490 transport mechanism indicates that the failure is
2491 temporary. If the send operation is tried again it might
2492 be successful.
2493
2494RMR_SEND_FAILED
2495
2496 The send operation was not successful and the underlying
2497 transport mechanism indicates a permanent (hard) failure;
2498 retrying the send is not possible.
2499
2500RMR_ERR_BADARG
2501
2502 The message buffer pointer did not refer to a valid
2503 message.
2504
2505RMR_ERR_NOHDR
2506
2507 The header in the message buffer was not valid or
2508 corrupted.
2509
2510RMR_ERR_NOENDPT
2511
2512 The message type in the message buffer did not map to a
2513 known endpoint.
2514
2515
2516The following values may be assigned to errno on failure.
2517
2518
2519INVAL
2520
2521 Parameter(s) passed to the function were not valid, or the
2522 underlying message processing environment was unable to
2523 interpret the message.
2524
2525
2526ENOKEY
2527
2528 The header information in the message buffer was invalid.
2529
2530
2531ENXIO
2532
2533 No known endpoint for the message could be found.
2534
2535
2536EMSGSIZE
2537
2538 The underlying transport refused to accept the message
2539 because of a size value issue (message was not attempted
2540 to be sent).
2541
2542
2543EFAULT
2544
2545 The message referenced by the message buffer is corrupt
2546 (NULL pointer or bad internal length).
2547
2548
2549EBADF
2550
2551 Internal RMR error; information provided to the message
2552 transport environment was not valid.
2553
2554
2555ENOTSUP
2556
2557 Sending was not supported by the underlying message
2558 transport.
2559
2560
2561EFSM
2562
2563 The device is not in a state that can accept the message.
2564
2565
2566EAGAIN
2567
2568 The device is not able to accept a message for sending.
2569 The user application should attempt to resend.
2570
2571
2572EINTR
2573
2574 The operation was interrupted by delivery of a signal
2575 before the message was sent.
2576
2577
2578ETIMEDOUT
2579
2580 The underlying message environment timed out during the
2581 send process.
2582
2583
2584ETERM
2585
2586 The underlying message environment is in a shutdown state.
2587
2588
2589EXAMPLE
2590--------------------------------------------------------------------------------------------
2591
2592The following is a simple example of how the rmr_send_msg
2593function is called. In this example, the send message buffer
2594is saved between calls and reused eliminating alloc/free
2595cycles.
2596
2597
2598::
2599
2600 static rmr_mbuf_t* send_msg = NULL; // message to send; reused on each call
2601 msg_t* send_pm; // payload for send
2602 msg_t* pm; // our message format in the received payload
2603 mif( send_msg == NULL ) {
2604 send_msg = rmr_alloc_msg( mr, MAX_SIZE ); r// new buffer to send
2605 }
2606 // reference payload and fill in message type
2607 pm = (msg_t*) send_msg->payload;
2608 send_msg->mtype = MT_ANSWER;
2609 msg->len = generate_data( pm ); e// something that fills the payload in
2610 msg = rmr_send_msg( mr, send_msg );
2611 mif( ! msg ) {
2612 m !return ERROR;
2613 m} else {
2614 m sif( msg->state != RMR_OK ) {
2615 m s m// check for eagain, and resend if needed
2616 m s m// else return error
2617 m s}
2618 m}
2619 mreturn OK;
2620 m r ;
2621
2622
2623
2624SEE ALSO
2625--------------------------------------------------------------------------------------------
2626
2627rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2628rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2629rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
2630rmr_ring_free(3), rmr_torcv_rcv(3), rmr_wh_send_msg(3)
2631
2632
2633NAME
2634--------------------------------------------------------------------------------------------
2635
2636rmr_set_stimeout
2637
2638SYNOPSIS
2639--------------------------------------------------------------------------------------------
2640
2641
2642::
2643
2644 #include <rmr/rmr.h>
2645 rmr_mbuf_t* rmr_set_stimeout( void* vctx, int rloops );
2646
2647
2648
2649DESCRIPTION
2650--------------------------------------------------------------------------------------------
2651
2652The rmr_set_stimeout function sets the configuration for how
2653RMr will retry message send operations which complete with
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002654either a *timeout* or *again* completion value. (Send
E. Scott Daniels392168d2019-11-06 15:12:38 -05002655operations include all of the possible message send
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002656functions: *rmr_send_msg(), rmr_call(), rmr_rts_msg()* and
2657*rmr_wh_send_msg().* The *rloops* parameter sets the maximum
2658number of retry loops that will be attempted before giving up
2659and returning the unsuccessful state to the user application.
2660Each retry loop is approximately 1000 attempts, and RMr does
2661**not** invoke any sleep function between retries in the
2662loop; a small, 1 mu-sec, sleep is executed between loop sets
2663if the *rloops* value is greater than 1.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002664
2665
2666Disabling Retries
2667~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2668
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002669By default, the send operations will execute with an *rloop*
2670setting of 1; each send operation will attempt to resend the
2671message approximately 1000 times before giving up. If the
E. Scott Daniels392168d2019-11-06 15:12:38 -05002672user application does not want to have send operations retry
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002673when the underlying transport mechanism indicates *timeout*
2674or *again,* the application should invoke this function and
2675pass a value of 0 (zero) for *rloops.* With this setting, all
2676RMr send operations will attempt a send operation only
2677**once,** returning immediately to the caller with the state
E. Scott Daniels392168d2019-11-06 15:12:38 -05002678of that single attempt.
2679
2680RETURN VALUE
2681--------------------------------------------------------------------------------------------
2682
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002683This function returns a -1 to indicate that the *rloops*
2684value could not be set, and the value *RMR_OK* to indicate
E. Scott Daniels392168d2019-11-06 15:12:38 -05002685success.
2686
2687ERRORS
2688--------------------------------------------------------------------------------------------
2689
E. Scott Danielsb7a4b522019-11-07 15:35:17 -05002690Currently errno is **not** set by this function; the only
2691cause of a failure is an invalid context (*vctx*) pointer.
E. Scott Daniels392168d2019-11-06 15:12:38 -05002692
2693EXAMPLE
2694--------------------------------------------------------------------------------------------
2695
2696The following is a simple example of how the rmr_set_stimeout
2697function is called.
2698
2699
2700::
2701
2702 #define NO_FLAGS 0
2703 char* Oport = "43086"; // port for message router listen
2704 int rmax_size = 4096; // max message size for default allocations
2705 void* mr_context; // message router context
2706 mr_context = rmr_init( port, max_size, NO_FLAGS );
2707 if( mr_context != NULL ) {
2708 rmr_set_stimeout( mr_context, 0 ); // turn off retries
2709 }
2710
2711
2712
2713SEE ALSO
2714--------------------------------------------------------------------------------------------
2715
2716rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
2717rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2718rmr_rts_msg(3), rmr_ready(3), rmr_mk_ring(3),
2719rmr_ring_free(3), rmr_send_msg(3), rmr_torcv_rcv(3),
2720rmr_wh_send_msg(3)
2721
2722
2723NAME
2724--------------------------------------------------------------------------------------------
2725
2726rmr_set_trace
2727
2728SYNOPSIS
2729--------------------------------------------------------------------------------------------
2730
2731
2732::
2733
2734 #include <rmr/rmr.h>
2735 int rmr_bytes2payload( rmr_mbuf_t* mbuf, unsigned char* data, int len )
2736
2737
2738
2739DESCRIPTION
2740--------------------------------------------------------------------------------------------
2741
2742The rmr_set_trace function will copy len bytes from data into
2743the trace portion of mbuf. If the trace area of mbuf is not
2744the correct size, the message buffer will be reallocated to
2745ensure that enough space is available for the trace data.
2746
2747RETURN VALUE
2748--------------------------------------------------------------------------------------------
2749
2750The rmr_set_trace function returns the number of bytes
2751successfully copied to the message. If 0 is returned either
2752the message pointer was nil, or the size in the parameters
2753was <= 0.
2754
2755SEE ALSO
2756--------------------------------------------------------------------------------------------
2757
2758rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
2759rmr_bytes2payload(3), rmr_call(3), rmr_free_msg(3),
2760rmr_get_rcvfd(3), rmr_get_meid(3), rmr_get_trace(3),
2761rmr_get_trlen(3), rmr_init(3), rmr_init_trace(3),
2762rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
2763rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
2764rmr_fib(3), rmr_has_str(3), rmr_tokenise(3), rmr_mk_ring(3),
2765rmr_ring_free(3), rmr_str2meid(3), rmr_str2xact(3),
2766rmr_wh_open(3), rmr_wh_send_msg(3)
2767
2768
2769NAME
2770--------------------------------------------------------------------------------------------
2771
2772rmr_str2meid
2773
2774SYNOPSIS
2775--------------------------------------------------------------------------------------------
2776
2777
2778::
2779
2780 #include <rmr/rmr.h>
2781 int rmr_str2meid( rmr_mbuf_t* mbuf, unsigned char* src, int len )
2782
2783
2784
2785DESCRIPTION
2786--------------------------------------------------------------------------------------------
2787
2788The rmr_str2meid function will copy the string pointed to by
E. Scott Daniels190665f2019-12-09 09:05:22 -05002789src to the managed entity ID (meid) field in the given
E. Scott Daniels392168d2019-11-06 15:12:38 -05002790message. The field is a fixed length, gated by the constant
2791RMR_MAX_MEID and if string length is larger than this value,
2792then **nothing** will be copied. (Note, this differs slightly
2793from the behaviour of the lrmr_bytes2meid() function.)
2794
2795RETURN VALUE
2796--------------------------------------------------------------------------------------------
2797
2798On success, the value RMR_OK is returned. If the string
2799cannot be copied to the message, the return value will be one
2800of the errors listed below.
2801
2802ERRORS
2803--------------------------------------------------------------------------------------------
2804
2805If the return value is not RMR_OK, then it will be set to one
2806of the values below.
2807
2808
2809
2810RMR_ERR_BADARG
2811
2812 The message, or an internal portion of the message, was
2813 corrupted or the pointer was invalid.
2814
2815
2816RMR_ERR_OVERFLOW
2817
2818 The length passed in was larger than the maximum length of
2819 the field; only a portion of the source bytes were copied.
2820
2821
2822EXAMPLE
2823--------------------------------------------------------------------------------------------
2824
2825
2826SEE ALSO
2827--------------------------------------------------------------------------------------------
2828
2829rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
2830rmr_get_meid(3), rmr_get_rcvfd(3), rmr_payload_size(3),
2831rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2832rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
2833rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
2834rmr_bytes2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
2835
2836
2837NAME
2838--------------------------------------------------------------------------------------------
2839
2840rmr_str2xact
2841
2842SYNOPSIS
2843--------------------------------------------------------------------------------------------
2844
2845
2846::
2847
2848 #include <rmr/rmr.h>
2849 int rmr_str2xact( rmr_mbuf_t* mbuf, unsigned char* src, int len )
2850
2851
2852
2853DESCRIPTION
2854--------------------------------------------------------------------------------------------
2855
2856The rmr_str2xact function will copy the string pointed to by
2857src to the transaction ID (xaction) field in the given
2858message. The field is a fixed length, gated by the constant
2859RMR_MAX_XID and if string length is larger than this value,
2860then **nothing** will be copied. (Note, this differs slightly
2861from the behaviour of the lrmr_bytes2xact() function.)
2862
2863
2864RETURN VALUE
2865--------------------------------------------------------------------------------------------
2866
2867On success, the value RMR_OK is returned. If the string
2868cannot be copied to the message, the return value will be
2869one of the errors listed below.
2870
2871ERRORS
2872--------------------------------------------------------------------------------------------
2873
2874If the return value is not RMR_OK, then it will be set to
2875one of the values below.
2876
2877
2878RMR_ERR_BADARG
2879
2880 The message, or an internal portion of the message, was
2881 corrupted or the pointer was invalid.
2882
2883
2884RMR_ERR_OVERFLOW
2885
2886 The length passed in was larger than the maximum length of
2887 the field; only a portion of the source bytes were copied.
2888
2889
2890EXAMPLE
2891--------------------------------------------------------------------------------------------
2892
2893
2894SEE ALSO
2895--------------------------------------------------------------------------------------------
2896
2897rmr_alloc_msg(3), rmr_bytes2meid(3), rmr_bytes2xact(3),
2898rmr_call(3), rmr_free_msg(3), rmr_get_meid(3),
2899rmr_get_rcvfd(3), rmr_get_xact(3), rmr_payload_size(3),
2900rmr_send_msg(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
2901rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
2902rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
2903rmr_str2meid(3), rmr_wh_open(3), rmr_wh_send_msg(3)
2904
2905
2906NAME
2907--------------------------------------------------------------------------------------------
2908
2909RMR support functions
2910
2911SYNOPSIS
2912--------------------------------------------------------------------------------------------
2913
2914
2915::
2916
2917 #include <rmr/rmr.h>
2918 #include <rmr/ring_inline.h>
2919 char* rmr_fib( char* fname );
2920 int rmr_has_str( char const* buf, char const* str, char sep, int max );
2921 int rmr_tokenise( char* buf, char** tokens, int max, char sep );
2922 void* rmr_mk_ring( int size );
2923 void rmr_ring_free( void* vr );
2924 static inline void* rmr_ring_extract( void* vr )
2925 static inline int rmr_ring_insert( void* vr, void* new_data )
2926
2927
2928
2929DESCRIPTION
2930--------------------------------------------------------------------------------------------
2931
2932These functions support the RMR library, and are made
2933available to user applications as some (e.g. route table
2934generators) might need and/or want to make use of them. The
2935rmr_fib function accepts a file name and reads the entire
2936file into a single buffer. The intent is to provide an easy
2937way to load a static route table without a lot of buffered
2938I/O hoops.
2939
2940The rmr_has_str function accepts a *buffer* containing a set
2941of delimited tokens (e.g. foo,bar,goo) and returns true if
2942the target string, *str,* matches one of the tokens. The
2943*sep* parameter provides the separation character in the
2944buffer (e.g a comma) and *max* indicates the maximum number
2945of tokens to split the buffer into before checking.
2946
2947The rmr_tokenise function is a simple tokeniser which splits
2948*buf* into tokens at each occurrence of *sep*. Multiple
2949occurrences of the separator character (e.g. a,,b) result in
2950a nil token. Pointers to the tokens are placed into the
2951*tokens* array provided by the caller which is assumed to
2952have at least enough space for *max* entries.
2953
2954The rmr_mk_ring function creates a buffer ring with *size*
2955entries.
2956
2957The rmr_ring_free function accepts a pointer to a ring
2958context and frees the associated memory.
2959
2960The rmr_ring_insert and rmr_ring_extract functions are
2961provided as static inline functions via the
2962*rmr/ring_inline.h* header file. These functions both accept
2963the ring *context* returned by mk_ring, and either insert a
2964pointer at the next available slot (tail) or extract the data
2965at the head.
2966
2967RETURN VALUES
2968--------------------------------------------------------------------------------------------
2969
2970The following are the return values for each of these
2971functions.
2972
2973The rmr_fib function returns a pointer to the buffer
2974containing the contents of the file. The buffer is terminated
2975with a single nil character (0) making it a legitimate C
2976string. If the file was empty or nonexistent, a buffer with
2977an immediate nil character. If it is important to the calling
2978programme to know if the file was empty or did not exist, the
2979caller should use the system stat function call to make that
2980determination.
2981
2982The rmr_has_str function returns 1 if *buf* contains the
2983token referenced by &ita and false (0) if it does not. On
2984error, a -1 value is returned and errno is set accordingly.
2985
2986The rmr_tokenise function returns the actual number of token
2987pointers placed into *tokens*
2988
2989The rmr_mk_ring function returns a void pointer which is the
2990*context* for the ring.
2991
2992The rmr_ring_insert function returns 1 if the data was
2993successfully inserted into the ring, and 0 if the ring is
2994full and the pointer could not be deposited.
2995
2996The rmr_ring_extract will return the data which is at the
2997head of the ring, or NULL if the ring is empty.
2998
2999ERRORS
3000--------------------------------------------------------------------------------------------
3001
3002Not many of these functions set the value in errno, however
3003the value may be one of the following:
3004
3005
3006INVAL
3007
3008 Parameter(s) passed to the function were not valid.
3009
3010
3011EXAMPLE
3012--------------------------------------------------------------------------------------------
3013
3014
3015SEE ALSO
3016--------------------------------------------------------------------------------------------
3017
3018rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3019rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3),
3020rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3),
3021
3022
3023NAME
3024--------------------------------------------------------------------------------------------
3025
3026rmr_torcv_msg
3027
3028SYNOPSIS
3029--------------------------------------------------------------------------------------------
3030
3031
3032::
3033
3034 #include <rmr/rmr.h>
3035 rmr_mbuf_t* rmr_torcv_msg( void* vctx, rmr_mbuf_t* old_msg, int ms_to );
3036
3037
3038
3039DESCRIPTION
3040--------------------------------------------------------------------------------------------
3041
3042The rmr_torcv_msg function will pause for *ms_to*
3043milliseconds waiting for a message to arrive. If a message
3044arrives before the timeout expires the message buffer
3045returned will have a status of RMR_OK and the payload will
3046contain the data received. If the timeout expires before the
3047message is received, the status will have the value
3048RMR_ERR_TIMEOUT. When a received message is returned the
3049message buffer will also contain the message type and length
3050set by the sender. If messages were queued while waiting for
3051the response to a previous invocation of rmr_call, the oldest
3052message is removed from the queue and returned without delay.
3053
3054The *vctx* pointer is the pointer returned by the rmr_init
3055function. *Old_msg* is a pointer to a previously used message
3056buffer or NULL. The ability to reuse message buffers helps to
3057avoid alloc/free cycles in the user application. When no
3058buffer is available to supply, the receive function will
3059allocate one.
3060
3061RETURN VALUE
3062--------------------------------------------------------------------------------------------
3063
3064The function returns a pointer to the rmr_mbuf_t structure
3065which references the message information (state, length,
3066payload), or a NULL pointer in the case of an extreme error.
3067
3068ERRORS
3069--------------------------------------------------------------------------------------------
3070
3071The *state* field in the message buffer will be one of the
3072following:
3073
3074
3075
3076RMR_OK
3077
3078 The message buffer (payload) references the received data.
3079
3080
3081RMR_ERR_INITFAILED
3082
3083 The first call to this function must initialise an
3084 underlying system notification mechanism. On failure, this
3085 error is returned and errno will have the system error
3086 status set. If this function fails to intialise, the poll
3087 mechansim, it is likely that message receives will never
3088 be successful.
3089
3090
3091RMR_ERR_TIMEOUT
3092
3093 The timeout expired before a complete message was
3094 received. All other fields in the message buffer are not
3095 valid.
3096
3097
3098RMR_ERR_EMPTY
3099
3100 A message was received, but it had no payload. All other
3101 fields in the message buffer are not valid.
3102
3103
3104
3105
3106INVAL
3107
3108 Parameter(s) passed to the function were not valid.
3109
3110
3111EBADF
3112
3113 The underlying message transport is unable to process the
3114 request.
3115
3116
3117ENOTSUP
3118
3119 The underlying message transport is unable to process the
3120 request.
3121
3122
3123EFSM
3124
3125 The underlying message transport is unable to process the
3126 request.
3127
3128
3129EAGAIN
3130
3131 The underlying message transport is unable to process the
3132 request.
3133
3134
3135EINTR
3136
3137 The underlying message transport is unable to process the
3138 request.
3139
3140
3141ETIMEDOUT
3142
3143 The underlying message transport is unable to process the
3144 request.
3145
3146
3147ETERM
3148
3149 The underlying message transport is unable to process the
3150 request.
3151
3152
3153EXAMPLE
3154--------------------------------------------------------------------------------------------
3155
3156
3157SEE ALSO
3158--------------------------------------------------------------------------------------------
3159
3160rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3161rmr_get_rcvfd(3), rmr_init(3), rmr_payload_size(3),
3162rmr_rcv_msg(3), rmr_send_msg(3), rmr_rcv_specific(3),
3163rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3164rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3)
3165
3166
3167NAME
3168--------------------------------------------------------------------------------------------
3169
3170rmr_trace_ref
3171
3172SYNOPSIS
3173--------------------------------------------------------------------------------------------
3174
3175
3176::
3177
3178 #include <rmr/rmr.h>
3179 int rmr_trace_ref( rmr_mbuf_t* mbuf, int* sizeptr )
3180
3181
3182
3183DESCRIPTION
3184--------------------------------------------------------------------------------------------
3185
3186The rmr_trace_ref function return a pointer to the trace area
3187in the message, and optionally populate the user programme
3188supplied size integer with the trace area size, if *sizeptr*
3189is not nil.
3190
3191RETURN VALUE
3192--------------------------------------------------------------------------------------------
3193
3194On success, a void pointer to the trace area of the message
3195is returned. A nil pointer is returned if the message has no
3196trace data area allocated, or if the message itself is
3197invalid.
3198
3199SEE ALSO
3200--------------------------------------------------------------------------------------------
3201
3202rmr_alloc_msg(3), rmr_tralloc_msg(3), rmr_bytes2xact(3),
3203rmr_bytes2meid(3), rmr_call(3), rmr_free_msg(3),
3204rmr_get_rcvfd(3), rmr_get_trlen(3), rmr_init(3),
3205rmr_init_trace(3), rmr_payload_size(3), rmr_send_msg(3),
3206rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3207rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3208rmr_mk_ring(3), rmr_ring_free(3), rmr_str2meid(3),
3209rmr_str2xact(3), rmr_wh_open(3), rmr_wh_send_msg(3),
3210rmr_set_trace(3)
3211
3212
3213NAME
3214--------------------------------------------------------------------------------------------
3215
3216rmr_tralloc_msg
3217
3218SYNOPSIS
3219--------------------------------------------------------------------------------------------
3220
3221
3222::
3223
3224 #include <rmr/rmr.h>
3225 rmr_mbuf_t* rmr_tralloc_msg( void* vctx, int size,
3226 int trace_size, unsigned const char *tr_data );
3227
3228
3229
3230DESCRIPTION
3231--------------------------------------------------------------------------------------------
3232
3233The rmr_alloc_msg function is used to allocate a buffer which
3234the user programme can write into and then send through the a
3235library. The buffer is allocated such that sending it
3236requires no additional copying from the buffer as it passes
3237through the underlying transport mechanism.
3238
3239The *size* parameter is used to set the payload length in the
3240message and If it is 0, then the default size supplied on the
3241*rmr_init* call will be used. In addition to allocating the
3242payload, a space in the buffer is reserved for *trace* data
3243(tr_size bytes), and the bytes pointed to by *tr_data* are
3244copied into that portion of the message. The *vctx* parameter
3245is the void context pointer that was returned by the
3246*rmr_init* function.
3247
3248The pointer to the message buffer returned is a structure
3249which has some user application visible fields; the structure
3250is described in rmr.h, and is illustrated below.
3251
3252
3253::
3254
3255 typedef struct {
3256 int state;
3257 int mtype;
3258 int len;
3259 unsigned char* payload;
3260 unsigned char* xaction;
3261 } rmr_mbuf_t;
3262
3263
3264
3265
3266
3267state
3268
3269 Is the current buffer state. Following a call to
3270 rmr_send_msg the state indicates whether the buffer was
3271 successfully sent which determines exactly what the
3272 payload points to. If the send failed, the payload
3273 referenced by the buffer is the message that failed to
3274 send (allowing the application to attempt a
3275 retransmission). When the state is a_OK the buffer
3276 represents an empty buffer that the application may fill
3277 in in preparation to send.
3278
3279
3280mtype
3281
3282 When sending a message, the application is expected to set
3283 this field to the appropriate message type value (as
3284 determined by the user programme). Upon send this value
3285 determines how the a library will route the message. For a
3286 buffer which has been received, this field will contain
3287 the message type that was set by the sending application.
3288
3289
3290len
3291
3292 The application using a buffer to send a message is
3293 expected to set the length value to the actual number of
3294 bytes that it placed into the message. This is likely less
3295 than the total number of bytes that the message can carry.
3296 For a message buffer that is passed to the application as
3297 the result of a receive call, this will be the value that
3298 the sending application supplied and should indicate the
3299 number of bytes in the payload which are valid.
3300
3301
3302payload
3303
3304 The payload is a pointer to the actual received data. The
3305 user programme may read and write from/to the memory
3306 referenced by the payload up until the point in time that
3307 the buffer is used on a rmr_send, rmr_call or rmr_reply
3308 function call. Once the buffer has been passed back to a a
3309 library function the user programme should **NOT** make
3310 use of the payload pointer.
3311
3312
3313xaction
3314
3315 The *xaction* field is a pointer to a fixed sized area in
3316 the message into which the user may write a transaction
3317 ID. The ID is optional with the exception of when the user
3318 application uses the rmr_call function to send a message
3319 and wait for the reply; the underlying a processing
3320 expects that the matching reply message will also contain
3321 the same data in the *xaction* field.
3322
3323
3324RETURN VALUE
3325--------------------------------------------------------------------------------------------
3326
3327The function returns a pointer to a rmr_mbuf structure, or
3328NULL on error.
3329
3330ERRORS
3331--------------------------------------------------------------------------------------------
3332
3333
3334
3335ENOMEM
3336
3337 Unable to allocate memory.
3338
3339
3340SEE ALSO
3341--------------------------------------------------------------------------------------------
3342
3343rmr_alloc_msg(3), rmr_mbuf(3) rmr_call(3), rmr_free_msg(3),
3344rmr_init(3), rmr_init_trace(3), rmr_get_trace(3),
3345rmr_get_trlen(3), rmr_payload_size(3), rmr_send_msg(3),
3346rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3347rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3348rmr_mk_ring(3), rmr_ring_free(3), rmr_set_trace(3)
3349
3350
3351NAME
3352--------------------------------------------------------------------------------------------
3353
3354rmr_wh_open
3355
3356SYNOPSIS
3357--------------------------------------------------------------------------------------------
3358
3359
3360::
3361
3362 #include <rmr/rmr.h>
3363 void rmr_close( void* vctx, rmr_whid_t whid )
3364
3365
3366
3367DESCRIPTION
3368--------------------------------------------------------------------------------------------
3369
3370The rmr_wh_close function closes the wormhole associated with
3371the wormhole id passed in. Future calls to rmr_wh_send_msg
3372with this ID will fail.
3373
3374The underlying TCP connection to the remote endpoint is
3375**not** closed as this session may be reqruired for
3376regularlly routed messages (messages routed based on message
3377type). There is no way to force a TCP session to be closed at
3378this point in time.
3379
3380SEE ALSO
3381--------------------------------------------------------------------------------------------
3382
3383rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3384rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
3385rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3386rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3387rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_open(3),
3388rmr_wh_send_msg(3)
3389
3390
3391NAME
3392--------------------------------------------------------------------------------------------
3393
3394rmr_wh_open
3395
3396SYNOPSIS
3397--------------------------------------------------------------------------------------------
3398
3399
3400::
3401
3402 #include <rmr/rmr.h>
3403 void* rmr_wh_open( void* vctx, char* target )
3404
3405
3406
3407DESCRIPTION
3408--------------------------------------------------------------------------------------------
3409
3410The rmr_wh_open function creates a direct link for sending, a
3411wormhole, to another RMr based process. Sending messages
3412through a wormhole requires that the connection be
3413established overtly by the user application (via this
3414function), and that the ID returned by rmr_wh_open be passed
3415to the rmr_wh_send_msg function.
3416
3417*Target* is the *name* or *IP-address* combination of the
3418processess that the wormhole should be connected to. *Vctx*
3419is the RMr void context pointer that was returned by the
3420rmr_init function.
3421
3422When invoked, this function immediatly attempts to connect to
3423the target process. If the connection cannot be established,
3424an error is returned to the caller, and no direct messages
3425can be sent to the target. Once a wormhole is connected, the
3426underlying transport mechanism (e.g. NNG) will provide
3427reconnects should the connection be lost, however the
3428handling of messages sent when a connection is broken is
3429undetermined as each underlying transport mechanism may
3430handle buffering and retries differently.
3431
3432RETURN VALUE
3433--------------------------------------------------------------------------------------------
3434
3435The rmr_wh_open function returns a type rmr_whid_t which must
3436be passed to the rmr_wh_send_msg function when sending a
3437message. The id may also be tested to determine success or
3438failure of the connection by using the RMR_WH_CONNECTED macro
3439and passing the ID as the parameter; a result of 1 indicates
3440that the connection was esablished and that the ID is valid.
3441
3442ERRORS
3443--------------------------------------------------------------------------------------------
3444
3445The following error values are specifically set by this RMR
3446function. In some cases the error message of a system call is
3447propagated up, and thus this list might be incomplete.
3448
3449
3450EINVAL
3451
3452 A parameter passed was not valid.
3453
3454EACCESS
3455
3456 The user applicarion does not have the ability to
3457 establish a wormhole to the indicated target (or maybe any
3458 target).
3459
3460ECONNREFUSED
3461
3462 The connection was refused.
3463
3464
3465EXAMPLE
3466--------------------------------------------------------------------------------------------
3467
3468
3469::
3470
3471 void* rmc;
3472 rmr_whid_t wh;
3473 rmc = rmr_init( "43086", 4096, 0 ); // init context
3474 wh = rmr_wh_open( rmc, "localhost:6123" );
3475 if( !RMR_WH_CONNECTED( wh ) ) {
3476 f fprintf( stderr, "unable to connect wormhole: %s\\n",
3477 strerror( errno ) );
3478 }
3479
3480
3481
3482SEE ALSO
3483--------------------------------------------------------------------------------------------
3484
3485rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3),
3486rmr_get_rcvfd(3), rmr_payload_size(3), rmr_send_msg(3),
3487rmr_rcv_msg(3), rmr_rcv_specific(3), rmr_rts_msg(3),
3488rmr_ready(3), rmr_fib(3), rmr_has_str(3), rmr_tokenise(3),
3489rmr_mk_ring(3), rmr_ring_free(3), rmr_wh_send_msg(3),
3490rmr_wh_close(3)
3491
3492
3493NAME
3494--------------------------------------------------------------------------------------------
3495
3496rmr_wh_send_msg
3497
3498SYNOPSIS
3499--------------------------------------------------------------------------------------------
3500
3501
3502::
3503
3504 #include <rmr/rmr.h>
3505 rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t id, rmr_mbuf_t* msg );
3506
3507
3508
3509DESCRIPTION
3510--------------------------------------------------------------------------------------------
3511
3512The rmr_wh_send_msg function accepts a message buffer from
3513the user application and attempts to send it using the
3514wormhole ID provided (id). Unlike *rmr_send_msg,* this
3515function attempts to send the message directly to a process
3516at the other end of a wormhole which was created with
3517*rmr_wh-open().* When sending message via wormholes, the
3518normal RMr routing based on message type is ignored, and the
3519caller may leave the message type unspecified in the message
3520buffer (unless it is needed by the receiving process).
3521
3522The message buffer (msg) used to send is the same format as
3523used for regular RMr send and reply to sender operations,
3524thus any buffer allocated by these means, or calls to
3525*rmr_rcv_msg()* can be passed to this function.
3526
3527Retries
3528~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3529
3530The send operations in RMr will retry *soft* send failures
3531until one of three conditions occurs:
3532
3533
3534
35351.
3536
3537 The message is sent without error
3538
3539
35402.
3541
3542 The underlying transport reports a * hard * failure
3543
3544
35453.
3546
3547 The maximum number of retry loops has been attempted
3548
3549
3550A retry loop consists of approximately 1000 send attemps **
3551without** any intervening calls to * sleep() * or * usleep().
3552* The number of retry loops defaults to 1, thus a maximum of
35531000 send attempts is performed before returning to the user
3554application. This value can be set at any point after RMr
3555initialisation using the * rmr_set_stimeout() * function
3556allowing the user application to completely disable retires
3557(set to 0), or to increase the number of retry loops.
3558
3559Transport Level Blocking
3560~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3561
3562The underlying transport mechanism used to send messages is
3563configured in *non-blocking* mode. This means that if a
3564message cannot be sent immediately the transport mechanism
3565will **not** pause with the assumption that the inability to
3566send will clear quickly (within a few milliseconds). This
3567means that when the retry loop is completely disabled (set to
35680), that the failure to accept a message for sending by the
3569underlying mechanisms (software or hardware) will be reported
3570immediately to the user application.
3571
3572It should be noted that depending on the underlying transport
3573mechanism being used, it is extremly possible that during
3574normal operations that retry conditions are very likely to
3575happen. These are completely out of RMr's control, and there
3576is nothing that RMr can do to avoid or midigate these other
3577than by allowing RMr to retry the send operation, and even
3578then it is possible (e.g. during connection reattempts), that
3579a single retry loop is not enough to guarentee a successful
3580send.
3581
3582RETURN VALUE
3583--------------------------------------------------------------------------------------------
3584
3585On success, a new message buffer, with an empty payload, is
3586returned for the application to use for the next send. The
3587state in this buffer will reflect the overall send operation
3588state and should be RMR_OK.
3589
3590If the state in the returned buffer is anything other than
3591RMR_OK, the user application may need to attempt a
3592retransmission of the message, or take other action depending
3593on the setting of errno as described below.
3594
3595In the event of extreme failure, a NULL pointer is returned.
3596In this case the value of errno might be of some use, for
3597documentation, but there will be little that the user
3598application can do other than to move on.
3599
3600ERRORS
3601--------------------------------------------------------------------------------------------
3602
3603The following values may be passed back in the *state* field
3604of the returned message buffer.
3605
3606
3607
3608RMR_ERR_WHID
3609
3610 The wormhole ID passed in was not associated with an open
3611 wormhole, or was out of range for a valid ID.
3612
3613RMR_ERR_NOWHOPEN
3614
3615 No wormholes exist, further attempt to validate the ID are
3616 skipped.
3617
3618RMR_ERR_BADARG
3619
3620 The message buffer pointer did not refer to a valid
3621 message.
3622
3623RMR_ERR_NOHDR
3624
3625 The header in the message buffer was not valid or
3626 corrupted.
3627
3628
3629The following values may be assigned to errno on failure.
3630
3631
3632INVAL
3633
3634 Parameter(s) passed to the function were not valid, or the
3635 underlying message processing environment was unable to
3636 interpret the message.
3637
3638
3639ENOKEY
3640
3641 The header information in the message buffer was invalid.
3642
3643
3644ENXIO
3645
3646 No known endpoint for the message could be found.
3647
3648
3649EMSGSIZE
3650
3651 The underlying transport refused to accept the message
3652 because of a size value issue (message was not attempted
3653 to be sent).
3654
3655
3656EFAULT
3657
3658 The message referenced by the message buffer is corrupt
3659 (NULL pointer or bad internal length).
3660
3661
3662EBADF
3663
3664 Internal RMR error; information provided to the message
3665 transport environment was not valid.
3666
3667
3668ENOTSUP
3669
3670 Sending was not supported by the underlying message
3671 transport.
3672
3673
3674EFSM
3675
3676 The device is not in a state that can accept the message.
3677
3678
3679EAGAIN
3680
3681 The device is not able to accept a message for sending.
3682 The user application should attempt to resend.
3683
3684
3685EINTR
3686
3687 The operation was interrupted by delivery of a signal
3688 before the message was sent.
3689
3690
3691ETIMEDOUT
3692
3693 The underlying message environment timed out during the
3694 send process.
3695
3696
3697ETERM
3698
3699 The underlying message environment is in a shutdown state.
3700
3701
3702EXAMPLE
3703--------------------------------------------------------------------------------------------
3704
3705The following is a simple example of how the a wormhole is
3706created (rmr_wh_open) and then how rmr_wh_send_msg function
3707is used to send messages. Some error checking is omitted for
3708clarity.
3709
3710
3711::
3712
3713 #include <rmr/rmr.h> .// system headers omitted for clarity
3714 int main() {
3715 rmr_whid_t whid = -1; // wormhole id for sending
3716 void* mrc; //msg router context
3717 int i;
3718 rmr_mbuf_t* sbuf; // send buffer
3719 int count = 0;
3720 mrc = rmr_init( "43086", RMR_MAX_RCV_BYTES, RMRFL_NONE );
3721 if( mrc == NULL ) {
3722 fprintf( stderr, "[FAIL] unable to initialise RMr environment\\n" );
3723 exit( 1 );
3724 }
3725 while( ! rmr_ready( mrc ) ) { e i// wait for routing table info
3726 sleep( 1 );
3727 }
3728 sbuf = rmr_alloc_msg( mrc, 2048 );
3729 while( 1 ) {
3730 if( whid < 0 ) {
3731 whid = rmr_wh_open( mrc, "localhost:6123" ); // open fails if endpoint refuses conn
3732 w if( RMR_WH_CONNECTED( wh ) ) {
3733 snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
3734 sbuf->len = strlen( sbuf->payload );
3735 sbuf = rmr_wh_send_msg( mrc, whid, sbuf );
3736 }
3737 }
3738 sleep( 5 );
3739 }
3740 }
3741
3742
3743
3744SEE ALSO
3745--------------------------------------------------------------------------------------------
3746
3747rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3),
3748rmr_payload_size(3), rmr_rcv_msg(3), rmr_rcv_specific(3),
3749rmr_rts_msg(3), rmr_ready(3), rmr_fib(3), rmr_has_str(3),
3750rmr_tokenise(3), rmr_mk_ring(3), rmr_ring_free(3),
3751rmr_set_stimeout(3), rmr_wh_open(3), rmr_wh_close(3)
3752