cygwin 1.5.23-2 : I can't use select() with serial device and socket

Enrique Perez-Terron
Fri Jan 19 22:00:00 GMT 2007

You don't show the complete output of the two programs. Do you have a device 
connected to the serial port that echoes the data written? Or  a device that 
provides some data to read? With the first program, how many bytes does it 

Is the serial port set driver set to generate echo locally? On Linux? On XP? 
On both?

> The second code write on socket, but it says that serial port isn't ready 
> to read.

Your select statement appears to tell that there are no data available to 
read on the serial port.

You should normally write select() read-write loops so that file descriptors 
are entered into the write_fdset only if there is something to write. 
Otherwise the program will be running in a tight loop because the the 
select() returns telling that (e.g) the serial_fd is ready to accept more 
data. The point in using select is to have the program sleep until there is 
something to do.

  while(up_is_open || down_is_open)
    if (up_is_open) {
        FD_SET(space_fd, &write_fdset);
        FD_SET(earth_fd, &read_fds);

    if (down_is_open) {
      if (has_data(down_buffer))
        FD_SET(earth_fd, &write_fdset);
        FD_SET(space_fd, &read_fdset);

    ready_fds = select(max_fd, &read_fdset, &write_fdset, NULL, NULL);
    if (ready_fds < 0) {...}

    if (FD_ISSET(earth_fd, &write_fdset) {...}
    if (FD_ISSET(space_fd, &write_fdset) {...}
    if (FD_ISSET(earth_fd, &read_fdset) {...}
    if (FD_ISSET(space_fd, &read_fdset) {...}


Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list