Still debugging, but shoud use select inside read data in order to get a timeout and avoid forever blocking read