[svn] gpgme - r1099 - in trunk: gpgme tests tests/gpg
svn author wk
cvs at cvs.gnupg.org
Fri Sep 23 15:29:06 CEST 2005
Author: wk
Date: 2005-09-23 15:29:04 +0200 (Fri, 23 Sep 2005)
New Revision: 1099
Added:
trunk/tests/gpg/t-encrypt-large.c
Modified:
trunk/gpgme/ChangeLog
trunk/gpgme/w32-io.c
trunk/tests/ChangeLog
trunk/tests/gpg/Makefile.am
trunk/tests/gpg/t-support.h
Log:
Boosted performance of w32 I/O
Modified: trunk/gpgme/ChangeLog
===================================================================
--- trunk/gpgme/ChangeLog 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/gpgme/ChangeLog 2005-09-23 13:29:04 UTC (rev 1099)
@@ -1,3 +1,14 @@
+2005-09-23 Werner Koch <wk at g10code.com>
+
+ * 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 <wk at g10code.com>
+
+ * w32-io.c (_gpgme_io_pipe): New environment variable to change
+ the size of the pipe buffer.
+
2005-09-13 Werner Koch <wk at g10code.com>
* ath.c: Changes to make it work under W32.
Modified: trunk/gpgme/w32-io.c
===================================================================
--- trunk/gpgme/w32-io.c 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/gpgme/w32-io.c 2005-09-23 13:29:04 UTC (rev 1099)
@@ -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 @@
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 @@
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 @@
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 @@
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);
Modified: trunk/tests/ChangeLog
===================================================================
--- trunk/tests/ChangeLog 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/tests/ChangeLog 2005-09-23 13:29:04 UTC (rev 1099)
@@ -1,3 +1,10 @@
+2005-09-23 Werner Koch <wk at g10code.com>
+
+ * 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 <marcus at g10code.de>
* gpg/Makefile.am (TESTS): Add t-wait.
Modified: trunk/tests/gpg/Makefile.am
===================================================================
--- trunk/tests/gpg/Makefile.am 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/tests/gpg/Makefile.am 2005-09-23 13:29:04 UTC (rev 1099)
@@ -28,7 +28,7 @@
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
Added: trunk/tests/gpg/t-encrypt-large.c
===================================================================
--- trunk/tests/gpg/t-encrypt-large.c 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/tests/gpg/t-encrypt-large.c 2005-09-23 13:29:04 UTC (rev 1099)
@@ -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 <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <gpgme.h>
+
+#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;
+}
Modified: trunk/tests/gpg/t-support.h
===================================================================
--- trunk/tests/gpg/t-support.h 2005-09-13 14:17:04 UTC (rev 1098)
+++ trunk/tests/gpg/t-support.h 2005-09-23 13:29:04 UTC (rev 1099)
@@ -96,7 +96,9 @@
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);
More information about the Gnupg-commits
mailing list