I'm writing a function to read from socket and return exact size of data. And I thought of codes like:
whlie len(buf) < required:
buf += socket.recv(required - len(buf))
return buf
But I think this might waste some CPU resources(not sure). I'm looking for a system call or something to return exact amount of data from socket, and it could be blocked until the required size is received.