diff options
Diffstat (limited to 'src/wait-private.c')
-rw-r--r-- | src/wait-private.c | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/src/wait-private.c b/src/wait-private.c index 2dee1a93..5d3f267c 100644 --- a/src/wait-private.c +++ b/src/wait-private.c @@ -72,7 +72,8 @@ _gpgme_wait_private_event_cb (void *data, gpgme_event_io_t type, finished and return its error value. Otherwise, wait until COND is satisfied or the operation finished. */ gpgme_error_t -_gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) +_gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond, + gpgme_error_t *op_err_p) { gpgme_error_t err = 0; int hang = 1; @@ -87,8 +88,10 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) /* An error occured. Close all fds in this context, and signal it. */ err = gpg_error_from_errno (errno); - _gpgme_cancel_with_err (ctx, err); + _gpgme_cancel_with_err (ctx, err, 0); + if (op_err_p) + *op_err_p = 0; return err; } @@ -96,6 +99,8 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) { if (ctx->fdt.fds[i].fd != -1 && ctx->fdt.fds[i].signaled) { + gpgme_error_t op_err = 0; + ctx->fdt.fds[i].signaled = 0; assert (nr); nr--; @@ -106,15 +111,33 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) UNLOCK (ctx->lock); if (!err) - err = _gpgme_run_io_cb (&ctx->fdt.fds[i], 0); + err = _gpgme_run_io_cb (&ctx->fdt.fds[i], 0, &op_err); if (err) { /* An error occured. Close all fds in this context, and signal it. */ - _gpgme_cancel_with_err (ctx, err); + _gpgme_cancel_with_err (ctx, err, 0); + if (op_err_p) + *op_err_p = 0; return err; } + else if (op_err) + { + /* An operational error occured. Cancel the current + operation but not the session, and signal it. */ + _gpgme_cancel_with_err (ctx, 0, op_err); + + /* NOTE: This relies on the operational error being + generated after the operation really has + completed, for example after no further status + line output is generated. Otherwise the + following I/O will spill over into the next + operation. */ + if (op_err_p) + *op_err_p = op_err; + return 0; + } } } @@ -123,7 +146,10 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) break; if (i == ctx->fdt.size) { - _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err); + struct gpgme_io_event_done_data data; + data.err = 0; + data.op_err = 0; + _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &data); hang = 0; } if (cond && *cond) @@ -131,14 +157,26 @@ _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond) } while (hang); + if (op_err_p) + *op_err_p = 0; return 0; } /* Wait until the blocking operation in context CTX has finished and - return the error value. */ + return the error value. This variant can not be used for + session-based protocols. */ gpgme_error_t _gpgme_wait_one (gpgme_ctx_t ctx) { - return _gpgme_wait_on_condition (ctx, NULL); + return _gpgme_wait_on_condition (ctx, NULL, NULL); +} + +/* Wait until the blocking operation in context CTX has finished and + return the error value. This is the right variant to use for + sesion-based protocols. */ +gpgme_error_t +_gpgme_wait_one_ext (gpgme_ctx_t ctx, gpgme_error_t *op_err) +{ + return _gpgme_wait_on_condition (ctx, NULL, op_err); } |