use Lwt_mutex/Mutex to guard each function call on a connection, so that reads/writes can't interleave badly.