From c3b5bacaeb0659f660f5bf0057f5a9de898de732 Mon Sep 17 00:00:00 2001
From: Jiri Hruska <jirka@fud.cz>
Date: Mon, 9 Sep 2013 01:05:14 +0200
Subject: [PATCH 1/4] pingpong: Check SSL library buffers for already read
 data

Otherwise the connection can get stuck during various phases,
waiting for new data on the socket using select() etc., but
they will never come as they were already read into SSL library.
---
 lib/pingpong.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/lib/pingpong.c b/lib/pingpong.c
index 7a76573..3ebeabe 100644
--- a/lib/pingpong.c
+++ b/lib/pingpong.c
@@ -33,6 +33,7 @@
 #include "pingpong.h"
 #include "multiif.h"
 #include "non-ascii.h"
+#include "sslgen.h"
 
 #define _MPRINTF_REPLACE /* use our functions only */
 #include <curl/mprintf.h>
@@ -105,6 +106,9 @@ CURLcode Curl_pp_statemach(struct pingpong *pp, bool block)
   if(Curl_pp_moredata(pp))
     /* We are receiving and there is data in the cache so just read it */
     rc = 1;
+  else if(!pp->sendleft && Curl_ssl_data_pending(conn, FIRSTSOCKET))
+    /* We are receiving and there is data ready in the SSL library */
+    rc = 1;
   else
     rc = Curl_socket_ready(pp->sendleft?CURL_SOCKET_BAD:sock, /* reading */
                            pp->sendleft?sock:CURL_SOCKET_BAD, /* writing */
-- 
1.7.9.msysgit.0

