rewrite do_read so the looping happens outside in the main loop
use functions in rpc.c