MCPcopy
hub / github.com/python-trio/trio / receive

Method receive

src/trio/_dtls.py:1079–1103  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

acquireMethod · 0.45
acceptMethod · 0.45
test_channelFunction · 0.45
test_553Function · 0.45
test_close_basicsFunction · 0.45
receive_blockFunction · 0.45
test_close_syncFunction · 0.45
receive_will_closeFunction · 0.45
receive_will_succeedFunction · 0.45
do_receiveFunction · 0.45
test_channel_fairnessFunction · 0.45

Calls 3

do_handshakeMethod · 0.95
_check_replacedMethod · 0.95
_read_loopFunction · 0.85

Tested by 15

acquireMethod · 0.36
acceptMethod · 0.36
test_channelFunction · 0.36
test_553Function · 0.36
test_close_basicsFunction · 0.36
receive_blockFunction · 0.36
test_close_syncFunction · 0.36
receive_will_closeFunction · 0.36
receive_will_succeedFunction · 0.36
do_receiveFunction · 0.36
test_channel_fairnessFunction · 0.36