]> sjero.net Git - wget/blobdiff - src/openssl.c
openssl: Retry to read if a non-blocking socket returns immediately.
[wget] / src / openssl.c
index 9bc59a5ce606d3e2f8984acfb6ec3ee629b2796f..201d24597995bbba66460fe709dcbb5f281dc9c3 100644 (file)
@@ -1,6 +1,6 @@
 /* SSL support via OpenSSL library.
    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
-   2009 Free Software Foundation, Inc.
+   2009, 2010, 2011 Free Software Foundation, Inc.
    Originally contributed by Christian Fraenkel.
 
 This file is part of GNU Wget.
@@ -33,9 +33,7 @@ as that of the covered work.  */
 
 #include <assert.h>
 #include <errno.h>
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
+#include <unistd.h>
 #include <string.h>
 
 #include <openssl/ssl.h>
@@ -48,6 +46,10 @@ as that of the covered work.  */
 #include "url.h"
 #include "ssl.h"
 
+#ifdef WINDOWS
+# include <w32sock.h>
+#endif
+
 /* Application-wide SSL context.  This is common to all SSL
    connections.  */
 static SSL_CTX *ssl_ctx;
@@ -259,8 +261,10 @@ openssl_read (int fd, char *buf, int bufsize, void *arg)
   do
     ret = SSL_read (conn, buf, bufsize);
   while (ret == -1
-         && SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
-         && errno == EINTR);
+         && (SSL_get_error (conn, ret) == SSL_ERROR_WANT_READ
+             || (SSL_get_error (conn, ret) == SSL_ERROR_SYSCALL
+                 && errno == EINTR)));
+
   return ret;
 }
 
@@ -398,7 +402,7 @@ ssl_connect_wget (int fd)
   if (!conn)
     goto error;
 #ifndef FD_TO_SOCKET
-# define FD_TO_SOCKET(x) (x)
+# define FD_TO_SOCKET(X) (X)
 #endif
   if (!SSL_set_fd (conn, FD_TO_SOCKET (fd)))
     goto error;