瀏覽代碼

cmRtNet.h/c:Added cmRtNetLocalHostName(). Replaced use of cmUdpHostNameXXX() w/ cmUdpHostName() in cmRtNetTest().

master
kpl 11 年之前
父節點
當前提交
bb1e86f9de
共有 2 個文件被更改,包括 20 次插入10 次删除
  1. 17
    9
      cmRtNet.c
  2. 3
    1
      cmRtNet.h

+ 17
- 9
cmRtNet.c 查看文件

415
   return rc;
415
   return rc;
416
 }
416
 }
417
 
417
 
418
+const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h )
419
+{
420
+  cmRtNet_t*  p = _cmRtNetHandleToPtr(h);
421
+  return cmUdpHostName(p->udpH);
422
+}
423
+
424
+
418
 bool cmRtNetIsValid( cmRtNetH_t h )
425
 bool cmRtNetIsValid( cmRtNetH_t h )
419
 { return h.h !=NULL; }
426
 { return h.h !=NULL; }
420
 
427
 
852
 
859
 
853
 void  cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
860
 void  cmRtNetTest( cmCtx_t* ctx, bool mstrFl )
854
 {
861
 {
855
-  char c;
856
-  _cmRtNetTest_t t;
857
-  cmUdpPort_t port = 5876;
858
-  _cmRtNetTest_t* p = &t;
859
-  cmRtNetRC_t rc = kOkNetRC;
860
-  unsigned hn = cmUdpHostNameMaxCharCount();
861
-  cmChar_t hostNameStr[ hn ];
862
+  char            c;
863
+  _cmRtNetTest_t  t;
864
+  const cmChar_t* hostNameStr;
865
+  cmUdpPort_t     port = 5876;
866
+  _cmRtNetTest_t* p    = &t;
867
+  cmRtNetRC_t     rc   = kOkNetRC;
862
   memset(&t,0,sizeof(t));
868
   memset(&t,0,sizeof(t));
863
 
869
 
864
-  if( cmUdpHostName(hostNameStr,hn) != kOkUdpRC )
865
-    goto errLabel;
866
 
870
 
867
   if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
871
   if( cmThreadCreate(&p->thH,_cmRtNetTestThreadFunc,p,&ctx->rpt) != kOkThRC )
868
     goto errLabel;
872
     goto errLabel;
870
   if((rc = cmRtNetAlloc(ctx,&p->netH,_cmRtNetTestRecv,p)) != kOkNetRC )
874
   if((rc = cmRtNetAlloc(ctx,&p->netH,_cmRtNetTestRecv,p)) != kOkNetRC )
871
     goto errLabel;
875
     goto errLabel;
872
 
876
 
877
+  hostNameStr = cmRtNetLocalHostName(p->netH);
878
+  if( hostNameStr == NULL )
879
+    hostNameStr = "<no-host-name>";
880
+
873
   if((rc = cmRtNetCreateNode(p->netH, hostNameStr, NULL, port )) != kOkNetRC)
881
   if((rc = cmRtNetCreateNode(p->netH, hostNameStr, NULL, port )) != kOkNetRC)
874
     goto errLabel;
882
     goto errLabel;
875
 
883
 

+ 3
- 1
cmRtNet.h 查看文件

34
 
34
 
35
   bool      cmRtNetIsValid( cmRtNetH_t h );
35
   bool      cmRtNetIsValid( cmRtNetH_t h );
36
 
36
 
37
+  const cmChar_t* cmRtNetLocalHostName( cmRtNetH_t h );
37
 
38
 
38
   // Create a network node.
39
   // Create a network node.
39
   // The 'nodeLabel' refers to a network device cfg. (see cmDevCfg).
40
   // The 'nodeLabel' refers to a network device cfg. (see cmDevCfg).
42
   // nodes in the node list.
43
   // nodes in the node list.
43
   cmRtNetRC_t cmRtNetCreateNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
44
   cmRtNetRC_t cmRtNetCreateNode( cmRtNetH_t h, const cmChar_t* nodeLabel, const cmChar_t* ipAddr, cmUdpPort_t ipPort );
44
 
45
 
46
+
45
   // Register the local endpoints.
47
   // Register the local endpoints.
46
   // Remote nodes will be able to send messages to these endpoints by
48
   // Remote nodes will be able to send messages to these endpoints by
47
   // referring to (nodeLabel/endPtLabel)
49
   // referring to (nodeLabel/endPtLabel)
61
   // an endpoint it updates it's own remote node/endpoint 
63
   // an endpoint it updates it's own remote node/endpoint 
62
   // list.
64
   // list.
63
   cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
65
   cmRtNetRC_t cmRtNetBeginSyncMode( cmRtNetH_t h );
64
-  bool      cmRtNetIsInSyncMode(  cmRtNetH_t h );
66
+  bool        cmRtNetIsInSyncMode(  cmRtNetH_t h );
65
 
67
 
66
   // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') 
68
   // When the network message recieve function (See cmRtNetAlloc() 'cbFunc') 
67
   // receives a message with the cmRtSysMsgHdr_t.selId == kNetSyncSelRtId
69
   // receives a message with the cmRtSysMsgHdr_t.selId == kNetSyncSelRtId

Loading…
取消
儲存