| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent da9fffa commit 53c691c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1902,7 +1902,11 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1902 | 1902 | ||
| 1903 | 1903 | statistics_.data_received += nread; | |
| 1904 | 1904 | ||
| 1905 | - if (UNLIKELY(stream_buf_offset_ > 0)) { | ||
| 1905 | + if (LIKELY(stream_buf_offset_ == 0)) { | ||
| 1906 | + // Shrink to the actual amount of used data. | ||
| 1907 | + buf.Resize(nread); | ||
| 1908 | + IncrementCurrentSessionMemory(nread); | ||
| 1909 | + } else { | ||
| 1906 | 1910 | // This is a very unlikely case, and should only happen if the ReadStart() | |
| 1907 | 1911 | // call in OnStreamAfterWrite() immediately provides data. If that does | |
| 1908 | 1912 | // happen, we concatenate the data we received with the already-stored | |
@@ -1911,20 +1915,18 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1911 | 1915 | AllocatedBuffer new_buf = env()->AllocateManaged(pending_len + nread); | |
| 1912 | 1916 | memcpy(new_buf.data(), stream_buf_.base + stream_buf_offset_, pending_len); | |
| 1913 | 1917 | memcpy(new_buf.data() + pending_len, buf.data(), nread); | |
| 1918 | + | ||
| 1919 | + // The data in stream_buf_ is already accounted for, add nread received | ||
| 1920 | + // bytes to session memory but remove the already processed | ||
| 1921 | + // stream_buf_offset_ bytes. | ||
| 1922 | + IncrementCurrentSessionMemory(nread - stream_buf_offset_); | ||
| 1923 | + | ||
| 1914 | 1924 | buf = std::move(new_buf); | |
| 1915 | 1925 | nread = buf.size(); | |
| 1916 | 1926 | stream_buf_offset_ = 0; | |
| 1917 | 1927 | stream_buf_ab_.Reset(); | |
| 1918 | - | ||
| 1919 | - // We have now fully processed the stream_buf_ input chunk (by moving the | ||
| 1920 | - // remaining part into buf, which will be accounted for below). | ||
| 1921 | - DecrementCurrentSessionMemory(stream_buf_.len); | ||
| 1922 | 1928 | } | |
| 1923 | 1929 | ||
| 1924 | - // Shrink to the actual amount of used data. | ||
| 1925 | - buf.Resize(nread); | ||
| 1926 | - IncrementCurrentSessionMemory(nread); | ||
| 1927 | - | ||
| 1928 | 1930 | // Remember the current buffer, so that OnDataChunkReceived knows the | |
| 1929 | 1931 | // offset of a DATA frame's data into the socket read buffer. | |
| 1930 | 1932 | stream_buf_ = uv_buf_init(buf.data(), nread); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments