gpgme/gpgme (6 files)

cvs user marcus cvs at cvs.gnupg.org
Thu Jun 2 23:38:23 CEST 2005


    Date: Thursday, June 2, 2005 @ 23:59:34
  Author: marcus
    Path: /cvs/gpgme/gpgme/gpgme

Modified: ChangeLog wait-global.c wait-private.c wait-user.c wait.c wait.h

2005-06-02  Marcus Brinkmann  <marcus at g10code.de>

	* wait.h (_gpgme_run_io_cb): New prototype.
	* wait.c (_gpgme_run_io_cb): New function.
	* wait-global.c (gpgme_wait): Call it.
	* wait-user.c (_gpgme_user_io_cb_handler): Likewise.
	* wait-private.c (_gpgme_wait_on_condition): Likewise.


----------------+
 ChangeLog      |    8 ++++++++
 wait-global.c  |    2 +-
 wait-private.c |    6 +-----
 wait-user.c    |    5 +----
 wait.c         |   35 +++++++++++++++++++++++++++++++++++
 wait.h         |    2 ++
 6 files changed, 48 insertions(+), 10 deletions(-)


Index: gpgme/gpgme/ChangeLog
diff -u gpgme/gpgme/ChangeLog:1.403 gpgme/gpgme/ChangeLog:1.404
--- gpgme/gpgme/ChangeLog:1.403	Thu Jun  2 13:22:14 2005
+++ gpgme/gpgme/ChangeLog	Thu Jun  2 23:59:34 2005
@@ -1,3 +1,11 @@
+2005-06-02  Marcus Brinkmann  <marcus at g10code.de>
+
+	* wait.h (_gpgme_run_io_cb): New prototype.
+	* wait.c (_gpgme_run_io_cb): New function.
+	* wait-global.c (gpgme_wait): Call it.
+	* wait-user.c (_gpgme_user_io_cb_handler): Likewise.
+	* wait-private.c (_gpgme_wait_on_condition): Likewise.
+
 2005-06-02  Werner Koch  <wk at g10code.com>
 
 	* passphrase.c (_gpgme_passphrase_status_handler): Take care of
Index: gpgme/gpgme/wait-global.c
diff -u gpgme/gpgme/wait-global.c:1.15 gpgme/gpgme/wait-global.c:1.16
--- gpgme/gpgme/wait-global.c:1.15	Thu Apr 14 10:49:20 2005
+++ gpgme/gpgme/wait-global.c	Thu Jun  2 23:59:34 2005
@@ -310,7 +310,7 @@
 	      ictx = item->ctx;
 	      assert (ictx);
 
-	      err = item->handler (item->handler_value, fdt.fds[i].fd);
+	      err = _gpgme_run_io_cb (&fdt.fds[i], 0);
 	      if (err)
 		{
 		  /* An error occured.  Close all fds in this context,
Index: gpgme/gpgme/wait-private.c
diff -u gpgme/gpgme/wait-private.c:1.11 gpgme/gpgme/wait-private.c:1.12
--- gpgme/gpgme/wait-private.c:1.11	Thu Mar 24 14:05:12 2005
+++ gpgme/gpgme/wait-private.c	Thu Jun  2 23:59:34 2005
@@ -101,15 +101,11 @@
 	{
 	  if (ctx->fdt.fds[i].fd != -1 && ctx->fdt.fds[i].signaled)
 	    {
-	      struct wait_item_s *item;
-	      
 	      ctx->fdt.fds[i].signaled = 0;
 	      assert (nr);
 	      nr--;
-	      
-	      item = (struct wait_item_s *) ctx->fdt.fds[i].opaque;
 
-	      err = item->handler (item->handler_value, ctx->fdt.fds[i].fd);
+	      err = _gpgme_run_io_cb (&ctx->fdt.fds[i], 0);
 	      if (err)
 		{
 		  /* An error occured.  Close all fds in this context,
Index: gpgme/gpgme/wait-user.c
diff -u gpgme/gpgme/wait-user.c:1.7 gpgme/gpgme/wait-user.c:1.8
--- gpgme/gpgme/wait-user.c:1.7	Thu Mar 24 14:05:12 2005
+++ gpgme/gpgme/wait-user.c	Thu Jun  2 23:59:34 2005
@@ -42,15 +42,12 @@
   gpgme_error_t err;
   struct tag *tag = (struct tag *) data;
   gpgme_ctx_t ctx;
-  struct wait_item_s *item;
 
   assert (data);
   ctx = tag->ctx;
   assert (ctx);
-  item = (struct wait_item_s *) ctx->fdt.fds[tag->idx].opaque;
-  assert (item);
 
-  err = (*item->handler) (item->handler_value, fd);
+  err = _gpgme_run_io_cb (&ctx->fdt.fds[tag->idx], 0);
   if (err)
     {
       unsigned int idx;
Index: gpgme/gpgme/wait.c
diff -u gpgme/gpgme/wait.c:1.44 gpgme/gpgme/wait.c:1.45
--- gpgme/gpgme/wait.c:1.44	Thu Mar 24 14:05:12 2005
+++ gpgme/gpgme/wait.c	Thu Jun  2 23:59:34 2005
@@ -167,3 +167,38 @@
   fdt->fds[idx].for_write = 0;
   fdt->fds[idx].opaque = NULL;
 }
+
+
+/* This is slightly embarrassing.  The problem is that running an I/O
+   callback _may_ influence the status of other file descriptors.  Our
+   own event loops could compensate for that, but the external event
+   loops cannot.  FIXME: We may still want to optimize this a bit when
+   we are called from our own event loops.  So if CHECKED is 1, the
+   check is skipped.  */
+gpgme_error_t
+_gpgme_run_io_cb (struct io_select_fd_s *an_fds, int checked)
+{
+  struct wait_item_s *item;
+  item = (struct wait_item_s *) an_fds->opaque;
+  assert (item);
+
+  if (!checked)
+    {
+      int nr;
+      struct io_select_fd_s fds;
+
+      fds = *an_fds;
+      fds.signaled = 0;
+      /* Just give it a quick poll.  */
+      nr = _gpgme_io_select (&fds, 1, 1);
+      assert (nr <= 1);
+      if (nr < 0)
+	return errno;
+      else if (nr == 0)
+	/* The status changed in the meantime, there is nothing left
+	   to do.  */
+	return 0;
+    }
+
+  return item->handler (item->handler_value, an_fds->fd);
+}
Index: gpgme/gpgme/wait.h
diff -u gpgme/gpgme/wait.h:1.11 gpgme/gpgme/wait.h:1.12
--- gpgme/gpgme/wait.h:1.11	Tue Dec  7 22:13:36 2004
+++ gpgme/gpgme/wait.h	Thu Jun  2 23:59:34 2005
@@ -77,4 +77,6 @@
 
 gpgme_error_t _gpgme_wait_one (gpgme_ctx_t ctx);
 
+gpgme_error_t _gpgme_run_io_cb (struct io_select_fd_s *an_fds, int checked);
+
 #endif	/* WAIT_H */




More information about the Gnupg-commits mailing list