X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=src%2Fgnutls.c;h=17c7c9287662b10292cc5c7b22babd33b3ae750e;hp=adba856044e4f0eaa9bf9fc8906671c849d6e8c2;hb=75c6ca0f5d1cc9baf604ed44f1a7b68a0373357d;hpb=05503232c07908deee8c357f5ec0ad8da6a96695 diff --git a/src/gnutls.c b/src/gnutls.c index adba8560..17c7c928 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -173,28 +173,33 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg) { int ret = 0; struct wgnutls_transport_context *ctx = arg; - int offset = ctx->peeklen; - + int offset = MIN (bufsize, ctx->peeklen); if (bufsize > sizeof ctx->peekbuf) bufsize = sizeof ctx->peekbuf; - if (offset) + if (ctx->peeklen) memcpy (buf, ctx->peekbuf, offset); - do + if (bufsize > offset) { - if (gnutls_record_check_pending (ctx->session) - || select_fd (fd, 0, WAIT_FOR_READ)) - ret = gnutls_record_recv (ctx->session, buf + offset, bufsize - offset); - } - while (ret == GNUTLS_E_INTERRUPTED); + do + { + if (gnutls_record_check_pending (ctx->session) + || select_fd (fd, 0, WAIT_FOR_READ)) + ret = gnutls_record_recv (ctx->session, buf + offset, + bufsize - offset); + } + while (ret == GNUTLS_E_INTERRUPTED); - if (ret > 0) - { - memcpy (ctx->peekbuf + offset, buf + offset, ret); - ctx->peeklen += ret; + if (ret > 0) + { + memcpy (ctx->peekbuf + offset, buf + offset, + ret); + ctx->peeklen += ret; + } } - return ctx->peeklen; + + return offset + ret; } static const char *