From fd1340085bc6879436dd2882dc5178c133434675 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 11 Aug 2020 07:59:41 +0200 Subject: core,w32: Use timeout in es_poll even if there are no FDs. * src/w32-estream.c (_gpgrt_w32_poll): Sleep if there are no handles to wait for. -- This better matches the semantics of poll and select and avoid busy waitins. We had this problem for example in the LDAP helper process reaper of GnuPG's Dirmngr. Signed-off-by: Werner Koch --- src/w32-estream.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/w32-estream.c b/src/w32-estream.c index 8ce9419..5bb1bcf 100644 --- a/src/w32-estream.c +++ b/src/w32-estream.c @@ -861,11 +861,25 @@ _gpgrt_w32_poll (gpgrt_poll_t *fds, size_t nfds, int timeout) trace_append (("%d/%c ", waitidx[i], waitinfo[i])); trace_finish (("]")); #endif /*ENABLE_TRACING*/ + if (!any) - return 0; + { + /* WFMO needs at least one object, thus we use use sleep here. + * INFINITE wait does not make any sense in this case, so we + * error out. */ + if (timeout == -1) + { + _gpg_err_set_errno (EINVAL); + return -1; + } + if (timeout) + Sleep (timeout); + code = WAIT_TIMEOUT; + } + else + code = WaitForMultipleObjects (nwait, waitbuf, 0, + timeout == -1 ? INFINITE : timeout); - code = WaitForMultipleObjects (nwait, waitbuf, 0, - timeout == -1 ? INFINITE : timeout); if (code < WAIT_OBJECT_0 + nwait) { /* This WFMO is a really silly function: It does return either -- cgit v1.2.3