X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Frmr.go;h=9a3116d78ccc88c8a7768a7b4e5d3713b8bf7895;hb=1307b2d8d34f48bf44267efc2d1e607823c8d06d;hp=0aeced219009dd3d54e3aa8d2477bd94c0ef6f12;hpb=e0948fe8b755b4d752ef9da4a46246cf3951c9dc;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go index 0aeced2..9a3116d 100755 --- a/pkg/xapp/rmr.go +++ b/pkg/xapp/rmr.go @@ -212,8 +212,8 @@ func (m *RMRClient) parseMessage(rxBuffer *C.rmr_mbuf_t) { } } -func (m *RMRClient) Allocate() *C.rmr_mbuf_t { - buf := C.rmr_alloc_msg(m.context, 0) +func (m *RMRClient) Allocate(size int) *C.rmr_mbuf_t { + buf := C.rmr_alloc_msg(m.context, C.int(size)) if buf == nil { Logger.Error("rmrClient: Allocating message buffer failed!") } @@ -236,20 +236,24 @@ func (m *RMRClient) SendRts(params *RMRParams) bool { } func (m *RMRClient) CopyBuffer(params *RMRParams) *C.rmr_mbuf_t { - txBuffer := params.Mbuf - if txBuffer == nil { - txBuffer = m.Allocate() - if txBuffer == nil { - return nil - } + if params.Mbuf != nil { + m.Free(params.Mbuf) + params.Mbuf = nil } - txBuffer.mtype = C.int(params.Mtype) - txBuffer.sub_id = C.int(params.SubId) - txBuffer.len = C.int(len(params.Payload)) + payLen := len(params.Payload) if params.PayloadLen != 0 { - txBuffer.len = C.int(params.PayloadLen) + payLen = params.PayloadLen + } + + txBuffer := m.Allocate(payLen) + if txBuffer == nil { + return nil } + txBuffer.mtype = C.int(params.Mtype) + txBuffer.sub_id = C.int(params.SubId) + txBuffer.len = C.int(payLen) + datap := C.CBytes(params.Payload) defer C.free(datap)