Add route table guide and formatting tweaks
[ric-plt/lib/rmr.git] / doc / src / man / rmr_send_msg.3.xfm
1 .if false
2 ==================================================================================
3    Copyright (c) 2019-2020 Nokia
4    Copyright (c) 2018-2020 AT&T Intellectual Property.
5
6    Licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8    You may obtain a copy of the License at
9
10        http://www.apache.org/licenses/LICENSE-2.0
11
12    Unless required by applicable law or agreed to in writing, software
13    distributed under the License is distributed on an "AS IS" BASIS,
14    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15    See the License for the specific language governing permissions and
16    limitations under the License.
17 ==================================================================================
18 .fi
19 .if false
20     Mnemonic    rmr_send_msg_man.xfm
21     Abstract    The manual page for the rmr_send_msg function.
22     Author      E. Scott Daniels
23     Date        28 January 2019
24 .fi
25
26 .gv e LIB lib
27 .im &{lib}/man/setup.im
28
29 &line_len(6i)
30
31 &h1(RMR Library Functions)
32 &h2(NAME)
33     rmr_send_msg
34
35 &h2(SYNOPSIS )
36 &indent
37 &ex_start
38 #include <rmr/rmr.h>
39
40 rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
41 &ex_end
42 &uindent
43
44 &h2(DESCRIPTION)
45 The &cw(rmr_send_msg) function accepts a message buffer from the user application
46 and attempts to send it.
47 The destination of the message is selected based on the message type specified
48 in the message buffer, and the matching information in the routing tables
49 which are currently in use by the RMR library.
50 This may actually result in the sending of the message to multiple destinations
51 which could degrade expected overall performance of the user application.
52 (Limiting excessive sending of messages is the responsibility of the application(s)
53 responsible for building the routing table used by the RMR library, and not the
54 responsibility of the library.)
55
56
57 .** pull in common retry text
58 .im &{lib}/man/retry.im
59
60
61 &h2(RETURN VALUE)
62 On success, a new message buffer, with an empty payload, is returned for the application
63 to use for the next send.
64 The state in this buffer will reflect the overall send operation state and will be
65 &cw(RMR_OK) when the send was successful.
66
67 &space
68 When the message cannot be successfully sent this function will return the unsent (original)
69 message buffer with the state set to indicate the reason for failure.
70 The value of &ital(errno) may also be set to reflect a more detailed failure reason if it
71 is known.
72
73 &space
74 In the event of extreme failure, a nil pointer is returned. In this case the value of
75 &cw(errno) might be of some use, for documentation, but there will be little that the
76 user application can do other than to move on.
77
78 .sp 1
79 &bold(CAUTION^:)
80 In some cases it is extremely likely that the message returned by the send function
81 does  &bold(not) reference the same memory structure.
82 Thus is important for the user programme to capture the new pointer for future use
83 or to be passed to &cw(rmr_free().)
84 If you are experiencing either double free errors or segment faults in either &cw(rmr_free()) or
85 &cw(rmr_send_msg(),) ensure that the return value from this function is being captured
86 and used.
87
88 &h2(ERRORS)
89 The following values may be passed back in the &ital(state) field of the returned message
90 buffer.
91
92 &space
93 &beg_dlist(.75i : ^&bold_font )
94 &ditem(RMR_RETRY) The message could not be sent, but the underlying transport mechanism
95     indicates that the failure is temporary. If the send operation is tried again
96     it might be successful.
97 &ditem(RMR_SEND_FAILED) The send operation was not successful and the underlying transport
98     mechanism indicates a permanent (hard) failure; retrying the send is not possible.
99 &ditem(RMR_ERR_BADARG) The message buffer pointer did not refer to a valid message.
100 &ditem(RMR_ERR_NOHDR)  The header in the message buffer was not valid or corrupted.
101 &ditem(RMR_ERR_NOENDPT)  The message type in the message buffer did not map to a known endpoint.
102 &end_dlist
103
104 &space
105 The following values may be assigned to &cw(errno) on failure.
106 &beg_dlist(.75i : ^&bold_font )
107 &ditem(INVAL) Parameter(s) passed to the function were not valid, or the underlying message processing environment was unable to interpret the message.
108
109 &ditem(ENOKEY) The header information in the message buffer was invalid.
110
111 &ditem(ENXIO) No known endpoint for the message could be found.
112
113 &ditem(EMSGSIZE) The underlying transport refused to accept the message because of a size value issue (message was not attempted to be sent).
114
115 &ditem(EFAULT) The message referenced by the message buffer is corrupt (nil pointer or bad internal length).
116
117 &ditem(EBADF) Internal RMR error; information provided to the message transport environment was not valid.
118
119 &ditem(ENOTSUP) Sending was not supported by the underlying message transport.
120
121 &ditem(EFSM) The device is not in a state that can accept the message.
122
123 &ditem(EAGAIN) The device is not able to accept a message for sending. The user application should attempt to resend.
124
125 &ditem(EINTR) The operation was interrupted by delivery of a signal before the message was sent.
126
127 &ditem(ETIMEDOUT) The underlying message environment timed out during the send process.
128
129 &ditem(ETERM) The underlying message environment is in a shutdown state.
130 &end_dlist
131
132 &h2(EXAMPLE)
133 The following is a simple example of how the &cw(rmr_send_msg) function is called.
134 In this example, the send message buffer is saved between calls and reused
135 eliminating alloc/free cycles.
136
137 &space
138 &ex_start
139     static rmr_mbuf_t*  send_msg = NULL;        // message to send; reused on each call
140     msg_t*  send_pm;                            // payload for send
141     msg_t*  pm;                                 // our message format in the received payload
142
143     if( send_msg  == NULL ) {
144         send_msg = rmr_alloc_msg( mr, MAX_SIZE ); // new buffer to send
145     }
146
147     // reference payload and fill in message type
148     pm = (msg_t*) send_msg->payload;
149     send_msg->mtype = MT_ANSWER;
150
151     msg->len = generate_data( pm );       // something that fills the payload in
152     msg = rmr_send_msg( mr, send_msg );   // ensure new pointer used after send
153     if( ! msg ) {
154         return ERROR;
155     } else {
156         if( msg->state != RMR_OK ) {
157             // check for RMR_ERR_RETRY, and resend if needed
158             // else return error
159         }
160     }
161     return OK;
162
163 &ex_end
164
165
166 &h2(SEE ALSO )
167 .ju off
168 rmr_alloc_msg(3),
169 rmr_call(3),
170 rmr_free_msg(3),
171 rmr_init(3),
172 rmr_payload_size(3),
173 rmr_rcv_msg(3),
174 rmr_rcv_specific(3),
175 rmr_rts_msg(3),
176 rmr_ready(3),
177 rmr_mk_ring(3),
178 rmr_ring_free(3),
179 rmr_torcv_rcv(3),
180 rmr_wh_send_msg(3)
181 .ju on
182