Skip to content

Commit 9e34634

Browse files
committed
make sure to read full message in async rawsocket
1 parent 0b4be95 commit 9e34634

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

xconn/transports.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ async def connect(
171171
writer.write(hs_request.to_bytes())
172172
await writer.drain()
173173

174-
hs_response_bytes = await reader.read(RAW_SOCKET_HEADER_LENGTH)
174+
hs_response_bytes = await reader.readexactly(RAW_SOCKET_HEADER_LENGTH)
175175
hs_response = Handshake.from_bytes(hs_response_bytes)
176176

177177
if hs_request.protocol != hs_response.protocol:
@@ -180,13 +180,13 @@ async def connect(
180180
return AsyncRawSocketTransport(reader, writer)
181181

182182
async def read(self) -> str | bytes:
183-
msg_header_bytes = await self._reader.read(RAW_SOCKET_HEADER_LENGTH)
183+
msg_header_bytes = await self._reader.readexactly(RAW_SOCKET_HEADER_LENGTH)
184184
msg_header = MessageHeader.from_bytes(msg_header_bytes)
185185

186186
if msg_header.kind == MSG_TYPE_WAMP:
187-
return await self._reader.read(msg_header.length)
187+
return await self._reader.readexactly(msg_header.length)
188188
elif msg_header.kind == MSG_TYPE_PING:
189-
ping_payload = await self._reader.read(msg_header.length)
189+
ping_payload = await self._reader.readexactly(msg_header.length)
190190
pong = MessageHeader(MSG_TYPE_PONG, msg_header.length)
191191
self._writer.write(pong.to_bytes())
192192
await self._writer.drain()
@@ -195,7 +195,7 @@ async def read(self) -> str | bytes:
195195

196196
return await self.read()
197197
elif msg_header.kind == MSG_TYPE_PONG:
198-
pong_payload = await self._reader.read(msg_header.length)
198+
pong_payload = await self._reader.readexactly(msg_header.length)
199199
pending_ping = self._pending_pings.pop(pong_payload, None)
200200
if pending_ping is not None:
201201
received_at = time.time() * 1000

0 commit comments

Comments
 (0)