From 8a1ce95287705641f20d75619190de2bb2099a06 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 23 Sep 2005 13:29:04 +0000 Subject: [PATCH] Boosted performance of w32 I/O --- gpgme/ChangeLog | 11 +++ gpgme/w32-io.c | 21 +++++- tests/ChangeLog | 7 ++ tests/gpg/Makefile.am | 2 +- tests/gpg/t-encrypt-large.c | 143 ++++++++++++++++++++++++++++++++++++ tests/gpg/t-support.h | 2 + 6 files changed, 181 insertions(+), 5 deletions(-) create mode 100644 tests/gpg/t-encrypt-large.c diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 385b818..1fb35ab 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,14 @@ +2005-09-23 Werner Koch + + * w32-io.c (_gpgme_io_pipe): Removed use of environment variable + again. + (create_reader, create_writer): Set thread priority higher. + +2005-09-19 Werner Koch + + * w32-io.c (_gpgme_io_pipe): New environment variable to change + the size of the pipe buffer. + 2005-09-13 Werner Koch * ath.c: Changes to make it work under W32. diff --git a/gpgme/w32-io.c b/gpgme/w32-io.c index ae09d9c..8b37ea3 100644 --- a/gpgme/w32-io.c +++ b/gpgme/w32-io.c @@ -51,6 +51,7 @@ #define READBUF_SIZE 4096 #define WRITEBUF_SIZE 4096 +#define PIPEBUF_SIZE 4096 #define MAX_READERS 20 #define MAX_WRITERS 20 @@ -261,6 +262,12 @@ create_reader (HANDLE fd) free (c); return NULL; } + else { + /* We set the priority of the thread higher because we know that + it only runs for a short time. This greatly helps to increase + the performance of the I/O. */ + SetThreadPriority (c->thread_hd, THREAD_PRIORITY_HIGHEST); + } return c; } @@ -513,6 +520,12 @@ create_writer (HANDLE fd) free (c); return NULL; } + else { + /* We set the priority of the thread higher because we know that + it only runs for a short time. This greatly helps to increase + the performance of the I/O. */ + SetThreadPriority (c->thread_hd, THREAD_PRIORITY_HIGHEST); + } return c; } @@ -646,9 +659,9 @@ _gpgme_io_pipe ( int filedes[2], int inherit_idx ) sec_attr.nLength = sizeof sec_attr; sec_attr.bInheritHandle = FALSE; - if (!CreatePipe ( &r, &w, &sec_attr, 0)) + if (!CreatePipe ( &r, &w, &sec_attr, PIPEBUF_SIZE)) return -1; - /* make one end inheritable */ + /* Make one end inheritable. */ if ( inherit_idx == 0 ) { HANDLE h; if (!DuplicateHandle( GetCurrentProcess(), r, @@ -900,13 +913,13 @@ _gpgme_io_spawn ( const char *path, char **argv, return -1; } - /* close the /dev/nul handle if used */ + /* Close the /dev/nul handle if used. */ if (hnul != INVALID_HANDLE_VALUE ) { if ( !CloseHandle ( hnul ) ) DEBUG1 ("CloseHandle(hnul) failed: ec=%d\n", (int)GetLastError()); } - /* Close the other ends of the pipes */ + /* Close the other ends of the pipes. */ for (i = 0; fd_parent_list[i].fd != -1; i++) _gpgme_io_close (fd_parent_list[i].fd); diff --git a/tests/ChangeLog b/tests/ChangeLog index 690e458..3932be3 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,10 @@ +2005-09-23 Werner Koch + + * gpg/t-support.h (init_gpgme) [W32]: Don't use LC_MESSAGES. + + * gpg/t-encrypt-large.c: New test. + * gpg/Makefile.am (TESTS): Add t-encrypt-large. + 2005-06-03 Marcus Brinkmann * gpg/Makefile.am (TESTS): Add t-wait. diff --git a/tests/gpg/Makefile.am b/tests/gpg/Makefile.am index 73009a9..7301240 100644 --- a/tests/gpg/Makefile.am +++ b/tests/gpg/Makefile.am @@ -28,7 +28,7 @@ noinst_HEADERS = t-support.h TESTS = t-encrypt t-encrypt-sym t-encrypt-sign t-sign t-signers \ t-decrypt t-verify t-decrypt-verify \ t-export t-import t-trustlist t-eventloop t-edit \ - t-keylist t-keylist-sig t-thread1 t-wait + t-keylist t-keylist-sig t-thread1 t-wait t-encrypt-large CLEANFILES = secring.gpg pubring.gpg trustdb.gpg DISTCLEANFILES = pubring.gpg~ random_seed diff --git a/tests/gpg/t-encrypt-large.c b/tests/gpg/t-encrypt-large.c new file mode 100644 index 0000000..6cc6138 --- /dev/null +++ b/tests/gpg/t-encrypt-large.c @@ -0,0 +1,143 @@ +/* t-encrypt-large.c - Regression test for large amounts of data. + Copyright (C) 2005 g10 Code GmbH + + This file is part of GPGME. + + GPGME is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of + the License, or (at your option) any later version. + + GPGME is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +/* We need to include config.h so that we know whether we are building + with large file system (LFS) support. */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include + +#include "t-support.h" + + +struct cb_parms +{ + size_t bytes_to_send; + size_t bytes_received; +}; + + + +/* The read callback used by GPGME to read data. */ +static ssize_t +read_cb (void *handle, void *buffer, size_t size) +{ + struct cb_parms *parms = handle; + char *p = buffer; + + for (; size && parms->bytes_to_send; size--, parms->bytes_to_send--) + *p++ = rand (); + + return (p - (char*)buffer); +} + +/* The write callback used by GPGME to write data. */ +static ssize_t +write_cb (void *handle, const void *buffer, size_t size) +{ + struct cb_parms *parms = handle; + + parms->bytes_received += size; + + return size; +} + + +static void +progress_cb (void *opaque, const char *what, int type, int current, int total) +{ + /* This is just a dummy. */ +} + + + + + +int +main (int argc, char *argv[]) +{ + gpgme_ctx_t ctx; + gpgme_error_t err; + struct gpgme_data_cbs cbs; + gpgme_data_t in, out; + gpgme_key_t key[3] = { NULL, NULL, NULL }; + gpgme_encrypt_result_t result; + size_t nbytes; + struct cb_parms parms; + + if (argc > 1) + nbytes = atoi (argv[1]); + else + nbytes = 100000; + + init_gpgme (GPGME_PROTOCOL_OpenPGP); + + memset (&cbs, 0, sizeof cbs); + cbs.read = read_cb; + cbs.write = write_cb; + memset (&parms, 0, sizeof parms); + parms.bytes_to_send = nbytes; + + err = gpgme_new (&ctx); + fail_if_err (err); + gpgme_set_armor (ctx, 0); + + /* Install a progress handler to enforce a bit of more work to the + gpgme i/o system. */ + gpgme_set_progress_cb (ctx, progress_cb, NULL); + + err = gpgme_data_new_from_cbs (&in, &cbs, &parms); + fail_if_err (err); + + err = gpgme_data_new_from_cbs (&out, &cbs, &parms); + fail_if_err (err); + + err = gpgme_get_key (ctx, "A0FF4590BB6122EDEF6E3C542D727CC768697734", + &key[0], 0); + fail_if_err (err); + err = gpgme_get_key (ctx, "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2", + &key[1], 0); + fail_if_err (err); + + err = gpgme_op_encrypt (ctx, key, GPGME_ENCRYPT_ALWAYS_TRUST, in, out); + fail_if_err (err); + result = gpgme_op_encrypt_result (ctx); + if (result->invalid_recipients) + { + fprintf (stderr, "Invalid recipient encountered: %s\n", + result->invalid_recipients->fpr); + exit (1); + } + printf ("plaintext=%u bytes, ciphertext=%u bytes\n", + (unsigned int)nbytes, (unsigned int)parms.bytes_received); + + gpgme_key_unref (key[0]); + gpgme_key_unref (key[1]); + gpgme_data_release (in); + gpgme_data_release (out); + gpgme_release (ctx); + return 0; +} diff --git a/tests/gpg/t-support.h b/tests/gpg/t-support.h index b48c7f0..0ed1ac8 100644 --- a/tests/gpg/t-support.h +++ b/tests/gpg/t-support.h @@ -96,7 +96,9 @@ init_gpgme (gpgme_protocol_t proto) gpgme_check_version (NULL); setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); +#ifndef HAVE_W32_SYSTEM gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); +#endif err = gpgme_engine_check_version (proto); fail_if_err (err); -- 2.26.2