]> sjero.net Git - wget/commitdiff
Make wgnutls_peek non blocking.
authorGiuseppe Scrivano <gscrivano@gnu.org>
Sun, 3 Apr 2011 00:15:22 +0000 (02:15 +0200)
committerGiuseppe Scrivano <gscrivano@gnu.org>
Sun, 3 Apr 2011 00:15:22 +0000 (02:15 +0200)
ChangeLog
bootstrap.conf
src/ChangeLog
src/gnutls.c

index abf36c49e3a5d6d965ff6c4b4cbedf510256ab7d..ba5af9abba726dbac23099606bd48c45d98533fe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-04-03  Giuseppe Scrivano  <gscrivano@gnu.org>
+
+       * bootstrap.conf (gnulib_modules): Add `fcntl'.
+
 2011-03-26  Giuseppe Scrivano  <gscrivano@gnu.org>
 
        * configure.ac: Fix the gnutls detection.
index 24d081632a481a73895b5a8066c34ab71285ae5b..3fb3bdfb4ed6da881c63024cb8c9e926778c87f2 100644 (file)
@@ -32,6 +32,7 @@ bind
 c-ctype
 close
 connect
+fcntl
 getaddrinfo
 getopt-gnu
 getpass-gnu
index 9d08bc6bef5f0fa0e5ab02219bc499f98308a931..ef3a863b1d5e31b1726191fbdac7641afadf2004 100644 (file)
@@ -1,3 +1,8 @@
+2011-04-03  Giuseppe Scrivano  <gscrivano@gnu.org>
+
+       * gnutls.c: Include <fcntl.h>
+       (wgnutls_peek): Make the socket non blocking before attempt a read.
+
 2011-03-31  Giuseppe Scrivano  <gscrivano@gnu.org>
 
        * recur.c (download_child_p): When --no-parent is used, check that the
index 9e5c733b4c90c536ac46e4b6e3dfe0d5180220f0..4f38aca1d9c43ed302159d3ecf29c0e8f44fe29b 100644 (file)
@@ -40,6 +40,7 @@ as that of the covered work.  */
 
 #include <gnutls/gnutls.h>
 #include <gnutls/x509.h>
+#include <fcntl.h>
 
 #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;