https://bugs.winehq.org/show_bug.cgi?id=40540
Bug ID: 40540 Summary: ReadFile overlapped not using ReadIntervalTimeout Product: Wine Version: 1.9.8 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: major Priority: P2 Component: -unknown Assignee: wine-bugs@winehq.org Reporter: henry@littau.org Distribution: ---
Created attachment 54371 --> https://bugs.winehq.org/attachment.cgi?id=54371 Copy of code where error occurs in Appload.exe
I am running on wine-1.9.8 (Staging).
Program is connected to a USB VCP serial device as COMnn. The behavior of overlapped reads is different between Windows and Wine. A Serial write is sent to the device, which triggers a response. The code below is waiting for the response. The response is 8 characters, pretty much immediately.
Under Wine, when I step with the VS2008 debugger remotely, the ReadFile returns with IO_Pending, and I see the eight characters in the read buffer. The call to WaitForSingleObject blocks until it times out, returns TIMEOUT, and the read process is considered failed.
Under Windows, ReadFile also returns IO_Pending, read buffer unmodified. The call to WaitForSingleObject returns Success. GetOverlappedResult succeeds with read length of 8. Life is good.
If I set dwToRead to 8 the code works correctly under Wine. When it is at 64, we have problems under Wine but not Windows. ReadIntervalTimeout in COMMTIMEOUTS is 1000 so after one second without new characters, the ReadFile should be considered complete and WaitForSingleObject should return. This appears not to be happening under Wine. Is this fixable under Wine?
Example code attached.
App is called Appload and is available here: https://wiki.opticonusa.com/techsupport/en/Appload
To run the app and demonstrate the issue you would need an Opticon barcode scanner, or a mock up of a scanner, on /dev/ttyACM0. App does an enumeration of COM devices, so Wine needs registry mods as described here: http://www.downtowndougbrown.com/2013/03/getting-x-ctu-in-wine-to-detect-you...
I can likely provide whatever a credible developer needs if the example attached is not sufficient.
https://bugs.winehq.org/show_bug.cgi?id=40540
henry@littau.org changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |henry@littau.org
https://bugs.winehq.org/show_bug.cgi?id=40540
Sebastian Lackner sebastian@fds-team.de changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |alexhenrie24@gmail.com, | |sebastian@fds-team.de
--- Comment #1 from Sebastian Lackner sebastian@fds-team.de --- @Alex Henrie: Could you take a look / try to reproduce the issue?
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |hardware
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #2 from Alex Henrie alexhenrie24@gmail.com --- Henry, I can't seem to reproduce this. Could you upload a complete test program to demonstrate the problem? You can base it on attachment 53426 to bug 39875.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #3 from henry@littau.org --- Created attachment 54482 --> https://bugs.winehq.org/attachment.cgi?id=54482 Fake device for null modem mock up
VS 2008 console app. leave it running while using the 40540Demo.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #4 from henry@littau.org --- Created attachment 54483 --> https://bugs.winehq.org/attachment.cgi?id=54483 Demo of issue
This on demonstrates working correctly without the use of WaitCommEvent, and when define is uncommented, incorrect function.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #5 from henry@littau.org --- I have attached two CPP files. Compile both with VS 2008 as console apps.
I have USB-RS232 adapter to null modem cable to 2nd USB-RS232 adapter plugged in and configured as COM31 and COM32.
Run 40540FakeDevice. It waits for any input, then sends some data back.
Run 40540Demo. You should see five successful transactions between the two programs using overlapped io. The hit key is there to give me time to attach a remote debugger.
Recompile 40540Demo with USE_WAITFOREVENT defined.
Run 40540Demo. It fails first time through the loop, reports, then fails elsewhere second time through the loop, reports, exits.
Bug 40540 is the first failure. I have not investigated the second, likely a clean up issue from the first.
I tried to reproduce the issue with one app, that's why the USE_COM1 define is in there. For some reason having the second com port in use in the single app does not reproduce the issue. I didn't bother with threads to investigate that further -- too easy to use another app :-)
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #6 from Alex Henrie alexhenrie24@gmail.com --- 40540Demo gives exactly the same output on both Wine and Windows.
Without USE_WAITFOREVENT:
Hit key
Waiting for the read operation to time out... Successfully read 'abcdefghijklmnopqrstuvwxyz' (27 bytes). Waiting for the read operation to time out... Successfully read 'abcdefghijklmnopqrstuvwxyz' (27 bytes). Waiting for the read operation to time out... Successfully read 'abcdefghijklmnopqrstuvwxyz' (27 bytes). Waiting for the read operation to time out... Successfully read 'abcdefghijklmnopqrstuvwxyz' (27 bytes). Waiting for the read operation to time out... Successfully read 'abcdefghijklmnopqrstuvwxyz' (27 bytes). Hit key
With USE_WAITFOREVENT:
Hit key
WaitForMultipleObjects failed with timeout WaitCommEvent failed with error 0x57 Hit key
In case you didn't know, you can cross-compile Windows programs with `wineg++ -m32 foobar.cpp -o foobar` and run them with `wine foobar.exe.so`. I did have to remove the '#include "stdafx.h"' and change "void main" to "int main" for your programs to compile.
I assume that you tested this program on Windows before uploading it, and that you didn't get an error. That would mean that there is something special about your Windows setup. What version of Windows do you have? Is it 32 or 64-bit? What happens if you compile and run your test programs on a slower computer?
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #7 from henry@littau.org --- Hi Alex,
On a slower computer I also see the timeout in WaitForMultipleObjects under Windows. That is likely an artifact of our little test environment, I have not seen this in real use. (Our devices run 9600 to 115200 baud and send 9 characters back, the test environment runs 2400 baud and sends 27 characters back once Windows gets around to switching tasks a couple times)
Bump the timeout on WaitForMultipleObjects to 1500: switch( WaitForMultipleObjects( dwCount, hEvents, FALSE, 1500 ) ) //::WaitForSingleObject( m_ovWait.hEvent, dwTimeout))
This should get you past the Windows speed issue.
I had no idea about wineg++, thank you, that is most helpful.
This issue, BTW, is the same under Wine and OS X. Should I file a bug specific to OS X or can this one be tagged for both?
I would also like to file a bug against WineHQ Buzilla because it thinks I spelled artifact wrong :-)
Henry
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #8 from Alex Henrie alexhenrie24@gmail.com --- (In reply to henry from comment #7)
Bump the timeout on WaitForMultipleObjects to 1500: switch( WaitForMultipleObjects( dwCount, hEvents, FALSE, 1500 ) ) //::WaitForSingleObject( m_ovWait.hEvent, dwTimeout))
This should get you past the Windows speed issue.
When I increase the WaitForMultipleObjects timeout to 1500, the test program succeeds on both Windows and Wine.
This issue, BTW, is the same under Wine and OS X. Should I file a bug specific to OS X or can this one be tagged for both?
There's no need to file a second bug report.
I would also like to file a bug against WineHQ Buzilla because it thinks I spelled artifact wrong :-)
That's your web browser doing the spell check, not Bugzilla...
If your only complaint is that Wine performs a little more slowly than Windows on the same hardware, that's not something that we can really fix. You'll just have to write your barcode scanner software so that it works on both fast and slow computers.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #9 from henry@littau.org --- Created attachment 54517 --> https://bugs.winehq.org/attachment.cgi?id=54517 New Demo of issue
Yikes!
So I think what was happening is running under the debugger gave me side-effects.
I attached a new version of the Demo. In this case the WaitForEvent stuff is left out. We go through the loop twice, once plain, once with an extra sleep.
Under Windows, both iterations succeed. Under Wine, first iteration succeeds, second iteration fails.
Good call, you are correct about the spell checker :-) My fresh Ubuntu install seems to have defaulted to British English for the Firefox spell checker...
Hopefully we now both see the same results.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #10 from Alex Henrie alexhenrie24@gmail.com --- Please update your programs so that they compile on wineg++ without any extra files. I don't want to spend any more time resolving compiler errors.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #11 from henry@littau.org --- Created attachment 54529 --> https://bugs.winehq.org/attachment.cgi?id=54529 wineg++ version of demo
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Attachment #54482|0 |1 is obsolete| | Attachment #54483|0 |1 is obsolete| | Attachment #54517|0 |1 is obsolete| | Attachment #54529|0 |1 is obsolete| |
--- Comment #12 from Alex Henrie alexhenrie24@gmail.com --- Created attachment 54538 --> https://bugs.winehq.org/attachment.cgi?id=54538 minimal test case
Okay, I played around with the new test program and determined that the problem is happening because of the Sleep call before the ReadFile call. This is definitely a bug in Wine. Attached is a much simplified test program--in fact, it's just attachment 53426 with a Sleep statement added.
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Summary|ReadFile overlapped not |ReadIntervalTimeout is |using ReadIntervalTimeout |ignored if there is data in | |the buffer when ReadFile is | |called and no data arrives | |after that Ever confirmed|0 |1 Status|UNCONFIRMED |NEW
--- Comment #13 from Alex Henrie alexhenrie24@gmail.com --- Changing status from UNCONFIRMED to NEW
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |testcase
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #14 from Alex Henrie alexhenrie24@gmail.com --- Created attachment 54627 --> https://bugs.winehq.org/attachment.cgi?id=54627 [PATCH] ntdll: Skip synchronous read if a serial read interval timeout is set.
Proposed patch
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |michael@fds-team.de
--- Comment #15 from Alex Henrie alexhenrie24@gmail.com --- Can this patch be included in Wine Staging?
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #16 from Bruno Jesus 00cpxxx@gmail.com --- Patch commited: http://source.winehq.org/git/wine.git/?a=commit;h=84fcaafb895f08b3513486f7b6...
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #17 from Alex Henrie alexhenrie24@gmail.com --- The test program is passing now - Thanks Alexandre!
Henry, can you retest your barcode scanner software with Wine 1.9.12?
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #18 from henry@littau.org --- I'm not building WINE so I had to wait for 1.9.12 Ubuntu binaries :-)
Short answer: Appload and a real barcode scanner still do not function correctly under Wine 1.9.12.
I see that our demo apps fail under 1.9.11 and now work under 1.9.12.
I will set up to do some remote debugging and try to characterize this further.
My offer to send to you a barcode scanner stands, if you think this would be helpful.
https://bugs.winehq.org/show_bug.cgi?id=40540
--- Comment #19 from henry@littau.org --- Sigh, spoke too soon. After a reboot of Ubuntu, Appload works correctly. Awesome!
Also checked it under Mac OS X. Works there as well!
Thank you much!
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Fixed by SHA1| |84fcaafb895f08b3513486f7b68 | |7882a2ffca1f8 Resolution|--- |FIXED
--- Comment #20 from Alex Henrie alexhenrie24@gmail.com --- You're welcome! I'm marking this bug RESOLVED FIXED.
https://bugs.winehq.org/show_bug.cgi?id=40540
Bruno Jesus 00cpxxx@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Component|-unknown |ntdll
https://bugs.winehq.org/show_bug.cgi?id=40540
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #21 from Alexandre Julliard julliard@winehq.org --- Closing bugs fixed in 1.9.13.
https://bugs.winehq.org/show_bug.cgi?id=40540
Alex Henrie alexhenrie24@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.winehq.org/sho | |w_bug.cgi?id=39875
https://bugs.winehq.org/show_bug.cgi?id=40540
Michael Stefaniuc mstefani@redhat.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |1.8.x CC| |mstefani@redhat.com
https://bugs.winehq.org/show_bug.cgi?id=40540
Michael Stefaniuc mstefani@redhat.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|1.8.x |---
--- Comment #22 from Michael Stefaniuc mstefani@redhat.com --- Removing 1.8.x milestone from bugs included in 1.8.6.