I wrote a simple test program and ran it under Windows, to see what Windows does. I've attached the program here. I found that...
Eric Pouech pouech-eric@wanadoo.fr writes:
[...]
I'm not sure this is a correct fix:
- you modify the passed overlapped structure (by filling in the
hEvent), I'm not sure Windows does it this way
...Windows doesn't do it this way, although according to the docs other members of the overlapped structure are modified by Windows.
Unfortunately, I'm not sure of another straightforward way to implement this. Unless somebody can come up with one, I think it's better to have Wine's behavior deviate slightly from Windows than to completely fail to support this feature.
[...]
I'd rather say it's GetOverlappedResult which is to blame. If the hEvent is NULL, then we shouldn't return any error (as we do) but rather assume all wait operation succeed (if hEven is NULL, ReadFile and WriteFile operations are synchronous, so calling GetOverlappedResult is a no-op).
This turns out not to be the case. As long as lpOverlapped is supplied, a NULL hEvent will work fine and allows overlapped reads.
But, this should be verified by small tests (and added to wine's test suite).
I agree; consider the attached file the first stab at a test program for this feature.
PS: some comments on your patch (not so useless regarding what I wrote above):
- CreateEvent can take a NULL parameter (for the name) which would
solve the name construction issue
Ah, I didn't know that. If we keep calling CreateEvent over and over again with a NULL parameter, will we eventually run out of some resource? If so, it may still be best to construct a name, since calling CreateEvent with the same name twice will apparently avoid creating another event.
- you don't need to but the hEvent as a static variable
Thanks, that's a relic from an earlier version. If the other aspects of this patch are OK, I'll fix it in an update.
The attached test program uses overlapped reads with a NULL hEvent in the OVERLAPPED structure to connect to an IP address and port given on the command line. Here's an example from Windows:
C:>overlapped-test 216.12.213.139 25 Calling ReadFile ReadFile returned ERROR_IO_PENDING, as expected ov .hEvent=00000000 Calling Sleep(2000) Calling GetOverlappedResult GetOverlappedresult read 85 bytes: 220 2search2.com ESMTP Sendmail 8.10.2-SOL3/8.10.2; Mon, 17 May 2004 11:58:26 -0400
----ScottG.