b13a3c8c8bb1ff463c67f25de406dee1962ec3e2
[ric-plt/lib/rmr.git] / doc / src / library / code_send.im
1
2 .if false
3 ==================================================================================
4         Copyright (c) 2019 Nokia
5         Copyright (c) 2018-2019 AT&T Intellectual Property.
6
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11        http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18 ==================================================================================
19 .fi
20
21 .** example sender code
22
23 &h2(Sender Sample)
24 The following code segment shows how a message buffer can be
25 allocated, populated, and sent.  The snippet also illustrates how the
26 result from the &func(rmr_send_msg) function is used to send the next
27 message.  It does not illustrate error and/or retry handling.
28 &space
29
30 &indent
31 &ex_start
32 mrc = rmr_init( listen_port, MAX_BUF_SZ, RMRFL_NOFLAGS );
33 rmr_set_stimeout( mrc, rmr_retries );
34
35 while( ! rmr_ready( mrc ) ) {
36     sleep( 1 );
37 }
38
39 sbuf = rmr_alloc_msg( mrc, 256 );   // 1st send buffer
40
41 while( TRUE ) {
42     sbuf->len = gen_status( (status_msg *) sbuf->payload );
43     sbuf->mtype = STATUS_MSG;
44     sbuf->sub_id = RMR_VOID_SUBID;     // subscription not used
45     sbuf = rmr_send_msg( mrc, sbuf );
46
47     sleep( delay_sec );
48 }
49
50 rmr_close( mrc );
51
52 &ex_end
53 &uindent