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

+ 1
- 0
cmRtNet.h View File

63
   {
63
   {
64
     cmRtSysMsgHdr_t hdr;      // standard cmRtSys msg  header 
64
     cmRtSysMsgHdr_t hdr;      // standard cmRtSys msg  header 
65
     cmRtNetSelId_t  selId;    // message selector id (See kXXXSelNetId above)
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
     unsigned        rtSubIdx; // cmInvalidIdx or rtSubIdx
67
     unsigned        rtSubIdx; // cmInvalidIdx or rtSubIdx
67
     unsigned        id;       // endptCnt     or endpoint id
68
     unsigned        id;       // endptCnt     or endpoint id
68
     const cmChar_t* label;    // node         or endpoint label
69
     const cmChar_t* label;    // node         or endpoint label

Loading…
Cancel
Save