]> granicus.if.org Git - rtmpdump/commitdiff
Refill if HTTP_read indicated it needs more data
authorMartin Storsjo <martin@martin.st>
Mon, 21 May 2012 15:17:32 +0000 (18:17 +0300)
committerHoward Chu <hyc@highlandsun.com>
Tue, 30 Oct 2012 16:01:51 +0000 (09:01 -0700)
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

index 21e2c1886dad05f5bbdc5435804c4283c98cc3c5..6183d200c36da64f236ae15b70fd34a355221892 100644 (file)
@@ -1403,9 +1403,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);
@@ -1416,12 +1418,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);