Fetch the next packet of data from this connection's peer, waiting if necessary. This is safe to call from multiple tasks simultaneously, in case you have some reason to do that. And more importantly, it's cancellation-safe, meaning that cancelling a call to `receive
(self)
| 1077 | ) |
| 1078 | |
| 1079 | async def receive(self) -> bytes: |
| 1080 | """Fetch the next packet of data from this connection's peer, waiting if |
| 1081 | necessary. |
| 1082 | |
| 1083 | This is safe to call from multiple tasks simultaneously, in case you have some |
| 1084 | reason to do that. And more importantly, it's cancellation-safe, meaning that |
| 1085 | cancelling a call to `receive` will never cause a packet to be lost or corrupt |
| 1086 | the underlying connection. |
| 1087 | |
| 1088 | """ |
| 1089 | if not self._did_handshake: |
| 1090 | await self.do_handshake() |
| 1091 | # If the packet isn't really valid, then openssl can decode it to the empty |
| 1092 | # string (e.g. b/c it's a late-arriving handshake packet, or a duplicate copy of |
| 1093 | # a data packet). Skip over these instead of returning them. |
| 1094 | while True: |
| 1095 | try: |
| 1096 | packet = await self._q.r.receive() |
| 1097 | except trio.EndOfChannel: |
| 1098 | assert self._replaced |
| 1099 | self._check_replaced() |
| 1100 | self._ssl.bio_write(packet) |
| 1101 | cleartext = _read_loop(self._ssl.read) |
| 1102 | if cleartext: |
| 1103 | return cleartext |
| 1104 | |
| 1105 | def set_ciphertext_mtu(self, new_mtu: int) -> None: |
| 1106 | """Tells Trio the `largest amount of data that can be sent in a single packet to |