+ if (i >= len - 1) {
+ buf[i] = 0;
+ return i;
+ }
+ } else {
+ fd_set rd_set, wr_set;
+ int maxfd = vpninfo->ssl_fd;
+
+ FD_ZERO(&rd_set);
+ FD_ZERO(&wr_set);
+
+ ret = SSL_get_error(vpninfo->https_ssl, ret);
+ if (ret == SSL_ERROR_WANT_READ)
+ FD_SET(vpninfo->ssl_fd, &rd_set);
+ else if (ret == SSL_ERROR_WANT_WRITE)
+ FD_SET(vpninfo->ssl_fd, &wr_set);
+ else {
+ vpn_progress(vpninfo, PRG_ERR, _("Failed to read from SSL socket\n"));
+ report_ssl_errors(vpninfo);
+ ret = -EIO;
+ break;
+ }
+ if (vpninfo->cancel_fd != -1) {
+ FD_SET(vpninfo->cancel_fd, &rd_set);
+ if (vpninfo->cancel_fd > vpninfo->ssl_fd)
+ maxfd = vpninfo->cancel_fd;
+ }
+ select(maxfd + 1, &rd_set, &wr_set, NULL, NULL);
+ if (vpninfo->cancel_fd != -1 &&
+ FD_ISSET(vpninfo->cancel_fd, &rd_set)) {
+ vpn_progress(vpninfo, PRG_ERR, _("SSL read cancelled\n"));
+ ret = -EINTR;
+ break;
+ }