X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sidecars%2Flistener%2Fmcl.c;fp=sidecars%2Flistener%2Fmcl.c;h=262486b04a5253c035c296dad2ded2c71b1019a0;hb=3cbdc585f92f4299f4e05108f9ed76766a72ff84;hp=78908d9ca22f0311f1d9cf0c36ecaf59fe236aca;hpb=c111a6cc35edbf493c7870077c091b04a3408f99;p=ric-app%2Fmc.git diff --git a/sidecars/listener/mcl.c b/sidecars/listener/mcl.c index 78908d9..262486b 100644 --- a/sidecars/listener/mcl.c +++ b/sidecars/listener/mcl.c @@ -208,6 +208,7 @@ static int open_fifo( mcl_ctx_t* ctx, int mtype, int io_dir ) { jfd = open( wbuf, O_RDWR | O_NONBLOCK ); // must have a reader before we can open a non-blocking writer if( jfd < 0 ) { logit( LOG_ERR, "(mcl) fifo open failed (rw): %s: %s", wbuf, strerror( errno ) ); + return -1; } fd = open( wbuf, O_WRONLY | O_NONBLOCK ); // this will be our actual writer, in non-blocking mode @@ -635,3 +636,29 @@ extern void mcl_fifo_fanout( void* vctx, int report, int long_hdr ) { } +/* + Given a buffer and length, along with the message type, look up the fifo and write + the buffer. Returns 0 on error; 1 on success. +*/ +extern int mcl_fifo_one( void* vctx, char* payload, int plen, int mtype ) { + mcl_ctx_t* ctx; // our context; mostly for the rmr context reference and symtable + fifo_t* fifo; // fifo to chalk counts on + int state = -1; + int fd; // file des to write to + + if( plen <= 0 ) { + return 1; + } + + if( (ctx = (mcl_ctx_t*) vctx) == NULL ) { + logit( LOG_ERR, "(mcl) invalid context given to fifo_one\n" ); + return 0; + } + + fd = suss_fifo( ctx, mtype, WRITER, &fifo ); // map the message type to an open fd + if( fd >= 0 ) { + state = write( fd, payload, plen ); + } + + return state == plen; +}