| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3840abe commit 71bb026
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1862,7 +1862,11 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1862 | 1862 | ||
| 1863 | 1863 | statistics_.data_received += nread; | |
| 1864 | 1864 | ||
| 1865 | - if (UNLIKELY(stream_buf_offset_ > 0)) { | ||
| 1865 | + if (LIKELY(stream_buf_offset_ == 0)) { | ||
| 1866 | + // Shrink to the actual amount of used data. | ||
| 1867 | + buf.Resize(nread); | ||
| 1868 | + IncrementCurrentSessionMemory(nread); | ||
| 1869 | + } else { | ||
| 1866 | 1870 | // This is a very unlikely case, and should only happen if the ReadStart() | |
| 1867 | 1871 | // call in OnStreamAfterWrite() immediately provides data. If that does | |
| 1868 | 1872 | // happen, we concatenate the data we received with the already-stored | |
@@ -1871,20 +1875,18 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1871 | 1875 | AllocatedBuffer new_buf = env()->AllocateManaged(pending_len + nread); | |
| 1872 | 1876 | memcpy(new_buf.data(), stream_buf_.base + stream_buf_offset_, pending_len); | |
| 1873 | 1877 | memcpy(new_buf.data() + pending_len, buf.data(), nread); | |
| 1878 | + | ||
| 1879 | + // The data in stream_buf_ is already accounted for, add nread received | ||
| 1880 | + // bytes to session memory but remove the already processed | ||
| 1881 | + // stream_buf_offset_ bytes. | ||
| 1882 | + IncrementCurrentSessionMemory(nread - stream_buf_offset_); | ||
| 1883 | + | ||
| 1874 | 1884 | buf = std::move(new_buf); | |
| 1875 | 1885 | nread = buf.size(); | |
| 1876 | 1886 | stream_buf_offset_ = 0; | |
| 1877 | 1887 | stream_buf_ab_.Reset(); | |
| 1878 | - | ||
| 1879 | - // We have now fully processed the stream_buf_ input chunk (by moving the | ||
| 1880 | - // remaining part into buf, which will be accounted for below). | ||
| 1881 | - DecrementCurrentSessionMemory(stream_buf_.len); | ||
| 1882 | 1888 | } | |
| 1883 | 1889 | ||
| 1884 | - // Shrink to the actual amount of used data. | ||
| 1885 | - buf.Resize(nread); | ||
| 1886 | - IncrementCurrentSessionMemory(nread); | ||
| 1887 | - | ||
| 1888 | 1890 | // Remember the current buffer, so that OnDataChunkReceived knows the | |
| 1889 | 1891 | // offset of a DATA frame's data into the socket read buffer. | |
| 1890 | 1892 | stream_buf_ = uv_buf_init(buf.data(), nread); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments