From: Juha Hyttinen Date: Fri, 25 Sep 2020 09:19:21 +0000 (+0300) Subject: Use old rmr buf buffer in send phase if given. RTS functionality will not work withou... X-Git-Tag: v0.5.3^0 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=f22b458846a20a4a9fcafb49e3195ab44a16840e;p=ric-plt%2Fxapp-frame.git Use old rmr buf buffer in send phase if given. RTS functionality will not work without it. Change-Id: I36c9ede95d554eafbb0e491134ea8e0613645a78 Signed-off-by: Juha Hyttinen --- diff --git a/pkg/xapp/rmr.go b/pkg/xapp/rmr.go index 9b91e1a..9f988dc 100755 --- a/pkg/xapp/rmr.go +++ b/pkg/xapp/rmr.go @@ -258,11 +258,21 @@ func (m *RMRClient) parseMessage(rxBuffer *C.rmr_mbuf_t) { func (m *RMRClient) Allocate(size int) *C.rmr_mbuf_t { m.contextMux.Lock() defer m.contextMux.Unlock() - buf := C.rmr_alloc_msg(m.context, C.int(size)) - if buf == nil { + outbuf := C.rmr_alloc_msg(m.context, C.int(size)) + if outbuf == nil { Logger.Error("rmrClient: Allocating message buffer failed!") } - return buf + return outbuf +} + +func (m *RMRClient) ReAllocate(inbuf *C.rmr_mbuf_t, size int) *C.rmr_mbuf_t { + m.contextMux.Lock() + defer m.contextMux.Unlock() + outbuf := C.rmr_realloc_msg(inbuf, C.int(size)) + if outbuf == nil { + Logger.Error("rmrClient: Allocating message buffer failed!") + } + return outbuf } func (m *RMRClient) Free(mbuf *C.rmr_mbuf_t) { @@ -302,17 +312,21 @@ func (m *RMRClient) SendWithRetry(params *RMRParams, isRts bool, to time.Duratio } func (m *RMRClient) CopyBuffer(params *RMRParams) *C.rmr_mbuf_t { - if params.Mbuf != nil { - m.Free(params.Mbuf) - params.Mbuf = nil - } payLen := len(params.Payload) if params.PayloadLen != 0 { payLen = params.PayloadLen } - txBuffer := m.Allocate(payLen) + txBuffer := params.Mbuf + params.Mbuf = nil + + if txBuffer != nil { + txBuffer = m.ReAllocate(txBuffer, payLen) + } else { + txBuffer = m.Allocate(payLen) + } + if txBuffer == nil { return nil }