Skip to content

Commit

Permalink
[asyncio] make quic_event_received public API
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Aug 11, 2019
1 parent f881307 commit 12f227b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
26 changes: 14 additions & 12 deletions aioquic/asyncio/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,9 @@ def datagram_received(self, data: Union[bytes, Text], addr: NetworkAddress) -> N
self._quic.receive_datagram(cast(bytes, data), addr, now=self._loop.time())
self._send_pending()

# private
# overridable

def _create_stream(
self, stream_id: int
) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]:
adapter = QuicStreamAdapter(self, stream_id)
reader = asyncio.StreamReader()
writer = asyncio.StreamWriter(adapter, None, reader, None)
self._stream_readers[stream_id] = reader
return reader, writer

def _handle_event(self, event: events.QuicEvent) -> None:
def quic_event_received(self, event: events.QuicEvent) -> None:
if isinstance(event, events.ConnectionIdIssued):
self._connection_id_issued_handler(event.connection_id)
elif isinstance(event, events.ConnectionIdRetired):
Expand All @@ -149,6 +140,17 @@ def _handle_event(self, event: events.QuicEvent) -> None:
if event.end_stream:
reader.feed_eof()

# private

def _create_stream(
self, stream_id: int
) -> Tuple[asyncio.StreamReader, asyncio.StreamWriter]:
adapter = QuicStreamAdapter(self, stream_id)
reader = asyncio.StreamReader()
writer = asyncio.StreamWriter(adapter, None, reader, None)
self._stream_readers[stream_id] = reader
return reader, writer

def _handle_timer(self) -> None:
now = max(self._timer_at, self._loop.time())
self._timer = None
Expand All @@ -162,7 +164,7 @@ def _send_pending(self) -> None:
# process events
event = self._quic.next_event()
while event is not None:
self._handle_event(event)
self.quic_event_received(event)
event = self._quic.next_event()

# send datagrams
Expand Down
2 changes: 1 addition & 1 deletion examples/http3-client.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def get(self, netloc: str, path: str) -> Deque[Event]:

return await asyncio.shield(waiter)

def _handle_event(self, event: QuicEvent):
def quic_event_received(self, event: QuicEvent):
#  pass event to the HTTP layer
for http_event in self._http.handle_event(event):
if (
Expand Down
2 changes: 1 addition & 1 deletion examples/http3-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __init__(self, quic: QuicConnection, server: HttpServer):
self._http: Optional[HttpConnection] = None
self._server = server

def _handle_event(self, event: QuicEvent):
def quic_event_received(self, event: QuicEvent):
if isinstance(event, aioquic.quic.events.ConnectionTerminated):
# remove the connection
for cid, protocol in list(self._server._protocols.items()):
Expand Down

0 comments on commit 12f227b

Please sign in to comment.