Changeset View
Changeset View
Standalone View
Standalone View
gpgme-1.3.0/doc/gpgme.texi
Context not available. | |||||
operation in @acronym{GPGME} is not predictable. | operation in @acronym{GPGME} is not predictable. | ||||
@example | @example | ||||
#include <stdlib.h> | |||||
#include <errno.h> | |||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <gpgme.h> | #include <gpgme.h> | ||||
Context not available. | |||||
if (type == GPGME_EVENT_DONE) | if (type == GPGME_EVENT_DONE) | ||||
@{ | @{ | ||||
result->done = 1; | result->done = 1; | ||||
result->err = *type_data; | result->err = *(gpgme_error_t*)type_data; | ||||
@} | @} | ||||
@} | @} | ||||
@end example | @end example | ||||
Context not available. | |||||
@{ | @{ | ||||
fd_set rfds; | fd_set rfds; | ||||
fd_set wfds; | fd_set wfds; | ||||
struct one_fd *fds = loop->fds; | |||||
int i, n; | int i, n; | ||||
int any = 0; | int any = 0; | ||||
pthread_mutex_lock (&loop->lock); | pthread_mutex_lock (&loop->lock); | ||||
FD_ZERO (&rfds); | FD_ZERO (&rfds); | ||||
FD_ZERO (&wfds); | FD_ZERO (&wfds); | ||||
for (i = 0; i < FDLIST_MAX; i++) | for (i = 0; i < MAX_FDS; i++) | ||||
if (fdlist[i].fd != -1) | if (fds[i].fd != -1) | ||||
FD_SET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds); | FD_SET (fds[i].fd, fds[i].dir ? &rfds : &wfds); | ||||
pthread_mutex_unlock (&loop->unlock); | pthread_mutex_unlock (&loop->lock); | ||||
do | do | ||||
@{ | @{ | ||||
Context not available. | |||||
return n; /* Error or timeout. */ | return n; /* Error or timeout. */ | ||||
pthread_mutex_lock (&loop->lock); | pthread_mutex_lock (&loop->lock); | ||||
for (i = 0; i < FDLIST_MAX && n; i++) | for (i = 0; i < MAX_FDS && n; i++) | ||||
@{ | @{ | ||||
if (fdlist[i].fd != -1) | if (fds[i].fd != -1) | ||||
@{ | @{ | ||||
if (FD_ISSET (fdlist[i].fd, fdlist[i].dir ? &rfds : &wfds)) | if (FD_ISSET (fds[i].fd, fds[i].dir ? &rfds : &wfds)) | ||||
@{ | @{ | ||||
assert (n); | assert (n); | ||||
n--; | n--; | ||||
Context not available. | |||||
/* The I/O callback handler can register/remove callbacks, | /* The I/O callback handler can register/remove callbacks, | ||||
so we have to unlock the file descriptor list. */ | so we have to unlock the file descriptor list. */ | ||||
pthread_mutex_unlock (&loop->lock); | pthread_mutex_unlock (&loop->lock); | ||||
(*fdlist[i].fnc) (fdlist[i].fnc_data, fdlist[i].fd); | (*fds[i].fnc) (fds[i].fnc_data, fds[i].fd); | ||||
pthread_mutex_lock (&loop->lock); | pthread_mutex_lock (&loop->lock); | ||||
@} | @} | ||||
@} | @} | ||||
Context not available. | |||||
ret = do_select (loop); | ret = do_select (loop); | ||||
@} | @} | ||||
while (ret >= 0 && !result->done); | while (ret >= 0 && !result->done); | ||||
return ret; | return; | ||||
@} | @} | ||||
@end example | @end example | ||||
Context not available. | |||||
gpgme_ctx_t ctx; | gpgme_ctx_t ctx; | ||||
gpgme_error_t err; | gpgme_error_t err; | ||||
gpgme_data_t sig, text; | gpgme_data_t sig, text; | ||||
gpgme_sig_stat_t status; | |||||
int i; | int i; | ||||
struct gpgme_io_cb_ts io_cbs = | struct gpgme_io_cbs io_cbs = | ||||
@{ | @{ | ||||
add_io_cb, | add_io_cb, | ||||
&loop, | &loop, | ||||
Context not available. | |||||
&result | &result | ||||
@}; | @}; | ||||
init_gpgme (void); | gpgme_check_version (NULL); | ||||
/* Initialize the loop structure. */ | /* Initialize the loop structure. */ | ||||
loop.lock = PTHREAD_MUTEX_INITIALIZER; | pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; | ||||
loop.lock = lock; | |||||
for (i = 0; i < MAX_FDS; i++) | for (i = 0; i < MAX_FDS; i++) | ||||
loop->fds[i].fd = -1; | loop.fds[i].fd = -1; | ||||
/* Initialize the result structure. */ | /* Initialize the result structure. */ | ||||
result.done = 0; | result.done = 0; | ||||
Context not available. | |||||
if (!err) | if (!err) | ||||
@{ | @{ | ||||
gpgme_set_io_cbs (ctx, &io_cbs); | gpgme_set_io_cbs (ctx, &io_cbs); | ||||
err = gpgme_op_verify_start (ctx, sig, text, &status); | err = gpgme_op_verify_start (ctx, sig, text, NULL); | ||||
@} | @} | ||||
if (err) | if (err) | ||||
@{ | @{ | ||||
Context not available. |