X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=examples%2Freceiver.c;h=6c6a0869e0eb55c43a8ac3e22644f583b99e0b51;hb=817516b6d7d3ffd874192c3a5342ead4c5da498b;hp=215fd54cd100bcadcb7d06acb0cb76dae806f285;hpb=ec88d3c0563eeb6ae5f73427edb0b3c4d7acf299;p=ric-plt%2Flib%2Frmr.git diff --git a/examples/receiver.c b/examples/receiver.c index 215fd54..6c6a086 100644 --- a/examples/receiver.c +++ b/examples/receiver.c @@ -1,14 +1,14 @@ // :vim ts=4 sw=4 noet: /* ================================================================================== - Copyright (c) 2019 Nokia - Copyright (c) 2018-2019 AT&T Intellectual Property. + Copyright (c) 2019-2020 Nokia + Copyright (c) 2018-2020 AT&T Intellectual Property. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -19,25 +19,31 @@ */ /* - Mnemonic: rmr_rcvr.c - Abstract: This is a very simple receiver that does nothing but listen - for messages and write stats every so often to the tty. + Mnemonic: rmr_rcvr.c + Abstract: This is a very simple receiver that does nothing but listen + for messages and write stats every so often to the tty. - Define these environment variables to have some control: - RMR_SEED_RT -- path to the static routing table - RMR_RTG_SVC -- host:port of the route table generator + Define these environment variables to have some control: + RMR_SEED_RT -- path to the static routing table + RMR_RTG_SVC -- host:port of the route table generator - Parms: Two positional parameters are recognised on the command line: - [port [stats-freq]] + Parms: Two positional parameters are recognised on the command line: + [port [stats-freq]] - where port is the port number to listen on and the stats frequency - is the number of messages received which causes stats to be - generated. If not supplied the listen port default is 4560 - and the stats frequency is every 10 messages. + where port is the port number to listen on and the stats frequency + is the number of messages received which causes stats to be + generated. If not supplied the listen port default is 4560 + and the stats frequency is every 10 messages. - Date: 1 April 2019 - Author: E. Scott Daniels + Date: 1 April 2019 + Author: E. Scott Daniels + + CAUTION: This example is now being pulled directly into the user documentation. + Because of this some altered line lengths and/or parameter list breaks + which seem strage have been applied to ensure that it formats nicely. + All code following the 'start_example' tag below is included. */ +// start_example #include #include @@ -49,54 +55,54 @@ int main( int argc, char** argv ) { - void* mrc; // msg router context - long long total = 0; - rmr_mbuf_t* msg = NULL; // message received - int stat_freq = 10; // write stats after reciving this many messages - int i; - char* listen_port = "4560"; // default to what has become the standard RMR port - long long count = 0; - long long bad = 0; - long long empty = 0; - - if( argc > 1 ) { - listen_port = argv[1]; - } - if( argc > 2 ) { - stat_freq = atoi( argv[2] ); - } - fprintf( stderr, " listening on port: %s\n", listen_port ); - fprintf( stderr, " stats will be reported every %d messages\n", stat_freq ); - - mrc = rmr_init( listen_port, RMR_MAX_RCV_BYTES, RMRFL_NONE ); // start your engines! - if( mrc == NULL ) { - fprintf( stderr, " ABORT: unable to initialise RMr\n" ); - exit( 1 ); - } - - while( ! rmr_ready( mrc ) ) { // wait for RMr to load a route table - fprintf( stderr, " waiting for ready\n" ); - sleep( 3 ); - } - fprintf( stderr, " rmr now shows ready\n" ); - - while( 1 ) { // forever; ctl-c, kill -15, etc to end - msg = rmr_rcv_msg( mrc, msg ); // block until one arrives - - if( msg ) { - if( msg->state == RMR_OK ) { - count++; // messages received for stats output - } else { - bad++; - } - } else { - empty++; - } - - if( (count % stat_freq) == 0 ) { - fprintf( stderr, " total msg received: %lld errors: %lld empty: %lld\n", count, bad, empty ); - } - - } + void* mrc; // msg router context + long long total = 0; + rmr_mbuf_t* msg = NULL; // message received + int stat_freq = 10; // write stats after reciving this many messages + int i; + char* listen_port = "4560"; // default to what has become the standard RMR port + long long count = 0; + long long bad = 0; + long long empty = 0; + + if( argc > 1 ) { + listen_port = argv[1]; + } + if( argc > 2 ) { + stat_freq = atoi( argv[2] ); + } + fprintf( stderr, " listening on port: %s\n", listen_port ); + fprintf( stderr, " stats will be reported every %d messages\n", stat_freq ); + + mrc = rmr_init( listen_port, RMR_MAX_RCV_BYTES, RMRFL_NONE ); + if( mrc == NULL ) { + fprintf( stderr, " ABORT: unable to initialise RMr\n" ); + exit( 1 ); + } + + while( ! rmr_ready( mrc ) ) { // wait for RMR to get a route table + fprintf( stderr, " waiting for ready\n" ); + sleep( 3 ); + } + fprintf( stderr, " rmr now shows ready\n" ); + + while( 1 ) { // receive until killed + msg = rmr_rcv_msg( mrc, msg ); // block until one arrives + + if( msg ) { + if( msg->state == RMR_OK ) { + count++; // nothing fancy, just count + } else { + bad++; + } + } else { + empty++; + } + + if( (count % stat_freq) == 0 ) { + fprintf( stderr, " total received: %lld; errors: %lld; empty: %lld\n", + count, bad, empty ); + } + } }