MCPcopy Create free account
hub / github.com/cppla/ServerStatus / _ping_thread

Function _ping_thread

clients/client-linux.py:204–240  ·  view source on GitHub ↗
(host, mark, port)

Source from the content-addressed store, hash-verified

202monitorServer = {}
203
204def _ping_thread(host, mark, port):
205 lostPacket = 0
206 packet_queue = Queue(maxsize=PING_PACKET_HISTORY_LEN)
207
208 while True:
209 # flush dns , every time.
210 IP = host
211 if host.count(':') < 1: # if not plain ipv6 address, means ipv4 address or hostname
212 try:
213 if PROBE_PROTOCOL_PREFER == 'ipv4':
214 IP = socket.getaddrinfo(host, None, socket.AF_INET)[0][4][0]
215 else:
216 IP = socket.getaddrinfo(host, None, socket.AF_INET6)[0][4][0]
217 except Exception:
218 pass
219
220 if packet_queue.full():
221 if packet_queue.get() == 0:
222 lostPacket -= 1
223 try:
224 b = timeit.default_timer()
225 socket.create_connection((IP, port), timeout=1).close()
226 pingTime[mark] = int((timeit.default_timer() - b) * 1000)
227 packet_queue.put(1)
228 except socket.error as error:
229 if error.errno == errno.ECONNREFUSED:
230 pingTime[mark] = int((timeit.default_timer() - b) * 1000)
231 packet_queue.put(1)
232 #elif error.errno == errno.ETIMEDOUT:
233 else:
234 lostPacket += 1
235 packet_queue.put(0)
236
237 if packet_queue.qsize() > 30:
238 lostRate[mark] = float(lostPacket) / packet_queue.qsize()
239
240 time.sleep(INTERVAL)
241
242def _net_speed():
243 while True:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected