- 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
+ }