X-Spam-Check-By: sourceware.org
Message-ID: <005201c73c15$464b7ac0$3001a8c0@Asymmetric>
From: "Enrique Perez-Terron" <enrio@online.no>
To: "Florent Morin" <morinflorent@gmail.com>, <cygwin@cygwin.com>
References: <25e2d6fe0701180840k6bd5b27di630bca3a0a010ac3@mail.gmail.com> 	 <45AFA5A5.3406349E@dessent.net> 	 <25e2d6fe0701180902m35903447w69c1ff91ef4eb8d1@mail.gmail.com> 	 <25e2d6fe0701190139r5e18aa89jc96e2229caaf8649@mail.gmail.com> <25e2d6fe0701190140u17a989fcva9e3cbf1d935ebd4@mail.gmail.com>
Subject: Re: cygwin 1.5.23-2 : I can't use select() with serial device and socket
Date: Fri, 19 Jan 2007 23:00:45 +0100
MIME-Version: 1.0
Content-Type: text/plain; 	format=flowed; 	charset="iso-8859-1"; 	reply-type=response
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Outlook Express 6.00.2900.3028
X-DCC-nextmail-Metrics: mail45.nsc.no 10045; Body=0 Fuz1=0 Fuz2=0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

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 
read?

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) {
      has_data(up_buffer))
        FD_SET(space_fd, &write_fdset);
      else
        FD_SET(earth_fd, &read_fds);
    }

    if (down_is_open) {
      if (has_data(down_buffer))
        FD_SET(earth_fd, &write_fdset);
      else
        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) {...}
  }

Regards 



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

