(self, event: events.Pong)
| 252 | self.transport.write(self.conn.send(event.response())) |
| 253 | |
| 254 | def handle_pong(self, event: events.Pong) -> None: |
| 255 | class="cm"># Ignore unsolicited pongs and stale pongs whose payload doesn't match the ping currently in flight. |
| 256 | if self.pending_ping_payload is None or bytes(event.payload) != self.pending_ping_payload: |
| 257 | return class="cm"># pragma: no cover |
| 258 | |
| 259 | self.last_ping_rtt = self.loop.time() - self.ping_sent_at |
| 260 | self.pending_ping_payload = None |
| 261 | class="cm"># The peer answered in time; cancel the pong deadline and chain the next ping. This `schedule_ping()` call is |
| 262 | class="cm"># what keeps the keepalive loop running when ping_timeout is set. When ping_timeout is None the next ping is |
| 263 | class="cm"># already scheduled by `send_keepalive_ping`, so we must not schedule a duplicate here. |
| 264 | if self.pong_timer is not None: |
| 265 | self.pong_timer.cancel() |
| 266 | self.pong_timer = None |
| 267 | self.schedule_ping() |
| 268 | |
| 269 | def start_keepalive(self) -> None: |
| 270 | if self.ping_interval is not None and self.ping_interval > 0: |
no test coverage detected