I'm reading information from a serial port using this code:
struct termios tio;
memset(&tio, 0, sizeof(tio));
// Open serial port in mode `8N1', non-blocking
tio.c_cflag = CS8 | CREAD | CLOCAL;
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 10;
int fd = open("/dev/ttyACM1", O_RDONLY);
cfsetospeed(&tio, B9600);
cfsetispeed(&tio, B9600);
tcsetattr(fd, TCSANOW, &tio);
unsigned char byte = '0';
// check for input from arduino
while (!quit)
{
    keyboardInput(quit);
    read(fd, &byte, 1);
    if ((byte == '1' || quit)
    {
        oldByteDoor = '1';
        break;
    }
}
where keyboardInput(quit) sets quit to true when the close button of the window is pressed.
If nothing is in the serial port it gets stuck at read(fd, &byte, 1) forever.
How can I prevent this?
Thanks