Thanks for all the cleanup and adding of windows support. To me it now looks good to merge.
Meanwhile I've created another patch that adds, a non-blocking version of PQcancel to libpq. Which doesn't have this problem by design, because it simply reuses the normal code for connection establishement. And it also includes tests for PQcancel itself.