Add user manual source
[ric-plt/lib/rmr.git] / doc / src / library / code_rcv.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(Receiver Sample)
24 The receiver code is even more simple than the sender code as it does not
25 need to wait for a route table to arrive (only senders need to do that), nor
26 does it need to allocate an initial buffer.
27 The example assumes that the sender is transmitting a zero terminated string
28 as the payload.
29
30 &space
31
32 &indent
33 &ex_start
34 rmr_mbuf_t* rbuf = NULL;
35 void* mrc = rmr_init( listen_port, MAX_BUF_SZ, RMRFL_NOFLAGS );
36
37 while( TRUE ) {
38     rbuf = rmr_rcv_msg( mrc, rbuf );    // reuse buffer on all but first loop
39     if( rbuf == NULL || rbuf->state != RMR_OK ) {
40         break;
41     }
42
43     fprintf( stdout, "mtype=%d sid=%d pay=%s\n",
44         rbuf->mtype, rbuf->sub_id, rbuf->payload );
45     sleep( delay_sec );
46 }
47
48 fprintf( stderr, "receive error\n" );
49 rmr_close( mrc );
50
51 &ex_end
52 &uindent