Check the return value of read()/write()