diff --git a/src/ChangeLog b/src/ChangeLog
index b1207895..548de629 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,9 @@
+2011-04-13  Giuseppe Scrivano  <gscrivano@gnu.org>
+
+	* openssl.c (openssl_poll): Check if the specified timeout is zero after
+	SSL_pending.
+	(openssl_peek): Make the call non-blocking.
+
 2011-04-11  Cristian Rodr�guez  <crrodriguez@opensuse.org> (tiny change)
 
 	* openssl.c (ssl_init) [! OPENSSL_NO_SSL2]: Use SSLv2 only when
diff --git a/src/openssl.c b/src/openssl.c
index 78fb5d85..b42d6986 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -289,10 +289,10 @@ openssl_poll (int fd, double timeout, int wait_for, void *arg)
 {
   struct openssl_transport_context *ctx = arg;
   SSL *conn = ctx->conn;
-  if (timeout == 0)
-    return 1;
   if (SSL_pending (conn))
     return 1;
+  if (timeout == 0)
+    return 1;
   return select_fd (fd, timeout, wait_for);
 }
 
@@ -302,6 +302,8 @@ openssl_peek (int fd, char *buf, int bufsize, void *arg)
   int ret;
   struct openssl_transport_context *ctx = arg;
   SSL *conn = ctx->conn;
+  if (! openssl_poll (fd, 0.0, WAIT_FOR_READ, arg))
+    return 0;
   do
     ret = SSL_peek (conn, buf, bufsize);
   while (ret == -1