#include "utils.h"
#include "connect.h"
#include "url.h"
+#include "ptimer.h"
#include "ssl.h"
#ifdef WIN32
static int
wgnutls_read (int fd, char *buf, int bufsize, void *arg)
{
+#ifdef F_GETFL
+ int flags = 0;
+#endif
int ret = 0;
+ struct ptimer *timer;
struct wgnutls_transport_context *ctx = arg;
if (ctx->peeklen)
return copysize;
}
+ if (opt.read_timeout)
+ {
+#ifdef F_GETFL
+ flags = fcntl (fd, F_GETFL, 0);
+ if (flags < 0)
+ return ret;
+
+ ret = fcntl (fd, F_SETFL, flags | O_NONBLOCK);
+ if (ret < 0)
+ return ret;
+#else
+ /* XXX: Assume it was blocking before. */
+ const int one = 1;
+ ret = ioctl (fd, FIONBIO, &one);
+ if (ret < 0)
+ return ret;
+#endif
+ timer = ptimer_new ();
+ if (timer == 0)
+ return -1;
+ }
+
do
- ret = gnutls_record_recv (ctx->session, buf, bufsize);
- while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN);
+ {
+ do
+ ret = gnutls_record_recv (ctx->session, buf, bufsize);
+ while (ret == GNUTLS_E_INTERRUPTED || ret == GNUTLS_E_AGAIN);
+ }
+ while (opt.read_timeout == 0 || ptimer_measure (timer) < opt.read_timeout);
+
+ if (opt.read_timeout)
+ {
+ ptimer_destroy (timer);
+#ifdef F_GETFL
+ ret = fcntl (fd, F_SETFL, flags);
+ if (ret < 0)
+ return ret;
+#else
+ const int zero = 0;
+ ret = ioctl (fd, FIONBIO, &zero);
+ if (ret < 0)
+ return ret;
+#endif
+ }
if (ret < 0)
ctx->last_error = ret;
bool
ssl_connect_wget (int fd)
{
- static const int cert_type_priority[] = {
- GNUTLS_CRT_X509, GNUTLS_CRT_OPENPGP, 0
- };
struct wgnutls_transport_context *ctx;
gnutls_session session;
int err;
gnutls_init (&session, GNUTLS_CLIENT);
gnutls_set_default_priority (session);
- gnutls_certificate_type_set_priority (session, cert_type_priority);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, credentials);
#ifndef FD_TO_SOCKET
# define FD_TO_SOCKET(X) (X)