3 * Copyright 2019 AT&T Intellectual Property
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 // :vim ts=4 sw=4 noet:
24 Mnemonic: rmr_sender2.c
25 Abstract: Very simple test sender that polls and deals with responses
26 in between sends (from a single process).
28 Date: 18 February 2018
29 Author: E. Scott Daniels
31 Modified: 18 Mar 2019 - changes to support demo
39 #include <sys/epoll.h>
42 #include "rmr_wrapper.h"
45 void usage( char* argv0 ) {
46 fprintf( stderr, "usage: %s [mtype-max]\n", argv0 );
47 fprintf( stderr, "Sender will send messages with rotating msg types from 0 through mtype-max (if supplied)\n" );
48 fprintf( stderr, "if not supplied, only mtype 0 is sent\n" );
49 fprintf( stderr, "The default listen port for return messages is 43086; this can be changed by setting DUMMY_SENDER_RMR_RCV_PORT in the environment.\n" );
50 fprintf( stderr, "The sender will send forever unless DEMO_SENDER_MAX is set in the environment which causes termination after max messages.\n" );
51 fprintf( stderr, "The sender will poll for received messages after each send. The amount of time waited is controlled with DEMO_SENDER_PTO (ms) in the env. Use 0 for non-blocking poll.\n" );
54 int main( int argc, char** argv ) {
55 struct rmr_context *rmr_c; //obtain our enhanced rmr_context
56 int mtype = 0; // we can loop through several message types
58 char* lport = "43086"; // default listen port
59 long rcount = 0; // number of acks received
61 if( (eparm = getenv( "DUMMY_SENDER_RMR_RCV_PORT" )) != NULL ) {
62 lport = strdup( eparm );
65 rmr_c = rmr_init_wrapper(lport);
67 while( ! rmr_ready( rmr_c->mrc ) ) {
68 fprintf( stderr, "<TEST> waiting for RMr to indicate ready\n" );
71 fprintf( stderr, "[OK] initialisation complete\n" );
74 usleep( 10 ); // simulate some work being done
75 char* message = "foo 111";
77 if(rmr_send_wrapper (rmr_c, mtype, message ) == 1) {
78 //message successfully received in the receive buffer
80 strcpy(reply,rmr_c->rbuf->payload);
81 fprintf( stderr, "Acknowledgment received with content:%s\n",rmr_c->rbuf->payload);
86 if( (count % 5000) == 0 ) {
87 fprintf( stdout, "[INFO] total sent: %ld total received: %ld drops=%ld\n", count, rcount, count - rcount );
92 fprintf( stderr, "[INFO] sender is terminating having sent %ld messages\n", count );
93 rmr_close_wrapper(rmr_c);