Handle the full lifetime of a single connection
(
self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter
)
| 69 | self.decoder = msgspec.msgpack.Decoder(Request) |
| 70 | |
| 71 | async def handle_connection( |
| 72 | self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter |
| 73 | ): |
| 74 | """Handle the full lifetime of a single connection""" |
| 75 | print("Connection opened") |
| 76 | while True: |
| 77 | try: |
| 78 | # Receive and decode a request |
| 79 | buffer = await prefixed_recv(reader) |
| 80 | req = self.decoder.decode(buffer) |
| 81 | |
| 82 | # Process the request |
| 83 | resp = await self.handle_request(req) |
| 84 | |
| 85 | # Encode and write the response |
| 86 | buffer = self.encoder.encode(resp) |
| 87 | await prefixed_send(writer, buffer) |
| 88 | except EOFError: |
| 89 | print("Connection closed") |
| 90 | return |
| 91 | |
| 92 | async def handle_request(self, req: Request) -> Any: |
| 93 | """Handle a single request and return the result (if any)""" |
nothing calls this directly
no test coverage detected