aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32-util.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2018-11-01 08:55:24 +0000
committerWerner Koch <[email protected]>2018-11-01 08:55:24 +0000
commit63ba09b541dabbe838253926896e721cb9be564a (patch)
tree26f2824b31ab5aafd1a351a4224b38161efa7ce7 /src/w32-util.c
parentw32: Merge all the object tables of w32-io into one. (diff)
downloadgpgme-63ba09b541dabbe838253926896e721cb9be564a.tar.gz
gpgme-63ba09b541dabbe838253926896e721cb9be564a.zip
w32: Use CancelSynchronousIo in destroy_reader.
* src/w32-util.c (_gpgme_w32_cancel_synchronous_io): New. * src/w32-io.c (destroy_reader): Use it here. -- This has not been tested but should on Vista and later help to fix a possible hang. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/w32-util.c')
-rw-r--r--src/w32-util.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/w32-util.c b/src/w32-util.c
index 79541898..8a04c8c1 100644
--- a/src/w32-util.c
+++ b/src/w32-util.c
@@ -99,8 +99,6 @@ static char *default_gpgconf_name;
gpgme_set_global_flag and accessed by _gpgme_get_inst_dir. */
static char *override_inst_dir;
-#ifdef HAVE_ALLOW_SET_FOREGROUND_WINDOW
-
#define RTLD_LAZY 0
static GPG_ERR_INLINE void *
@@ -135,7 +133,6 @@ dlclose (void * hd)
}
return -1;
}
-#endif /* HAVE_ALLOW_SET_FOREGROUND_WINDOW */
/* Return a malloced string encoded in UTF-8 from the wide char input
@@ -241,6 +238,45 @@ _gpgme_allow_set_foreground_window (pid_t pid)
}
+/* Wrapper around CancelSynchronousIo which is only available since
+ * Vista. */
+void
+_gpgme_w32_cancel_synchronous_io (HANDLE thread)
+{
+ static int initialized;
+ static BOOL (WINAPI * func)(DWORD);
+ void *handle;
+
+ if (!initialized)
+ {
+ /* Available since Vista; thus we dynload it. */
+ initialized = 1;
+ handle = dlopen ("kerner32.dll", RTLD_LAZY);
+ if (handle)
+ {
+ func = dlsym (handle, "CancelSynchronousIo");
+ if (!func)
+ {
+ dlclose (handle);
+ handle = NULL;
+ }
+ }
+ }
+
+ if (func)
+ {
+ int rc = func (thread);
+ TRACE2 (DEBUG_ENGINE, "gpgme:CancelSynchronousIo", 0,
+ "called for thread %p; result=%d", thread, rc);
+ }
+ else
+ {
+ TRACE0 (DEBUG_ENGINE, "gpgme:CancelSynchronousIo", 0,
+ "function not available");
+ }
+}
+
+
/* Return a string from the W32 Registry or NULL in case of error.
Caller must release the return value. A NULL for root is an alias
for HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE in turn. */