This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem using select() with com0com virtual serial ports


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);
  ...

we were able to build a custom cygwin1.dll that eliminates the
problem. I'm not a Win32 coder so I'm not comfortable submitting this
as a patch, but hopefully someone with the big picture view of how
this is supposed to work can take a look.

(I've redacted the cygcheck output because of the data it reveals
about my employer)

Attachment: testcomm.c
Description: Text document

Attachment: cygcheck.redacted.out
Description: Binary data

--
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/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]