Correct meid table parse bug
[ric-plt/lib/rmr.git] / src / rmr / common / src / wormholes.c
index 76567f9..248748f 100644 (file)
@@ -297,6 +297,60 @@ extern rmr_mbuf_t* rmr_wh_send_msg( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg
        return send2ep( ctx, ep, msg );                                                 // send directly to the endpoint
 }
 
+/*
+       Send a message directly to an open wormhole and then block until a response has
+       been received.  The return is the same as for rmr_call(); the received buffer
+       or nil if no response was received.
+*/
+extern rmr_mbuf_t* rmr_wh_call( void* vctx, rmr_whid_t whid, rmr_mbuf_t* msg, int call_id, int max_wait ) {
+       uta_ctx_t*      ctx;
+       endpoint_t*     ep;                             // enpoint that wormhole ID references
+       wh_mgt_t *whm;
+       char* d1;                                       // point at the call-id in the header
+
+       if( (ctx = (uta_ctx_t *) vctx) == NULL || msg == NULL ) {               // bad stuff, bail fast
+               errno = EINVAL;                                                                                         // if msg is null, this is their clue
+               if( msg != NULL ) {
+                       msg->state = RMR_ERR_BADARG;
+                       errno = EINVAL;                                                                                 // must ensure it's not eagain
+               }
+               return msg;
+       }
+
+       msg->state = RMR_OK;
+
+       if( (whm = ctx->wormholes) == NULL ) {
+               errno = EINVAL;                                                                                         // no wormholes open
+               msg->state = RMR_ERR_NOWHOPEN;
+               return msg;
+       }
+
+       if( whid < 0 || whid >= whm->nalloc || whm->eps[whid] == NULL ) {
+               errno = EINVAL;
+               msg->state = RMR_ERR_WHID;
+               return msg;
+       }
+
+       errno = 0;
+       if( msg->header == NULL ) {
+               rmr_vlog( RMR_VL_ERR, "rmr_wh_call: message had no header\n" );
+               msg->state = RMR_ERR_NOHDR;
+               errno = EBADMSG;                                                                                // must ensure it's not eagain
+               return msg;
+       }
+
+       ep = whm->eps[whid];
+       if( ep != NULL ) {
+               if( ! ep->open ) {
+                       rmr_wh_open( ctx, ep->name );
+               }
+               return mt_call( vctx, msg, call_id, max_wait, ep );                     // use main (internal) call to setup and block
+       }
+
+       msg->state = RMR_ERR_NOENDPT;
+       return msg;
+}
+
 /*
        This will "close" a wormhole.  We don't actually drop the session as that might be needed
        by others, but we do pull the ep reference from the list.
@@ -323,3 +377,43 @@ extern void rmr_wh_close( void* vctx, int whid ) {
 
        whm->eps[whid] = NULL;
 }
+
+/*
+       Check the state of an endpoint that is associated with the wormhold ID
+       passed in. If the state is "open" then we return RMR_OK. Other possible
+       return codes:
+
+               RMR_ERR_WHID        // wormhole id was invalid
+               RMR_ERR_NOENDPT     // the endpoint connection is not open
+               RMR_ERR_BADARG          // context or other arg was invalid
+               RMR_ERR_NOWHOPEN        // wormhole(s) have not been initalised
+
+*/
+extern int rmr_wh_state( void* vctx, rmr_whid_t whid ) {
+       uta_ctx_t*      ctx;
+       wh_mgt_t*       whm;                    // easy reference to wh mgt stuff
+       endpoint_t*     ep;                             // enpoint that wormhole ID references
+
+       if( (ctx = (uta_ctx_t *) vctx) == NULL ) {              // bad stuff, bail fast
+               errno = EINVAL;
+               return RMR_ERR_BADARG;
+       }
+
+       if( (whm = ctx->wormholes) == NULL ) {
+               errno = EINVAL;                                                                                         // no wormholes open
+               return RMR_ERR_NOWHOPEN;
+       }
+
+       if( whid < 0 || whid >= whm->nalloc || whm->eps[whid] == NULL ) {
+               errno = EINVAL;
+               return RMR_ERR_WHID;
+       }
+
+       errno = 0;
+
+       if( (ep = whm->eps[whid]) != NULL ) {
+               return ep->open ? RMR_OK : RMR_ERR_NOENDPT;
+       }
+
+       return RMR_ERR_NOENDPT;
+}