From 32ea9f7722e50cced038fe0815d37c65d31baa67 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 14 Nov 2010 10:17:20 -0500 Subject: [PATCH] Fixed EAGAIN when doing an SSH channel write. --- src/libpwmd.c | 19 ------------------- src/ssh.c | 15 ++++++++++++++- src/types.h | 7 ++----- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/libpwmd.c b/src/libpwmd.c index 5aaa23e6..3481e1e1 100644 --- a/src/libpwmd.c +++ b/src/libpwmd.c @@ -444,7 +444,6 @@ static int inquire_cb(void *data, const char *keyword) { pwm_t *pwm = (pwm_t *)data; gpg_error_t rc = 0; - int is_eagain = 0; /* Shouldn't get this far without a callback. */ if (!pwm->inquire_func) @@ -468,8 +467,6 @@ static int inquire_cb(void *data, const char *keyword) break; } -eagain: - is_eagain = 0; arc = assuan_send_data(pwm->ctx, result, len); arc = gpg_err_code(arc); @@ -479,12 +476,6 @@ eagain: } rc = arc; - - if (rc == GPG_ERR_EAGAIN) { - rc = 0; - is_eagain = 1; - goto process; - } } else if (rc) break; @@ -503,21 +494,11 @@ eagain: continue; } -process: rc = _pwmd_process(pwm); if (rc == GPG_ERR_EAGAIN) rc = 0; } - - if (!rc && is_eagain) { -#ifdef WITH_LIBPTH - pth_usleep(100000); -#else - usleep(100000); -#endif - goto eagain; - } } return gpg_err_code(rc); diff --git a/src/ssh.c b/src/ssh.c index fba9a552..5d884bca 100644 --- a/src/ssh.c +++ b/src/ssh.c @@ -120,7 +120,20 @@ static int write_hook(assuan_context_t ctx, assuan_fd_t fd, const void *data, #endif else { LOCK_SSH_MUTEX - *ret = libssh2_channel_write(pwm->tcp_conn->channel, data, len); + + /* libassuan cannot handle EAGAIN when doing writes. */ + do { + *ret = libssh2_channel_write(pwm->tcp_conn->channel, data, len); + + if (*ret == LIBSSH2_ERROR_EAGAIN) { +#ifdef WITH_LIBPTH + pth_usleep(50000); +#else + usleep(50000); + } +#endif + } while (*ret == LIBSSH2_ERROR_EAGAIN); + UNLOCK_SSH_MUTEX } diff --git a/src/types.h b/src/types.h index 18069ed7..96169430 100644 --- a/src/types.h +++ b/src/types.h @@ -169,10 +169,7 @@ typedef struct { } pwmd_nb_status_t; gpg_error_t _assuan_command(pwm_t *pwm, assuan_context_t ctx, - char **result, const char *cmd) - __attribute__ ((visibility ("hidden"))); - -gpg_error_t _connect_finalize(pwm_t *pwm) - __attribute__ ((visibility ("hidden"))); + char **result, const char *cmd); +gpg_error_t _connect_finalize(pwm_t *pwm); #endif -- 2.11.4.GIT