]> granicus.if.org Git - curl/commitdiff
http2: Fix bug that data to be drained are overwritten by pending "paused" data
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Thu, 7 May 2015 14:19:08 +0000 (23:19 +0900)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 18 May 2015 06:57:18 +0000 (08:57 +0200)
lib/http2.c

index e9eb81180fb0529bc32e498545632733adb1a48a..789f76a854c47d6608282e5802f72e76f1b6e6ae 100644 (file)
@@ -831,7 +831,22 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
     return ncopy;
   }
 
-  if(stream->data) {
+  infof(data, "http2_recv: %d bytes buffer at %p (stream %x)\n",
+        len, mem, stream->stream_id);
+
+  if(data->state.drain) {
+    DEBUGF(infof(data, "http2_recv: DRAIN %zu bytes stream %x!! (%p => %p)\n",
+                 stream->memlen, stream->stream_id,
+                 stream->mem, mem));
+    if(mem != stream->mem) {
+      /* if we didn't get the same buffer this time, we must move the data to
+         the beginning */
+      memmove(mem, stream->mem, stream->memlen);
+      stream->len = len - stream->memlen;
+      stream->mem = mem;
+    }
+  }
+  else if(stream->data) {
     nread = MIN(len, stream->datalen);
     memcpy(mem, stream->data, nread);
 
@@ -851,22 +866,6 @@ static ssize_t http2_recv(struct connectdata *conn, int sockindex,
           (int)nread);
     return nread;
   }
-
-  infof(data, "http2_recv: %d bytes buffer at %p (stream %x)\n",
-        len, mem, stream->stream_id);
-
-  if(data->state.drain) {
-    DEBUGF(infof(data, "http2_recv: DRAIN %zu bytes stream %x!! (%p => %p)\n",
-                 stream->memlen, stream->stream_id,
-                 stream->mem, mem));
-    if(mem != stream->mem) {
-      /* if we didn't get the same buffer this time, we must move the data to
-         the beginning */
-      memmove(mem, stream->mem, stream->memlen);
-      stream->len = len - stream->memlen;
-      stream->mem = mem;
-    }
-  }
   else if(httpc->pause_stream_id) {
     /* If a stream paused nghttp2_session_mem_recv previously, and has
        not processed all data, it still refers to the buffer in