2 ==================================================================================
3 Copyright (c) 2019 Nokia
4 Copyright (c) 2018-2019 AT&T Intellectual Property.
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
10 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
20 Mnemonic rmr_send_msg_man.xfm
21 Abstract The manual page for the rmr_send_msg function.
22 Author E. Scott Daniels
27 .im &{lib}/man/setup.im
31 &h1(RMR Library Functions)
40 rmr_mbuf_t* rmr_send_msg( void* vctx, rmr_mbuf_t* msg );
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.)
57 .** pull in common retry text
58 .im &{lib}/man/retry.im
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.
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
74 In the event of extreme failure, a NULL 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.
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
89 The following values may be passed back in the &ital(state) field of the returned message
93 &beg_dlist(.75i : ^&bold_font )
94 &di(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 &di(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 &di(RMR_ERR_BADARG) The message buffer pointer did not refer to a valid message.
100 &di(RMR_ERR_NOHDR) The header in the message buffer was not valid or corrupted.
101 &di(RMR_ERR_NOENDPT) The message type in the message buffer did not map to a known endpoint.
105 The following values may be assigned to &cw(errno) on failure.
106 &beg_dlist(.75i : ^&bold_font )
107 &di(INVAL) Parameter(s) passed to the function were not valid, or the underlying message processing environment was unable to interpret the message.
110 &di(ENOKEY) The header information in the message buffer was invalid.
113 &di(ENXIO) No known endpoint for the message could be found.
116 &di(EMSGSIZE) The underlying transport refused to accept the message because of a size value issue (message was not attempted to be sent).
119 &di(EFAULT) The message referenced by the message buffer is corrupt (NULL pointer or bad internal length).
122 &di(EBADF) Internal RMR error; information provided to the message transport environment was not valid.
125 &di(ENOTSUP) Sending was not supported by the underlying message transport.
128 &di(EFSM) The device is not in a state that can accept the message.
131 &di(EAGAIN) The device is not able to accept a message for sending. The user application should attempt to resend.
134 &di(EINTR) The operation was interrupted by delivery of a signal before the message was sent.
137 &di(ETIMEDOUT) The underlying message environment timed out during the send process.
140 &di(ETERM) The underlying message environment is in a shutdown state.
144 The following is a simple example of how the &cw(rmr_send_msg) function is called.
145 In this example, the send message buffer is saved between calls and reused
146 eliminating alloc/free cycles.
150 static rmr_mbuf_t* send_msg = NULL; // message to send; reused on each call
151 msg_t* send_pm; // payload for send
152 msg_t* pm; // our message format in the received payload
154 if( send_msg == NULL ) {
155 send_msg = rmr_alloc_msg( mr, MAX_SIZE ); // new buffer to send
158 // reference payload and fill in message type
159 pm = (msg_t*) send_msg->payload;
160 send_msg->mtype = MT_ANSWER;
162 msg->len = generate_data( pm ); // something that fills the payload in
163 msg = rmr_send_msg( mr, send_msg ); // ensure new pointer used after send
167 if( msg->state != RMR_OK ) {
168 // check for RMR_ERR_RETRY, and resend if needed