X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=src%2Fnanomsg%2Fsrc%2Frmr.c;h=1ed2cbcd245bd66d4abde3eb2f2a354efabdd4b7;hb=refs%2Fchanges%2F66%2F66%2F2;hp=3fe4247d244c431155724e41ddf8501f512623af;hpb=fd9cc7a5b3355146388ebdf4d558cb284c66c5f1;p=ric-plt%2Flib%2Frmr.git diff --git a/src/nanomsg/src/rmr.c b/src/nanomsg/src/rmr.c index 3fe4247..1ed2cbc 100644 --- a/src/nanomsg/src/rmr.c +++ b/src/nanomsg/src/rmr.c @@ -154,7 +154,7 @@ extern int rmr_payload_size( rmr_mbuf_t* msg ) { } errno = 0; - return msg->alloc_len - sizeof( uta_mhdr_t ); // figure size should we not have a msg buffer + return msg->alloc_len - RMR_HDR_LEN( msg->header ); // transport buffer less header and other data bits } /* @@ -169,10 +169,44 @@ extern rmr_mbuf_t* rmr_alloc_msg( void* vctx, int size ) { return NULL; } - m = alloc_zcmsg( ctx, NULL, size, 0 ); + m = alloc_zcmsg( ctx, NULL, size, 0, DEF_TR_LEN ); return m; } +/* + Allocates a send message as a zerocopy message allowing the underlying message protocol + to send the buffer without copy. In addition, a trace data field of tr_size will be + added and the supplied data coppied to the buffer before returning the message to + the caller. +*/ +extern rmr_mbuf_t* rmr_tralloc_msg( void* vctx, int size, int tr_size, unsigned const char* data ) { + uta_ctx_t* ctx; + rmr_mbuf_t* m; + int state; + + if( (ctx = (uta_ctx_t *) vctx) == NULL ) { + return NULL; + } + + m = alloc_zcmsg( ctx, NULL, size, 0, tr_size ); // alloc with specific tr size + if( m != NULL ) { + state = rmr_set_trace( m, data, tr_size ); // roll their data in + if( state != tr_size ) { + m->state = RMR_ERR_INITFAILED; + } + } + + return m; +} + +/* + Need an external path to the realloc static function as it's called by an + outward facing mbuf api function. +*/ +extern rmr_mbuf_t* rmr_realloc_msg( rmr_mbuf_t* msg, int new_tr_size ) { + return realloc_msg( msg, new_tr_size ); +} + /* Return the message to the available pool, or free it outright. */