(size)
| 124 | stream.sendall(struct.pack(">I", len(frame)) + frame) |
| 125 | |
| 126 | def read_exact(size): |
| 127 | data = bytearray() |
| 128 | while len(data) < size: |
| 129 | chunk = stream.recv(size - len(data)) |
| 130 | if not chunk: |
| 131 | raise RuntimeError("owner closed connection before response") |
| 132 | data.extend(chunk) |
| 133 | return data |
| 134 | |
| 135 | size = struct.unpack(">I", read_exact(4))[0] |
| 136 | if not 0 < size <= 8 * 1024 * 1024: |