[rtmpdump] [PATCH 4/4] Refill if HTTP_read indicated it needs more data

Martin Storsjo martin at martin.st
Mon May 21 17:17:32 CEST 2012


HTTP_read wants to skip past the first payload byte, so
it actually needs to have at least 144 + 1 bytes buffered.

This also avoids relying on the magic 144 byte constant altogether,
which could easily break if servers include less reply headers.
---
 librtmp/rtmp.c |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/librtmp/rtmp.c b/librtmp/rtmp.c
index 58c809d..1619dc4 100644
--- a/librtmp/rtmp.c
+++ b/librtmp/rtmp.c
@@ -1288,9 +1288,11 @@ ReadN(RTMP *r, char *buffer, int n)
       int nBytes = 0, nRead;
       if (r->Link.protocol & RTMP_FEATURE_HTTP)
         {
+	  int refill = 0;
 	  while (!r->m_resplen)
 	    {
-	      if (r->m_sb.sb_size < 144)
+	      int ret;
+	      if (r->m_sb.sb_size < 13 || refill)
 	        {
 		  if (!r->m_unackd)
 		    HTTP_Post(r, RTMPT_IDLE, "", 1);
@@ -1301,12 +1303,20 @@ ReadN(RTMP *r, char *buffer, int n)
 		      return 0;
 		    }
 		}
-	      if (HTTP_read(r, 0) == -1)
+	      if ((ret = HTTP_read(r, 0)) == -1)
 		{
 		  RTMP_Log(RTMP_LOGDEBUG, "%s, No valid HTTP response found", __FUNCTION__);
 		  RTMP_Close(r);
 		  return 0;
 		}
+              else if (ret == -2)
+                {
+                  refill = 1;
+                }
+              else
+                {
+                  refill = 0;
+                }
 	    }
 	  if (r->m_resplen && !r->m_sb.sb_size)
 	    RTMPSockBuf_Fill(&r->m_sb);
-- 
1.7.9.4



More information about the rtmpdump mailing list