瀏覽代碼

cmRtNet.h/c:Added cmRtNetIsInitialized() and check for non-blank node label and bcast address.

master
kpl 11 年之前
父節點
當前提交
e8e3f189ed
共有 2 個檔案被更改,包括 22 行新增1 行删除
  1. 20
    1
      cmRtNet.c
  2. 2
    0
      cmRtNet.h

+ 20
- 1
cmRtNet.c 查看文件

4
 #include "cmCtx.h"
4
 #include "cmCtx.h"
5
 #include "cmMem.h"
5
 #include "cmMem.h"
6
 #include "cmMallocDebug.h"
6
 #include "cmMallocDebug.h"
7
+#include "cmLinkedHeap.h"
7
 #include "cmUdpPort.h"
8
 #include "cmUdpPort.h"
8
 #include "cmRtNet.h"
9
 #include "cmRtNet.h"
9
 #include "cmTime.h"
10
 #include "cmTime.h"
10
 #include "cmRtSysMsg.h"
11
 #include "cmRtSysMsg.h"
12
+#include "cmText.h"
11
 
13
 
12
 // flags for cmRtNetNode_t.flags;
14
 // flags for cmRtNetNode_t.flags;
13
 enum
15
 enum
193
   cmRtNetRC_t rc = kOkNetRC;
195
   cmRtNetRC_t rc = kOkNetRC;
194
   cmRtNetNode_t* np;
196
   cmRtNetNode_t* np;
195
 
197
 
196
-  if( label == NULL )
198
+  if( cmTextIsEmpty(label) )
197
     return cmErrMsg(&p->err,kInvalidLabelNetRC,"A null or blank node label was encountered.");
199
     return cmErrMsg(&p->err,kInvalidLabelNetRC,"A null or blank node label was encountered.");
198
 
200
 
199
   if((np = _cmRtNetFindNode(p,label)) != NULL )
201
   if((np = _cmRtNetFindNode(p,label)) != NULL )
620
   if((rc = cmRtNetFinalize(h)) != kOkNetRC )
622
   if((rc = cmRtNetFinalize(h)) != kOkNetRC )
621
     goto errLabel;
623
     goto errLabel;
622
 
624
 
625
+  if( cmTextIsEmpty(bcastAddr) )
626
+  {
627
+    rc = cmErrMsg(&p->err,kInvalidArgNetRC,"The 'broadcast address' is not valid.");
628
+    goto errLabel;
629
+  }
630
+
623
   // if this is the local node then initialze the local socket
631
   // if this is the local node then initialze the local socket
624
   if( cmUdpInit(p->udpH,port,kNonBlockingUdpFl | kBroadcastUdpFl,_cmRtNetRecv,p,NULL,0,p->udpRecvBufByteCnt,p->udpTimeOutMs) != kOkUdpRC )
632
   if( cmUdpInit(p->udpH,port,kNonBlockingUdpFl | kBroadcastUdpFl,_cmRtNetRecv,p,NULL,0,p->udpRecvBufByteCnt,p->udpTimeOutMs) != kOkUdpRC )
625
   {
633
   {
647
   return rc;
655
   return rc;
648
 }
656
 }
649
 
657
 
658
+
659
+bool cmRtNetIsInitialized( cmRtNetH_t h )
660
+{
661
+  if( cmRtNetIsValid(h) == false )
662
+    return false;
663
+
664
+  cmRtNet_t* p = _cmRtNetHandleToPtr(h);
665
+  return p->localNode != NULL && cmTextIsNotEmpty(p->bcastAddr);
666
+}
667
+
668
+
650
 cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId )
669
 cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId )
651
 {
670
 {
652
   cmRtNetRC_t rc = kOkNetRC;
671
   cmRtNetRC_t rc = kOkNetRC;

+ 2
- 0
cmRtNet.h 查看文件

18
     kNodeNotFoundNetRC,
18
     kNodeNotFoundNetRC,
19
     kEndNotFoundNetRC,
19
     kEndNotFoundNetRC,
20
     kLocalNodeNetRC,
20
     kLocalNodeNetRC,
21
+    kInvalidArgNetRC,
21
     kSyncFailNetRC,
22
     kSyncFailNetRC,
22
     kNodeEndCntErrNetRC
23
     kNodeEndCntErrNetRC
23
   };
24
   };
47
   // 'ipPort' refers to the socket port (which may need to be made available 
48
   // 'ipPort' refers to the socket port (which may need to be made available 
48
   // by the machine firewall cfg.)
49
   // by the machine firewall cfg.)
49
   cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
50
   cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
51
+  bool        cmRtNetIsInitialized( cmRtNetH_t h );
50
 
52
 
51
   // Register the local endpoints.
53
   // Register the local endpoints.
52
   // Endpoints may only be registered once the network is initialized via
54
   // Endpoints may only be registered once the network is initialized via

Loading…
取消
儲存