2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004, 2005 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
36 /* The private event loops are used for all blocking operations, and
37 for the key and trust item listing operations. They are completely
38 separated from each other. */
41 /* Internal I/O callback functions. */
43 /* The add_io_cb and remove_io_cb handlers are shared with the global
47 _gpgme_wait_private_event_cb (void *data, gpgme_event_io_t type,
52 case GPGME_EVENT_START:
53 /* Nothing to do here, as the wait routine is called after the
54 initialization is finished. */
57 case GPGME_EVENT_DONE:
60 case GPGME_EVENT_NEXT_KEY:
61 _gpgme_op_keylist_event_cb (data, type, type_data);
64 case GPGME_EVENT_NEXT_TRUSTITEM:
65 _gpgme_op_trustlist_event_cb (data, type, type_data);
71 /* If COND is a null pointer, wait until the blocking operation in CTX
72 finished and return its error value. Otherwise, wait until COND is
73 satisfied or the operation finished. */
75 _gpgme_wait_on_condition (gpgme_ctx_t ctx, volatile int *cond,
76 gpgme_error_t *op_err_p)
78 gpgme_error_t err = 0;
86 int nr = _gpgme_io_select (ctx->fdt.fds, ctx->fdt.size, 0);
91 /* An error occured. Close all fds in this context, and
93 err = gpg_error_from_errno (errno);
94 _gpgme_cancel_with_err (ctx, err, 0);
99 for (i = 0; i < ctx->fdt.size && nr; i++)
101 if (ctx->fdt.fds[i].fd != -1 && ctx->fdt.fds[i].signaled)
103 gpgme_error_t op_err = 0;
105 ctx->fdt.fds[i].signaled = 0;
111 err = gpg_error (GPG_ERR_CANCELED);
115 err = _gpgme_run_io_cb (&ctx->fdt.fds[i], 0, &op_err);
118 /* An error occured. Close all fds in this context,
120 _gpgme_cancel_with_err (ctx, err, 0);
126 /* An operational error occured. Cancel the current
127 operation but not the session, and signal it. */
128 _gpgme_cancel_with_err (ctx, 0, op_err);
130 /* NOTE: This relies on the operational error being
131 generated after the operation really has
132 completed, for example after no further status
133 line output is generated. Otherwise the
134 following I/O will spill over into the next
143 for (i = 0; i < ctx->fdt.size; i++)
144 if (ctx->fdt.fds[i].fd != -1)
146 if (i == ctx->fdt.size)
148 struct gpgme_io_event_done_data data;
151 _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &data);
163 /* Wait until the blocking operation in context CTX has finished and
164 return the error value. This variant can not be used for
165 session-based protocols. */
167 _gpgme_wait_one (gpgme_ctx_t ctx)
169 return _gpgme_wait_on_condition (ctx, NULL, NULL);
172 /* Wait until the blocking operation in context CTX has finished and
173 return the error value. This is the right variant to use for
174 sesion-based protocols. */
176 _gpgme_wait_one_ext (gpgme_ctx_t ctx, gpgme_error_t *op_err)
178 return _gpgme_wait_on_condition (ctx, NULL, op_err);