Make wgnutls_peek non blocking.

This commit is contained in:
Giuseppe Scrivano 2011-04-03 02:15:22 +02:00
parent 28db25933b
commit ca244196f1
4 changed files with 24 additions and 0 deletions

View File

@ -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.

View File

@ -32,6 +32,7 @@ bind
c-ctype
close
connect
fcntl
getaddrinfo
getopt-gnu
getpass-gnu

View 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

View 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;