From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6937 invoked by alias); 22 Jan 2009 15:55:42 -0000 Received: (qmail 6911 invoked by uid 22791); 22 Jan 2009 15:55:41 -0000 X-Spam-Check-By: sourceware.org Received: from pool-71-126-240-83.bstnma.fios.verizon.net (HELO cgf.cx) (71.126.240.83) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 22 Jan 2009 15:55:34 +0000 Received: from ednor.cgf.cx (ednor.casa.cgf.cx [192.168.187.5]) by cgf.cx (Postfix) with ESMTP id 85ACD13C029 for ; Thu, 22 Jan 2009 10:55:24 -0500 (EST) Received: by ednor.cgf.cx (Postfix, from userid 201) id 6697A2B385; Thu, 22 Jan 2009 10:55:23 -0500 (EST) Date: Thu, 22 Jan 2009 16:24:00 -0000 From: Christopher Faylor To: cygwin@cygwin.com Subject: Re: Problem using select() with com0com virtual serial ports Message-ID: <20090122155522.GA5369@ednor.casa.cgf.cx> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: <7701e1400901220725r5712f806sff846b9aff8b4be3@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7701e1400901220725r5712f806sff846b9aff8b4be3@mail.gmail.com> User-Agent: Mutt/1.5.16 (2007-06-09) Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2009-01/txt/msg00674.txt.bz2 On Thu, Jan 22, 2009 at 10:25:32AM -0500, Paul Ingemi wrote: >I'm using Cygwin with com0com, and I find that every other time I read >a character from the virtual serial port, select() continues to >believe the serial port is ready, but then read() will block until a >character actually comes in. This does not happen with a real serial >port. > >Attached below is a test program which exhibits the symptoms when used >with com0com virtual serial ports. > >I worked around the problem by performing a second select() >immediately after the first one returns with ready file descriptors. >That second select determines which of these really are ready. > >Using strace and the source code for Cygwin, I worked with the author >of com0com, Vyacheslav Frolov, to find a potential problem and >solution. That thread is here: > >http://sourceforge.net/forum/forum.php?thread_id=2885701&forum_id=440108 > >Vyacheslav suggests that initially peek_serial() returns because >st.cbInQue is nonzero. However, since we didn't wait for a comm event, >EV_RXCHAR is still set on the comm handle. The next time into >select(), st.cbInQue is zero but WaitCommEvent succeeds immediately >due to the previously set event. > >By clearing the comm event mask (and therefore the comm event) before >setting it to EV_RXCHAR: > >select.cc function peek_serial(): > ... > SetCommMask (h, 0); // <=== added > SetCommMask (h, EV_RXCHAR); > ... This seems like a hack to me. I don't see anything in the MSDN documentation which would imply that SetCommMask (h, 0) should cause this type of behavior. Wouldn't the fact that this works for a regular serial driver imply that there is a problem with the com0com driver? It is a simple enough hack that I don't mind adding it, if it fixes your problem but I am not convinced that your driver is operating correctly. cgf -- 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/