From 998a35905643069b4b69c181457430cac9487fed Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 2 Jun 2005 22:05:32 +0000 Subject: [PATCH] 2005-06-02 Marcus Brinkmann * 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. --- branches/gpgme-1-0-branch/gpgme/ChangeLog | 8 +++++ branches/gpgme-1-0-branch/gpgme/wait-global.c | 2 +- .../gpgme-1-0-branch/gpgme/wait-private.c | 6 +--- branches/gpgme-1-0-branch/gpgme/wait-user.c | 5 +-- branches/gpgme-1-0-branch/gpgme/wait.c | 35 +++++++++++++++++++ branches/gpgme-1-0-branch/gpgme/wait.h | 2 ++ 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/branches/gpgme-1-0-branch/gpgme/ChangeLog b/branches/gpgme-1-0-branch/gpgme/ChangeLog index 8a348c4..d949da7 100644 --- a/branches/gpgme-1-0-branch/gpgme/ChangeLog +++ b/branches/gpgme-1-0-branch/gpgme/ChangeLog @@ -1,3 +1,11 @@ +2005-06-02 Marcus Brinkmann + + * 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 * gpgme.h: Add GPGME_STATUS_NEED_PASSPHRASE_PIN. diff --git a/branches/gpgme-1-0-branch/gpgme/wait-global.c b/branches/gpgme-1-0-branch/gpgme/wait-global.c index f3a5b43..7895d8b 100644 --- a/branches/gpgme-1-0-branch/gpgme/wait-global.c +++ b/branches/gpgme-1-0-branch/gpgme/wait-global.c @@ -310,7 +310,7 @@ gpgme_wait (gpgme_ctx_t ctx, gpgme_error_t *status, int hang) 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, diff --git a/branches/gpgme-1-0-branch/gpgme/wait-private.c b/branches/gpgme-1-0-branch/gpgme/wait-private.c index 166b713..d884c94 100644 --- a/branches/gpgme-1-0-branch/gpgme/wait-private.c +++ b/branches/gpgme-1-0-branch/gpgme/wait-private.c @@ -101,15 +101,11 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) { 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, diff --git a/branches/gpgme-1-0-branch/gpgme/wait-user.c b/branches/gpgme-1-0-branch/gpgme/wait-user.c index 3800b4f..ad3c9d3 100644 --- a/branches/gpgme-1-0-branch/gpgme/wait-user.c +++ b/branches/gpgme-1-0-branch/gpgme/wait-user.c @@ -42,15 +42,12 @@ _gpgme_user_io_cb_handler (void *data, int fd) 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; diff --git a/branches/gpgme-1-0-branch/gpgme/wait.c b/branches/gpgme-1-0-branch/gpgme/wait.c index f3cc8f6..c787045 100644 --- a/branches/gpgme-1-0-branch/gpgme/wait.c +++ b/branches/gpgme-1-0-branch/gpgme/wait.c @@ -167,3 +167,38 @@ _gpgme_remove_io_cb (void *data) 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); +} diff --git a/branches/gpgme-1-0-branch/gpgme/wait.h b/branches/gpgme-1-0-branch/gpgme/wait.h index cec4d8d..eafbb6f 100644 --- a/branches/gpgme-1-0-branch/gpgme/wait.h +++ b/branches/gpgme-1-0-branch/gpgme/wait.h @@ -77,4 +77,6 @@ void _gpgme_wait_user_event_cb (void *data, gpgme_event_io_t type, 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 */ -- 2.26.2