I'd suggest moving some of the existing code into helper functions first.
You asked for that the first time too. I've tried, but I just couldn't find any good seams to carve it along besides consolidating the PeekMessage calls (e7e4c3d8eee915975e958521b8caffe94ef7a34d). The 3 major hunks (message pump, the IMessageFilter_MessagePending stuff, and polling the handles for completions/APCs) all tie into how the loop exits and the post conditions (re-posting QuitMessage, writing `*index` (or leaving it unmodified), errors, translating previous Wait* result), and the order is quite important (because of side-effects like consuming/preserving QS_ALLPOSTMESSAGE).
If you have any ideas I'd love to hear them. I could certainly pull those 3 major hunks out into functions, but when they have get passed in pointers to a bunch of outside-the-loop variables, and their return value ends up being decoded into ends up with stuff like `if(hr == S_FALSE) break; else if(FAILED(hr)) goto err;` then the flow control just turned into spaghetti I hated even more than what it started as.
ten commits per MR is rather too many (especially when they're non trivial).
Yeah, for lack of coming up with decent helper functions I tried to dice it *really* finely separate testable commits that changed only one behavior. I think they are all correct and improvements on the status quo, but the very first commit fixes the same bug (short-timeout race) for MTAs that the last finally fixes for STAs, so it felt weird to propose actually merging it partially. And yet that's really the order in which the steps make the most sense to read (in terms of minimizing extraneous code change); getting the MTA out of the loop, so that it's *only* the mesage loops, then building toward toward the case where everything is happening in the right order and there's a correct place to put the timeout.
The part that I dislike about this series is temporarily introducing use of MWMO_INPUTAVAILABLE; that was a detour born of trying to split the last 3 commits apart from each other, so there's only one behavior change at a time.
1. WAIT_OBJECT_* signaled after dispatching a message 2. WAIT_IO_COMPLETION after dispatching a message (rather than just once at the start) 3. making sure to we're out of relevant messages before escalating WAIT_TIMOUET to RPC_S_CALLPENDING).
Required some careful work to *preserve* bugs until the next commit.
I guess there's a few things in the middle that basically just refactor/add tests without changing any observable behavior, so I'll move those to the front and make a separate MR, just to cut down the size of this one... And I guess I could also put a lot of the new tests in as just new `todo_wine` tests, separate from the actual changes that fix them. That would at least get a lot of lines of code out of this MR, though not much of the conceptual complexity.