return -1 when error in read or write