doc(code): Indent fixes and whitespace cleanup
[ric-plt/lib/rmr.git] / test / app_test / sender.c
index 89a0afc..3602d4f 100644 (file)
@@ -1,14 +1,14 @@
 // :vim ts=4 sw=4 noet:
 /*
 ==================================================================================
 // :vim ts=4 sw=4 noet:
 /*
 ==================================================================================
-    Copyright (c) 2019 Nokia
-    Copyright (c) 2018-2019 AT&T Intellectual Property.
+       Copyright (c) 2019 Nokia
+       Copyright (c) 2018-2019 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
 
 
    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,
 
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
 
 /*
        Mnemonic:       sender.c
 
 /*
        Mnemonic:       sender.c
-       Abstract:       This is a simple sender which will send a series of messages. 
+       Abstract:       This is a simple sender which will send a series of messages.
                                It is expected that the first attempt(s) will fail if the receiver
                                is not up and this does not start decrementing the number to
                                It is expected that the first attempt(s) will fail if the receiver
                                is not up and this does not start decrementing the number to
-                               send until it has a good send.  
+                               send until it has a good send.
 
                                The process will check the receive queue and list received messages
                                but pass/fail is not dependent on what comes back.
 
                                If the receiver(s) do not become connectable in 20 sec this process
 
                                The process will check the receive queue and list received messages
                                but pass/fail is not dependent on what comes back.
 
                                If the receiver(s) do not become connectable in 20 sec this process
-                               will give up and fail. 
+                               will give up and fail.
 
 
                                Message types will vary between 1 and 10, so the route table must
 
 
                                Message types will vary between 1 and 10, so the route table must
-                               be set up to support those message types.  
+                               be set up to support those message types.
 
                                Message format is:
                                        ck1 ck2|<msg-txt><nil>
 
                                Ck1 is the simple check sum of the msg-text (NOT includeing <nil>)
                                Ck2 is the simple check sum of the trace data which is a nil terminated
 
                                Message format is:
                                        ck1 ck2|<msg-txt><nil>
 
                                Ck1 is the simple check sum of the msg-text (NOT includeing <nil>)
                                Ck2 is the simple check sum of the trace data which is a nil terminated
-                               series of bytes. 
+                               series of bytes.
 
                                Parms:  argv[1] == nmsgs; argv[2] == delay; argv[3] == listen port
 
 
                                Parms:  argv[1] == nmsgs; argv[2] == delay; argv[3] == listen port
 
@@ -74,11 +74,11 @@ static int sum( char* str ) {
 }
 
 int main( int argc, char** argv ) {
 }
 
 int main( int argc, char** argv ) {
-    void* mrc;                                                 // msg router context
-    struct epoll_event events[1];                      // list of events to give to epoll
-    struct epoll_event epe;                 // event definition for event to listen to
-    int     ep_fd = -1;                                                // epoll's file des (given to epoll_wait)
-    int rcv_fd;                                                // file des that NNG tickles -- give this to epoll to listen on
+       void* mrc;                                                      // msg router context
+       struct epoll_event events[1];                   // list of events to give to epoll
+       struct epoll_event epe;                 // event definition for event to listen to
+       int     ep_fd = -1;                                             // epoll's file des (given to epoll_wait)
+       int rcv_fd;                                                     // file des that NNG tickles -- give this to epoll to listen on
        int nready;                                                             // number of events ready for receive
        rmr_mbuf_t*             sbuf;                                   // send buffer
        rmr_mbuf_t*             rbuf;                                   // received buffer
        int nready;                                                             // number of events ready for receive
        rmr_mbuf_t*             sbuf;                                   // send buffer
        rmr_mbuf_t*             rbuf;                                   // received buffer
@@ -107,12 +107,12 @@ int main( int argc, char** argv ) {
 
        fprintf( stderr, "<SNDR> listen port: %s; sending %d messages; delay=%d\n", listen_port, nmsgs, delay );
 
 
        fprintf( stderr, "<SNDR> listen port: %s; sending %d messages; delay=%d\n", listen_port, nmsgs, delay );
 
-    if( (mrc = rmr_init( listen_port, 1400, RMRFL_NONE )) == NULL ) {
+       if( (mrc = rmr_init( listen_port, 1400, RMRFL_NONE )) == NULL ) {
                fprintf( stderr, "<SNDR> unable to initialise RMr\n" );
                exit( 1 );
        }
 
                fprintf( stderr, "<SNDR> unable to initialise RMr\n" );
                exit( 1 );
        }
 
-    if( (rcv_fd = rmr_get_rcvfd( mrc )) >= 0 ) {                       // epoll only available from NNG -- skip receive later if not NNG
+       if( (rcv_fd = rmr_get_rcvfd( mrc )) >= 0 ) {                    // epoll only available from NNG -- skip receive later if not NNG
                if( rcv_fd < 0 ) {
                        fprintf( stderr, "<SNDR> unable to set up polling fd\n" );
                        exit( 1 );
                if( rcv_fd < 0 ) {
                        fprintf( stderr, "<SNDR> unable to set up polling fd\n" );
                        exit( 1 );
@@ -121,10 +121,10 @@ int main( int argc, char** argv ) {
                        fprintf( stderr, "<SNDR> [FAIL] unable to create epoll fd: %d\n", errno );
                        exit( 1 );
                }
                        fprintf( stderr, "<SNDR> [FAIL] unable to create epoll fd: %d\n", errno );
                        exit( 1 );
                }
-       epe.events = EPOLLIN;
-       epe.data.fd = rcv_fd;
+               epe.events = EPOLLIN;
+               epe.data.fd = rcv_fd;
 
 
-       if( epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ) != 0 )  {
+               if( epoll_ctl( ep_fd, EPOLL_CTL_ADD, rcv_fd, &epe ) != 0 )  {
                        fprintf( stderr, "<SNDR> [FAIL] epoll_ctl status not 0 : %s\n", strerror( errno ) );
                        exit( 1 );
                }
                        fprintf( stderr, "<SNDR> [FAIL] epoll_ctl status not 0 : %s\n", strerror( errno ) );
                        exit( 1 );
                }
@@ -147,10 +147,10 @@ int main( int argc, char** argv ) {
                }
        }
        fprintf( stderr, "<SNDR> rmr is ready; starting to send\n" );
                }
        }
        fprintf( stderr, "<SNDR> rmr is ready; starting to send\n" );
-       
+
        timeout = time( NULL ) + 20;
 
        timeout = time( NULL ) + 20;
 
-    while( count < nmsgs ) {                                                           // we send 10 messages after the first message is successful
+       while( count < nmsgs ) {                                                                // we send 10 messages after the first message is successful
                snprintf( trace, 100, "%lld", (long long) time( NULL ) );
                rmr_set_trace( sbuf, trace, strlen( trace ) + 1 );
                snprintf( wbuf, 200, "count=%d tr=%s %d stand up and cheer!", count, trace, rand() );
                snprintf( trace, 100, "%lld", (long long) time( NULL ) );
                rmr_set_trace( sbuf, trace, strlen( trace ) + 1 );
                snprintf( wbuf, 200, "count=%d tr=%s %d stand up and cheer!", count, trace, rand() );
@@ -213,9 +213,9 @@ int main( int argc, char** argv ) {
                if( delay > 0 ) {
                        usleep( delay );
                }
                if( delay > 0 ) {
                        usleep( delay );
                }
-    }
+       }
+
 
 
-       
        timeout = time( NULL ) + 2;                             // allow 2 seconds for the pipe to drain from the receiver
        while( time( NULL ) < timeout );
                if( rcv_fd >= 0 ) {
        timeout = time( NULL ) + 2;                             // allow 2 seconds for the pipe to drain from the receiver
        while( time( NULL ) < timeout );
                if( rcv_fd >= 0 ) {