@@ -124,7 +124,7 @@ def printMessage(msg):
124124 state = canLink .getState ()
125125 if state == CanLink .State .Permitted :
126126 break
127- physicalLayer .receiveAll (sock , verbose = settings [ 'trace' ] )
127+ physicalLayer .receiveAll (sock , verbose = True )
128128 physicalLayer .sendAll (sock , verbose = True )
129129
130130
@@ -140,15 +140,20 @@ def printMessage(msg):
140140print ("nodeIdToAlias: {}" .format (canLink .nodeIdToAlias ))
141141
142142
143- def receiveLoop ():
143+ def socketLoop ():
144144 """put the read on a separate thread"""
145145 while True :
146- physicalLayer .receiveAll (sock , verbose = settings ['trace' ])
147- precise_sleep (.01 )
146+ count = 0
147+ count += physicalLayer .sendAll (sock , verbose = True )
148+ count += physicalLayer .receiveAll (sock , verbose = True )
149+ if count < 1 :
150+ precise_sleep (.01 )
151+ # else no sleep (socket already delayed)
152+ print ("Stopped receiving." )
148153
149154
150155import threading # noqa E402
151- thread = threading .Thread (daemon = True , target = receiveLoop )
156+ thread = threading .Thread (daemon = True , target = socketLoop )
152157
153158
154159def result (arg1 , arg2 = None , arg3 = None , result = True ) :
@@ -199,17 +204,23 @@ def result(arg1, arg2=None, arg3=None, result=True) :
199204 NodeID (settings ['localNodeID' ]), None )
200205if settings ['trace' ] : print ("SM: {}" .format (message ))
201206canLink .sendMessage (message )
202- physicalLayer .sendAll (sock )
203- # pull the received messages
204- while True :
205- try :
206- received = readQueue .get (True , settings ['timeout' ])
207- if settings ['trace' ]:
208- print ("received: " , received )
209- except Empty :
210- break
211207
208+ # physicalLayer.sendAll(sock, verbose=True) # can't use port on 2 threads!
209+ # (moved to socketLoop)
210+
211+ # pull the received messages
212+ # Commented since using verbose=True for receiveAll
213+ # while True :
214+ # # physicalLayer.sendAll(sock, verbose=True)
215+ # try :
216+ # received = readQueue.get(True, settings['timeout'])
217+ # if settings['trace']:
218+ # print("received: ", received)
219+ # except Empty:
220+ # break
212221# print the resulting node store contents
222+ print ("\n Waiting for SNIP requests and responses..." )
223+ precise_sleep (2 ) # Wait for approximately all SNIP info to arrive.
213224print ("\n Discovered nodes:" )
214225
215226for node in remoteNodeStore .asArray () :
0 commit comments