From ca244196f1c7347f89e4b382198177a48b44133c Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Sun, 3 Apr 2011 02:15:22 +0200 Subject: [PATCH] Make wgnutls_peek non blocking. --- ChangeLog | 4 ++++ bootstrap.conf | 1 + src/ChangeLog | 5 +++++ src/gnutls.c | 14 ++++++++++++++ 4 files changed, 24 insertions(+) diff --git a/ChangeLog b/ChangeLog index abf36c49..ba5af9ab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2011-04-03 Giuseppe Scrivano + + * bootstrap.conf (gnulib_modules): Add `fcntl'. + 2011-03-26 Giuseppe Scrivano * configure.ac: Fix the gnutls detection. diff --git a/bootstrap.conf b/bootstrap.conf index 24d08163..3fb3bdfb 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -32,6 +32,7 @@ bind c-ctype close connect +fcntl getaddrinfo getopt-gnu getpass-gnu diff --git a/src/ChangeLog b/src/ChangeLog index 9d08bc6b..ef3a863b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2011-04-03 Giuseppe Scrivano + + * gnutls.c: Include + (wgnutls_peek): Make the socket non blocking before attempt a read. + 2011-03-31 Giuseppe Scrivano * recur.c (download_child_p): When --no-parent is used, check that the diff --git a/src/gnutls.c b/src/gnutls.c index 9e5c733b..4f38aca1 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -40,6 +40,7 @@ as that of the covered work. */ #include #include +#include #include "utils.h" #include "connect.h" @@ -182,6 +183,15 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg) if (bufsize > offset) { + int flags; + flags = fcntl (fd, F_GETFL, 0); + if (flags < 0) + return ret; + + ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK); + if (ret < 0) + return ret; + do { ret = gnutls_record_recv (ctx->session, buf + offset, @@ -203,6 +213,10 @@ wgnutls_peek (int fd, char *buf, int bufsize, void *arg) ret); ctx->peeklen += ret; } + + fcntl (fd, F_SETFL, flags); + if (ret < 0) + return ret; } return offset + ret; -- 2.39.2