1 // :vim ts=4 sw=4 noet:
4 Abstract: This is a very simple receiver that does nothing but listen
5 for messages and write stats every so often to the tty.
7 Define these environment variables to have some control:
8 RMR_SEED_RT -- path to the static routing table
9 RMR_RTG_SVC -- host:port of the route table generator
11 Parms: Two positional parameters are recognised on the command line:
14 where port is the port number to listen on and the stats frequency
15 is the number of messages received which causes stats to be
16 generated. If not supplied the listen port default is 4560
17 and the stats frequency is every 10 messages.
20 Author: E. Scott Daniels
32 int main( int argc, char** argv ) {
33 void* mrc; // msg router context
35 rmr_mbuf_t* msg = NULL; // message received
36 int stat_freq = 10; // write stats after reciving this many messages
44 listen_port = argv[1];
47 stat_freq = atoi( argv[2] );
49 fprintf( stderr, "<DEMO> listening on port: %s\n", listen_port );
50 fprintf( stderr, "<DEMO> stats will be reported every %d messages\n", stat_freq );
52 mrc = rmr_init( listen_port, RMR_MAX_RCV_BYTES, RMRFL_NONE ); // start your engines!
54 fprintf( stderr, "<DEMO> ABORT: unable to initialise RMr\n" );
58 while( ! rmr_ready( mrc ) ) { // wait for RMr to load a route table
59 fprintf( stderr, "<DEMO> waiting for ready\n" );
62 fprintf( stderr, "<DEMO> rmr now shows ready\n" );
64 while( 1 ) { // forever; ctl-c, kill -15, etc to end
65 msg = rmr_rcv_msg( mrc, msg ); // block until one arrives
68 if( msg->state == RMR_OK ) {
69 count++; // messages received for stats output
77 if( (count % stat_freq) == 0 ) {
78 fprintf( stderr, "<DEMO> total msg received: %lld errors: %lld empty: %lld\n", count, bad, empty );