1 // :vim ts=4 sw=4 noet:
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 ==================================================================================
23 Abstract: This is a very simple receiver that does nothing but listen
24 for messages and write stats every so often to the tty.
26 Define these environment variables to have some control:
27 RMR_SEED_RT -- path to the static routing table
28 RMR_RTG_SVC -- host:port of the route table generator
30 Parms: Two positional parameters are recognised on the command line:
33 where port is the port number to listen on and the stats frequency
34 is the number of messages received which causes stats to be
35 generated. If not supplied the listen port default is 4560
36 and the stats frequency is every 10 messages.
39 Author: E. Scott Daniels
51 int main( int argc, char** argv ) {
52 void* mrc; // msg router context
54 rmr_mbuf_t* msg = NULL; // message received
55 int stat_freq = 10; // write stats after reciving this many messages
57 char* listen_port = "4560"; // default to what has become the standard RMR port
63 listen_port = argv[1];
66 stat_freq = atoi( argv[2] );
68 fprintf( stderr, "<DEMO> listening on port: %s\n", listen_port );
69 fprintf( stderr, "<DEMO> stats will be reported every %d messages\n", stat_freq );
71 mrc = rmr_init( listen_port, RMR_MAX_RCV_BYTES, RMRFL_NONE ); // start your engines!
73 fprintf( stderr, "<DEMO> ABORT: unable to initialise RMr\n" );
77 while( ! rmr_ready( mrc ) ) { // wait for RMr to load a route table
78 fprintf( stderr, "<DEMO> waiting for ready\n" );
81 fprintf( stderr, "<DEMO> rmr now shows ready\n" );
83 while( 1 ) { // forever; ctl-c, kill -15, etc to end
84 msg = rmr_rcv_msg( mrc, msg ); // block until one arrives
87 if( msg->state == RMR_OK ) {
88 count++; // messages received for stats output
96 if( (count % stat_freq) == 0 ) {
97 fprintf( stderr, "<DEMO> total msg received: %lld errors: %lld empty: %lld\n", count, bad, empty );