Ver código fonte

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

master
kpl 11 anos atrás
pai
commit
e8e3f189ed
2 arquivos alterados com 22 adições e 1 exclusões
  1. 20
    1
      cmRtNet.c
  2. 2
    0
      cmRtNet.h

+ 20
- 1
cmRtNet.c Ver arquivo

@@ -4,10 +4,12 @@
4 4
 #include "cmCtx.h"
5 5
 #include "cmMem.h"
6 6
 #include "cmMallocDebug.h"
7
+#include "cmLinkedHeap.h"
7 8
 #include "cmUdpPort.h"
8 9
 #include "cmRtNet.h"
9 10
 #include "cmTime.h"
10 11
 #include "cmRtSysMsg.h"
12
+#include "cmText.h"
11 13
 
12 14
 // flags for cmRtNetNode_t.flags;
13 15
 enum
@@ -193,7 +195,7 @@ cmRtNetRC_t _cmRtNetCreateNode( cmRtNet_t* p, const cmChar_t* label, const cmCha
193 195
   cmRtNetRC_t rc = kOkNetRC;
194 196
   cmRtNetNode_t* np;
195 197
 
196
-  if( label == NULL )
198
+  if( cmTextIsEmpty(label) )
197 199
     return cmErrMsg(&p->err,kInvalidLabelNetRC,"A null or blank node label was encountered.");
198 200
 
199 201
   if((np = _cmRtNetFindNode(p,label)) != NULL )
@@ -620,6 +622,12 @@ cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cm
620 622
   if((rc = cmRtNetFinalize(h)) != kOkNetRC )
621 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 631
   // if this is the local node then initialze the local socket
624 632
   if( cmUdpInit(p->udpH,port,kNonBlockingUdpFl | kBroadcastUdpFl,_cmRtNetRecv,p,NULL,0,p->udpRecvBufByteCnt,p->udpTimeOutMs) != kOkUdpRC )
625 633
   {
@@ -647,6 +655,17 @@ cmRtNetRC_t cmRtNetInitialize( cmRtNetH_t h, const cmChar_t* bcastAddr, const cm
647 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 669
 cmRtNetRC_t cmRtNetRegisterEndPoint( cmRtNetH_t h, const cmChar_t* endPtLabel, unsigned endPtId )
651 670
 {
652 671
   cmRtNetRC_t rc = kOkNetRC;

+ 2
- 0
cmRtNet.h Ver arquivo

@@ -18,6 +18,7 @@ extern "C" {
18 18
     kNodeNotFoundNetRC,
19 19
     kEndNotFoundNetRC,
20 20
     kLocalNodeNetRC,
21
+    kInvalidArgNetRC,
21 22
     kSyncFailNetRC,
22 23
     kNodeEndCntErrNetRC
23 24
   };
@@ -47,6 +48,7 @@ extern "C" {
47 48
   // 'ipPort' refers to the socket port (which may need to be made available 
48 49
   // by the machine firewall cfg.)
49 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 53
   // Register the local endpoints.
52 54
   // Endpoints may only be registered once the network is initialized via

Carregando…
Cancelar
Salvar