Add route table guide and formatting tweaks
[ric-plt/lib/rmr.git] / doc / src / man / rmr_wh_send_msg.3.xfm
1 .if false
2 ==================================================================================
3    Copyright (c) 2019 Nokia
4    Copyright (c) 2018-2019 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_wh_send_msg_man.xfm
21     Abstract    The manual page for the rmr_wh_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_wh_send_msg
34
35 &h2(SYNOPSIS )
36 &indent
37 &ex_start
38 #include <rmr/rmr.h>
39
40 rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t id, rmr_mbuf_t* msg );
41 &ex_end
42 &uindent
43
44 &h2(DESCRIPTION)
45 The &cw(rmr_wh_send_msg) function accepts a message buffer from the user application
46 and attempts to send it using the wormhole ID provided (id).
47 Unlike &ital(rmr_send_msg,) this function attempts to send the message directly
48 to a process at the other end of a wormhole which was created with &ital(rmr_wh_open().)
49 When sending message via wormholes, the normal RMR routing based on message type is
50 ignored, and the caller may leave the message type unspecified in the message buffer
51 (unless it is needed by the receiving process).
52
53 .sp
54 The message buffer (msg) used to send is the same format as used for regular RMR
55 send and reply to sender operations, thus any buffer allocated by these means, or
56 calls to &ital(rmr_rcv_msg()) can be passed to this function.
57
58 .** pull in common retry text
59 .im &{lib}/man/retry.im
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 should be
65 &cw(RMR_OK.)
66
67 &space
68 If the state in the returned buffer is anything other than &cw(RMR_OK,) the user application
69 may need to attempt a retransmission of the message, or take other action depending on the
70 setting of &cw(errno) as described below.
71
72 &space
73 In the event of extreme failure, a nil pointer is returned. In this case the value of
74 &cw(errno) might be of some use, for documentation, but there will be little that the
75 user application can do other than to move on.
76
77 &h2(ERRORS)
78 The following values may be passed back in the &ital(state) field of the returned message
79 buffer.
80
81 &space
82 &beg_dlist(.75i : ^&bold_font )
83 &ditem(RMR_ERR_WHID) The wormhole ID passed in was not associated with an open wormhole, or was out of range for a valid ID.
84 &ditem(RMR_ERR_NOWHOPEN) No wormholes exist, further attempt to validate the ID are skipped.
85 &ditem(RMR_ERR_BADARG) The message buffer pointer did not refer to a valid message.
86 &ditem(RMR_ERR_NOHDR)  The header in the message buffer was not valid or corrupted.
87 &end_dlist
88
89 &space
90 The following values may be assigned to &cw(errno) on failure.
91 &beg_dlist(.75i : ^&bold_font )
92 &ditem(INVAL) Parameter(s) passed to the function were not valid, or the underlying message processing environment was unable to interpret the message.
93
94 &ditem(ENOKEY) The header information in the message buffer was invalid.
95
96 &ditem(ENXIO) No known endpoint for the message could be found.
97
98 &ditem(EMSGSIZE) The underlying transport refused to accept the message because of a size value issue (message was not attempted to be sent).
99
100 &ditem(EFAULT) The message referenced by the message buffer is corrupt (nil pointer or bad internal length).
101
102 &ditem(EBADF) Internal RMR error; information provided to the message transport environment was not valid.
103
104 &ditem(ENOTSUP) Sending was not supported by the underlying message transport.
105
106 &ditem(EFSM) The device is not in a state that can accept the message.
107
108 &ditem(EAGAIN) The device is not able to accept a message for sending. The user application should attempt to resend.
109
110 &ditem(EINTR) The operation was interrupted by delivery of a signal before the message was sent.
111
112 &ditem(ETIMEDOUT) The underlying message environment timed out during the send process.
113
114 &ditem(ETERM) The underlying message environment is in a shutdown state.
115 &end_dlist
116
117 &h2(EXAMPLE)
118 The following is a simple example of how the a wormhole is created (rmr_wh_open) and then
119 how &cw(rmr_wh_send_msg) function is used to send messages.
120 Some error checking is omitted for clarity.
121
122 &space
123 &ex_start
124
125 #include <rmr/rmr.h>    // system headers omitted for clarity
126
127 int main() {
128    rmr_whid_t whid = -1;   // wormhole id for sending
129    void* mrc;      //msg router context
130         int i;
131    rmr_mbuf_t*  sbuf;      // send buffer
132    int     count = 0;
133    int     norm_msg_size = 1500;  // most msg fit in this size
134
135    mrc = rmr_init( "43086", norm_msg_size, RMRFL_NONE );
136    if( mrc == NULL ) {
137       fprintf( stderr, "[FAIL] unable to initialise RMR environment\n" );
138       exit( 1 );
139    }
140
141    while( ! rmr_ready( mrc ) ) {        // wait for routing table info
142       sleep( 1 );
143    }
144
145    sbuf = rmr_alloc_msg( mrc, 2048 );
146
147    while( 1 ) {
148      if( whid < 0 ) {
149        whid = rmr_wh_open( mrc, "localhost:6123" );  // open fails if endpoint refuses conn
150           if( RMR_WH_CONNECTED( wh ) ) {
151            snprintf( sbuf->payload, 1024, "periodic update from sender: %d", count++ );
152            sbuf->len =  strlen( sbuf->payload );
153            sbuf = rmr_wh_send_msg( mrc, whid, sbuf );
154         }
155      }
156
157      sleep( 5 );
158    }
159 }
160 &ex_end
161
162
163 &h2(SEE ALSO )
164 .ju off
165 rmr_alloc_msg(3),
166 rmr_call(3),
167 rmr_free_msg(3),
168 rmr_init(3),
169 rmr_payload_size(3),
170 rmr_rcv_msg(3),
171 rmr_rcv_specific(3),
172 rmr_rts_msg(3),
173 rmr_ready(3),
174 rmr_fib(3),
175 rmr_has_str(3),
176 rmr_tokenise(3),
177 rmr_mk_ring(3),
178 rmr_ring_free(3),
179 rmr_set_stimeout(3),
180 rmr_wh_open(3),
181 rmr_wh_close(3),
182 rmr_wh_state(3)
183 .ju on
184