Send a ping and wait for a pong if ping_timeout is configured. Called periodically if the websocket_ping_interval is set and non-zero.
(self)
| 1352 | return max(0, last_ping_time + interval - now) |
| 1353 | |
| 1354 | async def periodic_ping(self) -> None: |
| 1355 | """Send a ping and wait for a pong if ping_timeout is configured. |
| 1356 | |
| 1357 | Called periodically if the websocket_ping_interval is set and non-zero. |
| 1358 | """ |
| 1359 | interval = self.ping_interval |
| 1360 | timeout = self.ping_timeout |
| 1361 | |
| 1362 | await asyncio.sleep(interval) |
| 1363 | |
| 1364 | while True: |
| 1365 | # send a ping |
| 1366 | self._received_pong = False |
| 1367 | ping_time = IOLoop.current().time() |
| 1368 | self.write_ping(b"") |
| 1369 | |
| 1370 | # wait until the ping timeout |
| 1371 | await asyncio.sleep(timeout) |
| 1372 | |
| 1373 | # make sure we received a pong within the timeout |
| 1374 | if timeout > 0 and not self._received_pong: |
| 1375 | self.close(reason="ping timed out") |
| 1376 | return |
| 1377 | |
| 1378 | # wait until the next scheduled ping |
| 1379 | await asyncio.sleep( |
| 1380 | self.ping_sleep_time( |
| 1381 | last_ping_time=ping_time, |
| 1382 | interval=interval, |
| 1383 | now=IOLoop.current().time(), |
| 1384 | ) |
| 1385 | ) |
| 1386 | |
| 1387 | |
| 1388 | class WebSocketClientConnection(simple_httpclient._HTTPConnection): |
no test coverage detected