Browse Source

cmRtNet.h/c : Added hdrByteCnt field to cmRtNetSyncMsg_t. Updated _cmRtNetDeserializeSyncMsg()

to use cmRtNetSyncMsg_t.hdrByteCnt.
master
kpl 10 years ago
parent
commit
51a0d5c006
2 changed files with 7 additions and 4 deletions
  1. 6
    4
      cmRtNet.c
  2. 1
    0
      cmRtNet.h

+ 6
- 4
cmRtNet.c View File

@@ -263,7 +263,9 @@ unsigned _cmRtNetNodeEndpointCount( cmRtNetNode_t* np )
263 263
 }
264 264
 
265 265
 unsigned _cmRtNetSyncMsgSerialByteCount( const cmRtNetSyncMsg_t* m )
266
-{ return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); }
266
+{ 
267
+  return sizeof(cmRtNetSyncMsg_t) + (m->label==NULL ? 1 : strlen(m->label) + 1); 
268
+}
267 269
 
268 270
 cmRtNetRC_t _cmRtNetSerializeSyncMsg( cmRtNet_t* p, const cmRtNetSyncMsg_t* m, void* buf, unsigned n )
269 271
 {
@@ -283,7 +285,7 @@ cmRtNetRC_t _cmRtNetDeserializeSyncMsg( const void* buf, unsigned n, cmRtNetSync
283 285
   assert( n > sizeof(*m));
284 286
   memcpy(m,buf,sizeof(*m));
285 287
   const cmRtNetSyncMsg_t* mp = (const cmRtNetSyncMsg_t*)buf;
286
-  const cmChar_t*   s  = (const cmChar_t*)(mp+1);
288
+  const cmChar_t*   s  = ((const cmChar_t*)(mp)) + mp->hdrByteCnt;
287 289
   m->label = cmMemAllocStr(s);
288 290
   return kOkNetRC;
289 291
 }
@@ -297,6 +299,7 @@ cmRtNetRC_t _cmRtNetSendSyncMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRtNetSelId_t
297 299
   m.hdr.rtSubIdx = cmInvalidIdx;
298 300
   m.hdr.selId    = kNetSyncSelRtId;
299 301
   m.selId        = selId;
302
+  m.hdrByteCnt   = sizeof(cmRtNetSyncMsg_t);
300 303
   m.label        = msgLabel;
301 304
   m.id           = msgId;
302 305
   m.rtSubIdx     = msgRtSubIdx;
@@ -524,7 +527,7 @@ cmRtNetRC_t  _cmRtNetSendEndpointReplyMsg( cmRtNet_t* p, cmRtNetNode_t* np, cmRt
524 527
 bool    _cmRtNetIsSyncModeMsg( const void* data, unsigned dataByteCnt )
525 528
 {
526 529
   cmRtNetSyncMsg_t* m = (cmRtNetSyncMsg_t*)data;
527
-  return dataByteCnt >= sizeof(cmRtNetSyncMsg_t) && m->hdr.selId == kNetSyncSelRtId;
530
+  return dataByteCnt >= sizeof(cmRtSysMsgHdr_t) && m->hdr.selId == kNetSyncSelRtId;
528 531
 }
529 532
 
530 533
 // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') 
@@ -673,7 +676,6 @@ void _cmRtNetRecv( void* cbArg, const char* data, unsigned dataByteCnt, const st
673 676
   else
674 677
   {
675 678
     // All non-sync messages arriving here are prefixed by a cmRtNetMsg_t header - fill in the source addr here.
676
-
677 679
     // NOTE: the source addr could be filled in by the sender but this would increase the size
678 680
     // of the msg.  Instead we choose the more time consuming method of looking up the
679 681
     // soure node here - hmmmm????.

+ 1
- 0
cmRtNet.h View File

@@ -63,6 +63,7 @@ extern "C" {
63 63
   {
64 64
     cmRtSysMsgHdr_t hdr;      // standard cmRtSys msg  header 
65 65
     cmRtNetSelId_t  selId;    // message selector id (See kXXXSelNetId above)
66
+    unsigned        hdrByteCnt; // size of the header record at transmission (used to locate the serialzed label)
66 67
     unsigned        rtSubIdx; // cmInvalidIdx or rtSubIdx
67 68
     unsigned        id;       // endptCnt     or endpoint id
68 69
     const cmChar_t* label;    // node         or endpoint label

Loading…
Cancel
Save