(sock, length)
| 3 | # Working: nbd protocol, read/write serving up files, error handling, file size detection, in theory, large file support... not really, so_reuseaddr, nonforking |
| 4 | |
| 5 | def recvall(sock, length): |
| 6 | rv = [] |
| 7 | while sum(map(len, rv)) < length: |
| 8 | rv.append(sock.recv(length-sum(map(len, rv)))) |
| 9 | assert rv[-1], "no more data to read" |
| 10 | return ''.join(rv) |
| 11 | |
| 12 | def serveclient(): |
| 13 | READ, WRITE, CLOSE = 0,1,2 |