test(e2e): Add return to sender app based test
[ric-plt/lib/rmr.git] / src / nanomsg / src / rtable_static.c
index 41ebc61..cfcb27e 100644 (file)
@@ -1,14 +1,14 @@
 // : vi ts=4 sw=4 noet :
 /*
 ==================================================================================
-       Copyright (c) 2019 Nokia 
+       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
 
-       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,
@@ -56,15 +56,15 @@ static int uta_link2( char* target ) {
                return -1;
        }
 
-    nn_sock = nn_socket( AF_SP, NN_PUSH );             // the socket we'll use to connect to the target
+       nn_sock = nn_socket( AF_SP, NN_PUSH );          // the socket we'll use to connect to the target
        if( nn_sock < 0 ) {
-               fprintf( stderr, "[WARN] rmr: link2: unable to create socket for link to target: %s: %d\n", target, errno );
+               fprintf( stderr, "[WARN] rmr: link2: unable to create socket for link to target: %s: %d\n\n\n", target, errno );
                return -1;
        }
 
        snprintf( conn_info, sizeof( conn_info ), "tcp://%s", target );
-    if( nn_connect( nn_sock, conn_info ) < 0 ) {                                                       // connect failed
-               fprintf( stderr, "[WARN] rmr: link2: unable to create link to target: %s: %d\n", target, errno );
+       if( nn_connect( nn_sock, conn_info ) < 0 ) {                                                    // connect failed
+               fprintf( stderr, "[WARN] rmr: link2: unable to create link to target: %s: %d\n\n\n", target, errno );
                nn_close( nn_sock );
                return -1;
        }
@@ -91,7 +91,7 @@ static int rt_link2_ep( endpoint_t* ep ) {
 }
 
 /*
-       Add an endpoint to a route table entry for the group given. If the endpoint isn't in the 
+       Add an endpoint to a route table entry for the group given. If the endpoint isn't in the
        hash we add it and create the endpoint struct.
 
        The caller must supply the specific route table (we assume it will be pending, but they
@@ -138,6 +138,7 @@ static endpoint_t*  uta_add_ep( route_table_t* rt, rtable_ent_t* rte, char* ep_n
                }
 
                ep->nn_sock = -1;                                       // not connected
+               ep->open = 0;
                ep->addr = uta_h2ip( ep_name );
                ep->name = strdup( ep_name );
 
@@ -194,7 +195,7 @@ static int uta_epsock_byname( route_table_t* rt, char* ep_name ) {
        entry. Returns the nanomsg socket number if there is a rte for the message
        type, and group is defined, else returns -1.
 
-       The group is the group number to select from. 
+       The group is the group number to select from.
 
        The user supplied integer 'more' will be set if there are additional groups
        defined to the matching route table entry which have a higher group number.
@@ -203,14 +204,15 @@ static int uta_epsock_byname( route_table_t* rt, char* ep_name ) {
        invoke this function again to make a selection against that group. If there
        are no more groups, more is set to 0.
 */
-static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more ) {
+static int uta_epsock_rr( route_table_t *rt, uint64_t key, int group, int* more ) {
        rtable_ent_t* rte;                      // matching rt entry
        endpoint_t*     ep;                             // seected end point
-       int nn_sock = -1;
+       int nn_sock = -2;
        int dummy;
        rrgroup_t* rrg;
 
-       if( ! more ) {                          // eliminate cheks each time we need to user
+
+       if( ! more ) {                          // eliminate checks each time we need to use
                more = &dummy;
        }
 
@@ -219,20 +221,20 @@ static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more ) {
                return -1;
        }
 
-       if( (rte = rmr_sym_pull( rt->hash, mtype )) == NULL ) {
+       if( (rte = rmr_sym_pull( rt->hash, key )) == NULL ) {
                *more = 0;
-               //if( DEBUG ) fprintf( stderr, ">>>> rte not found for type = %d\n", mtype );
+               //if( DEBUG ) fprintf( stderr, "#### >>> rte not found for type key=%lu\n", key );
                return -1;
        }
 
        if( group < 0 || group >= rte->nrrgroups ) {
-               //if( DEBUG ) fprintf( stderr, ">>>> group out of range: mtype=%d group=%d max=%d\n", mtype, group, rte->nrrgroups );
+               //if( DEBUG ) fprintf( stderr, ">>>> group out of range: key=%lu group=%d max=%d\n", key, group, rte->nrrgroups );
                *more = 0;
                return -1;
        }
 
        if( (rrg = rte->rrgroups[group]) == NULL ) {
-               //if( DEBUG ) fprintf( stderr, ">>>> rrg not found for type = %d\n", mtype );
+               //if( DEBUG ) fprintf( stderr, ">>>> rrg not found for type = %lu\n", key );
                *more = 0;                                      // groups are inserted contig, so nothing should be after a nil pointer
                return -1;
        }
@@ -241,14 +243,14 @@ static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more ) {
 
        switch( rrg->nused ) {
                case 0:                         // nothing allocated, just punt
-                       //if( DEBUG ) fprintf( stderr, ">>>> nothing allocated for the rrg\n" );
+                       //if( DEBUG )
                        return -1;
 
-               case 1:                         // exactly one, no rr to deal with and more is not possible even if fanout > 1
+               case 1:                         // exactly one, no rr to deal with
                        nn_sock = rrg->epts[0]->nn_sock;
                        ep = rrg->epts[0];
                        break;
-       
+
                default:                                                                                // need to pick one and adjust rr counts
                        ep = rrg->epts[rrg->ep_idx];
                        nn_sock = rrg->epts[rrg->ep_idx++]->nn_sock;
@@ -258,7 +260,7 @@ static int uta_epsock_rr( route_table_t *rt, int mtype, int group, int* more ) {
                        break;
        }
 
-       if( ! ep->open ) {                              // not connected
+       if( ep && ! ep->open ) {                                // not connected
                if( ep->addr == NULL ) {                                        // name didn't resolve before, try again
                        ep->addr = uta_h2ip( ep->name );
                }