3 ==================================================================================
4 Copyright (c) 2019 Nokia
5 Copyright (c) 2018-2019 AT&T Intellectual Property.
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
11 http://www.apache.org/licenses/LICENSE-2.0
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 ==================================================================================
21 .** example sender code
23 &h2(Receive and Send Sample)
24 The following code snippet receives messages and responds to the
25 sender if the message type is odd. The code illustrates how the
26 received message may be used to return a message to the source.
27 Variable type definitions are omitted for clarity and should be
31 It should also be noted that things like the message type which id
32 returned to the sender (99) is a random value that these applications
33 would have agreed on in advance and is &bold(not) an RMR definition.
39 mrc = rmr_init( listen_port, MAX_BUF_SZ, RMRFL_NOFLAGS );
40 rmr_set_stimeout( mrc, 1 ); // allow RMR to retry failed sends for ~1ms
42 while( ! rmr_ready( mrc ) ) { // we send, therefore we need a route table
46 mbuf = NULL; // ensure our buffer pointer is nil for 1st call
49 mbuf = rmr_rcv_msg( mrc, mbuf ); // wait for message
51 if( mbuf == NULL || mbuf->state != RMR_OK ) {
55 if( mbuf->mtype % 2 ) { // respond to odd message types
56 plen = rmr_payload_size( mbuf ); // max size
58 // reset necessary fields in msg
59 mbuf->mtype = 99; // response type
60 mbuf->sub_id = RMR_VOID_SUBID; // we turn subid off
61 mbuf->len = snprintf( mbuf->payload, plen, "pong: %s", get_info() );
63 mbuf = rmr_rts_msg( mrc, mbuf ); // return to sender
64 if( mbuf == NULL || mbuf->state != RMR_OK ) {
65 fprintf( stderr, "return to sender failed\n" );
70 fprintf( stderr, "abort: receive failure\n" );