Reads exactly n bytes from socket Raises SocketError if there isn't enough data
(socket, n)
| 60 | |
| 61 | |
| 62 | def read_exactly(socket, n): |
| 63 | """ |
| 64 | Reads exactly n bytes from socket |
| 65 | Raises SocketError if there isn't enough data |
| 66 | """ |
| 67 | data = b"" |
| 68 | while len(data) < n: |
| 69 | next_data = read(socket, n - len(data)) |
| 70 | if not next_data: |
| 71 | raise SocketError("Unexpected EOF") |
| 72 | data += next_data |
| 73 | return data |
| 74 | |
| 75 | |
| 76 | def next_frame_header(socket): |