MCPcopy
hub / github.com/encode/uvicorn / handle_pong

Method handle_pong

uvicorn/protocols/websockets/wsproto_impl.py:254–267  ·  uvicorn/protocols/websockets/wsproto_impl.py::WSProtocol.handle_pong
(self, event: events.Pong)

Source from the content-addressed store, hash-verified

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:

Callers 1

handle_eventsMethod · 0.95

Calls 2

schedule_pingMethod · 0.95
cancelMethod · 0.45

Tested by

no test coverage detected