From 51a0d5c0069b1ce533f0fc89853f7f61c729ecac Mon Sep 17 00:00:00 2001 From: kpl Date: Mon, 16 Jun 2014 10:42:55 -0700 Subject: [PATCH] cmRtNet.h/c : Added hdrByteCnt field to cmRtNetSyncMsg_t. Updated _cmRtNetDeserializeSyncMsg() to use cmRtNetSyncMsg_t.hdrByteCnt. --- cmRtNet.c | 10 ++++++---- cmRtNet.h | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmRtNet.c b/cmRtNet.c index a23a7a5..71537a9 100644 --- a/cmRtNet.c +++ b/cmRtNet.c @@ -263,7 +263,9 @@ unsigned _cmRtNetNodeEndpointCount( cmRtNetNode_t* np ) } unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m ) -{ return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); } +{ + return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); +} cmRtNetRC_t _cmRtNetSerializeSyncMsg( cmRtNet_t* p, const cmRtNetSyncMsg_t* m, void* buf, unsigned n ) { @@ -283,7 +285,7 @@ cmRtNetRC_t _cmRtNetDeserializeSyncMsg( const void* buf, unsigned n, cmRtNetSync assert( n > sizeof(*m)); memcpy(m,buf,sizeof(*m)); const cmRtNetSyncMsg_t* mp = (const cmRtNetSyncMsg_t*)buf; - const cmChar_t* s = (const cmChar_t*)(mp+1); + const cmChar_t* s = ((const cmChar_t*)(mp)) + mp->hdrByteCnt; m->label = cmMemAllocStr(s); return kOkNetRC; } @@ -297,6 +299,7 @@ cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t m.hdr.rtSubIdx = cmInvalidIdx; m.hdr.selId = kNetSyncSelRtId; m.selId = selId; + m.hdrByteCnt = sizeof(cmRtNetSyncMsg_t); m.label = msgLabel; m.id = msgId; m.rtSubIdx = msgRtSubIdx; @@ -524,7 +527,7 @@ cmRtNetRC_t _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRt bool _cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt ) { cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data; - return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId; + return dataByteCnt >= sizeof(cmRtSysMsgHdr_t) && m->hdr.selId == kNetSyncSelRtId; } // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') @@ -673,7 +676,6 @@ void _cmRtNetRecv( void* cbArg, const char* data, unsigned dataByteCnt, const st else { // All non-sync messages arriving here are prefixed by a cmRtNetMsg_t header - fill in the source addr here. - // NOTE: the source addr could be filled in by the sender but this would increase the size // of the msg. Instead we choose the more time consuming method of looking up the // soure node here - hmmmm????. diff --git a/cmRtNet.h b/cmRtNet.h index 2b091e7..6c992cb 100644 --- a/cmRtNet.h +++ b/cmRtNet.h @@ -63,6 +63,7 @@ extern "C" { { cmRtSysMsgHdr_t hdr; // standard cmRtSys msg header cmRtNetSelId_t selId; // message selector id (See kXXXSelNetId above) + unsigned hdrByteCnt; // size of the header record at transmission (used to locate the serialzed label) unsigned rtSubIdx; // cmInvalidIdx or rtSubIdx unsigned id; // endptCnt or endpoint id const cmChar_t* label; // node or endpoint label