select() blocks

Adhemerval Zanella adhemerval.zanella@linaro.org
Mon Apr 23 11:12:00 GMT 2018



On 23/04/2018 06:41, Levente wrote:
> Dear List,
> 
> 
> I'd like to ask a question before I file a bug report.
> 
> I'm monitoring a file descriptor with select(). The file descriptor is
> connected to a serial port, which is in reality a USB-serial
> converter. When calling select() with a finite timeout, and
> disconnecting the USB-serial converter, select() blocks forever.
> 
> Is this intentional?
> 
> I have this select() call:
> 
>             ret = select(serial->fd+1, &rfds, NULL, NULL, &tv_timeout);
> 
> I'm on a Debian stable, using libc-bin version 2.24-11+deb9u3. I have
> similar issue on OpenWRT.

Maybe this tip [1] may help you? In any case, select is just a direct 
wrapper for architectures that define __NR_select (which I assume it is
your case)  or a __NR_pselect6 call where it adjusts the timeout from a
'struct timeval' to 'struct timespec ts'.

All USB, tty, etc interaction over file descriptors are handled in kernel,
so it is most likely a kernel issue (if it is really an issue).

[1] https://stackoverflow.com/questions/34170350/detecting-if-a-character-device-has-disconnected-in-linux-in-with-termios-api-c



More information about the Libc-help mailing list