Rewrite write_nonblock_fully to include timeouts and use it