add timeout in read function