| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 179a5c5 commit e9388c8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,9 +21,11 @@ namespace node { | |||
| 21 | 21 | using v8::Array; | |
| 22 | 22 | using v8::ArrayBuffer; | |
| 23 | 23 | using v8::ArrayBufferView; | |
| 24 | + using v8::BackingStore; | ||
| 24 | 25 | using v8::Boolean; | |
| 25 | 26 | using v8::Context; | |
| 26 | 27 | using v8::EscapableHandleScope; | |
| 28 | + using v8::False; | ||
| 27 | 29 | using v8::Function; | |
| 28 | 30 | using v8::FunctionCallbackInfo; | |
| 29 | 31 | using v8::FunctionTemplate; | |
@@ -37,6 +39,7 @@ using v8::Number; | |||
| 37 | 39 | using v8::Object; | |
| 38 | 40 | using v8::ObjectTemplate; | |
| 39 | 41 | using v8::String; | |
| 42 | + using v8::True; | ||
| 40 | 43 | using v8::Uint8Array; | |
| 41 | 44 | using v8::Undefined; | |
| 42 | 45 | using v8::Value; | |
@@ -267,17 +270,20 @@ Local<Value> Http2Settings::Pack( | |||
| 267 | 270 | size_t count, | |
| 268 | 271 | const nghttp2_settings_entry* entries) { | |
| 269 | 272 | EscapableHandleScope scope(env->isolate()); | |
| 270 | - const size_t size = count * 6; | ||
| 271 | - AllocatedBuffer buffer = AllocatedBuffer::AllocateManaged(env, size); | ||
| 272 | - ssize_t ret = | ||
| 273 | - nghttp2_pack_settings_payload( | ||
| 274 | - reinterpret_cast<uint8_t*>(buffer.data()), | ||
| 275 | - size, | ||
| 276 | - entries, | ||
| 277 | - count); | ||
| 278 | - Local<Value> buf = Undefined(env->isolate()); | ||
| 279 | - if (ret >= 0) buf = buffer.ToBuffer().ToLocalChecked(); | ||
| 280 | - return scope.Escape(buf); | ||
| 273 | + std::unique_ptr<BackingStore> bs; | ||
| 274 | + { | ||
| 275 | + NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data()); | ||
| 276 | + bs = ArrayBuffer::NewBackingStore(env->isolate(), count * 6); | ||
| 277 | + } | ||
| 278 | + if (nghttp2_pack_settings_payload(static_cast<uint8_t*>(bs->Data()), | ||
| 279 | + bs->ByteLength(), | ||
| 280 | + entries, | ||
| 281 | + count) < 0) { | ||
| 282 | + return scope.Escape(Undefined(env->isolate())); | ||
| 283 | + } | ||
| 284 | + Local<ArrayBuffer> ab = ArrayBuffer::New(env->isolate(), std::move(bs)); | ||
| 285 | + return scope.Escape(Buffer::New(env, ab, 0, ab->ByteLength()) | ||
| 286 | + .FromMaybe(Local<Value>())); | ||
| 281 | 287 | } | |
| 282 | 288 | ||
| 283 | 289 | // Updates the shared TypedArray with the current remote or local settings for | |
@@ -323,7 +329,7 @@ void Http2Settings::Done(bool ack) { | |||
| 323 | 329 | double duration = (end - startTime_) / 1e6; | |
| 324 | 330 | ||
| 325 | 331 | Local<Value> argv[] = { | |
| 326 | - ack ? v8::True(env()->isolate()) : v8::False(env()->isolate()), | ||
| 332 | + ack ? True(env()->isolate()) : False(env()->isolate()), | ||
| 327 | 333 | Number::New(env()->isolate(), duration) | |
| 328 | 334 | }; | |
| 329 | 335 | MakeCallback(callback(), arraysize(argv), argv); | |
@@ -368,19 +374,23 @@ Origins::Origins( | |||
| 368 | 374 | return; | |
| 369 | 375 | } | |
| 370 | 376 | ||
| 371 | - buf_ = AllocatedBuffer::AllocateManaged( | ||
| 372 | - env, | ||
| 373 | - (alignof(nghttp2_origin_entry) - 1) + | ||
| 374 | - count_ * sizeof(nghttp2_origin_entry) + | ||
| 375 | - origin_string_len); | ||
| 377 | + { | ||
| 378 | + NoArrayBufferZeroFillScope no_zero_fill_scope(env->isolate_data()); | ||
| 379 | + bs_ = ArrayBuffer::NewBackingStore(env->isolate(), | ||
| 380 | + alignof(nghttp2_origin_entry) - 1 + | ||
| 381 | + count_ * sizeof(nghttp2_origin_entry) + | ||
| 382 | + origin_string_len); | ||
| 383 | + } | ||
| 376 | 384 | ||
| 377 | 385 | // Make sure the start address is aligned appropriately for an nghttp2_nv*. | |
| 378 | - char* start = AlignUp(buf_.data(), alignof(nghttp2_origin_entry)); | ||
| 386 | + char* start = AlignUp(static_cast<char*>(bs_->Data()), | ||
| 387 | + alignof(nghttp2_origin_entry)); | ||
| 379 | 388 | char* origin_contents = start + (count_ * sizeof(nghttp2_origin_entry)); | |
| 380 | 389 | nghttp2_origin_entry* const nva = | |
| 381 | 390 | reinterpret_cast<nghttp2_origin_entry*>(start); | |
| 382 | 391 | ||
| 383 | - CHECK_LE(origin_contents + origin_string_len, buf_.data() + buf_.size()); | ||
| 392 | + CHECK_LE(origin_contents + origin_string_len, | ||
| 393 | + static_cast<char*>(bs_->Data()) + bs_->ByteLength()); | ||
| 384 | 394 | CHECK_EQ(origin_string->WriteOneByte( | |
| 385 | 395 | env->isolate(), | |
| 386 | 396 | reinterpret_cast<uint8_t*>(origin_contents), | |
@@ -819,7 +829,7 @@ void Http2Session::ConsumeHTTP2Data() { | |||
| 819 | 829 | DecrementCurrentSessionMemory(stream_buf_.len); | |
| 820 | 830 | stream_buf_offset_ = 0; | |
| 821 | 831 | stream_buf_ab_.Reset(); | |
| 822 | - stream_buf_allocation_.clear(); | ||
| 832 | + stream_buf_allocation_.reset(); | ||
| 823 | 833 | stream_buf_ = uv_buf_init(nullptr, 0); | |
| 824 | 834 | ||
| 825 | 835 | // Send any data that was queued up while processing the received data. | |
@@ -1247,7 +1257,8 @@ void Http2StreamListener::OnStreamRead(ssize_t nread, const uv_buf_t& buf) { | |||
| 1247 | 1257 | ||
| 1248 | 1258 | Local<ArrayBuffer> ab; | |
| 1249 | 1259 | if (session->stream_buf_ab_.IsEmpty()) { | |
| 1250 | - ab = session->stream_buf_allocation_.ToArrayBuffer(); | ||
| 1260 | + ab = ArrayBuffer::New(env->isolate(), | ||
| 1261 | + std::move(session->stream_buf_allocation_)); | ||
| 1251 | 1262 | session->stream_buf_ab_.Reset(env->isolate(), ab); | |
| 1252 | 1263 | } else { | |
| 1253 | 1264 | ab = PersistentToLocal::Strong(session->stream_buf_ab_); | |
@@ -1823,7 +1834,7 @@ Http2Stream* Http2Session::SubmitRequest( | |||
| 1823 | 1834 | } | |
| 1824 | 1835 | ||
| 1825 | 1836 | uv_buf_t Http2Session::OnStreamAlloc(size_t suggested_size) { | |
| 1826 | - return AllocatedBuffer::AllocateManaged(env(), suggested_size).release(); | ||
| 1837 | + return env()->allocate_managed_buffer(suggested_size); | ||
| 1827 | 1838 | } | |
| 1828 | 1839 | ||
| 1829 | 1840 | // Callback used to receive inbound data from the i/o stream | |
@@ -1833,7 +1844,7 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1833 | 1844 | Http2Scope h2scope(this); | |
| 1834 | 1845 | CHECK_NOT_NULL(stream_); | |
| 1835 | 1846 | Debug(this, "receiving %d bytes, offset %d", nread, stream_buf_offset_); | |
| 1836 | - AllocatedBuffer buf(env(), buf_); | ||
| 1847 | + std::unique_ptr<BackingStore> bs = env()->release_managed_buffer(buf_); | ||
| 1837 | 1848 | ||
| 1838 | 1849 | // Only pass data on if nread > 0 | |
| 1839 | 1850 | if (nread <= 0) { | |
@@ -1843,24 +1854,34 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1843 | 1854 | return; | |
| 1844 | 1855 | } | |
| 1845 | 1856 | ||
| 1857 | + CHECK_LE(static_cast<size_t>(nread), bs->ByteLength()); | ||
| 1858 | + | ||
| 1846 | 1859 | statistics_.data_received += nread; | |
| 1847 | 1860 | ||
| 1848 | 1861 | if (LIKELY(stream_buf_offset_ == 0)) { | |
| 1849 | 1862 | // Shrink to the actual amount of used data. | |
| 1850 | - buf.Resize(nread); | ||
| 1863 | + bs = BackingStore::Reallocate(env()->isolate(), std::move(bs), nread); | ||
| 1851 | 1864 | } else { | |
| 1852 | 1865 | // This is a very unlikely case, and should only happen if the ReadStart() | |
| 1853 | 1866 | // call in OnStreamAfterWrite() immediately provides data. If that does | |
| 1854 | 1867 | // happen, we concatenate the data we received with the already-stored | |
| 1855 | 1868 | // pending input data, slicing off the already processed part. | |
| 1856 | 1869 | size_t pending_len = stream_buf_.len - stream_buf_offset_; | |
| 1857 | - AllocatedBuffer new_buf = | ||
| 1858 | - AllocatedBuffer::AllocateManaged(env(), pending_len + nread); | ||
| 1859 | - memcpy(new_buf.data(), stream_buf_.base + stream_buf_offset_, pending_len); | ||
| 1860 | - memcpy(new_buf.data() + pending_len, buf.data(), nread); | ||
| 1861 | - | ||
| 1862 | - buf = std::move(new_buf); | ||
| 1863 | - nread = buf.size(); | ||
| 1870 | + std::unique_ptr<BackingStore> new_bs; | ||
| 1871 | + { | ||
| 1872 | + NoArrayBufferZeroFillScope no_zero_fill_scope(env()->isolate_data()); | ||
| 1873 | + new_bs = ArrayBuffer::NewBackingStore(env()->isolate(), | ||
| 1874 | + pending_len + nread); | ||
| 1875 | + } | ||
| 1876 | + memcpy(static_cast<char*>(new_bs->Data()), | ||
| 1877 | + stream_buf_.base + stream_buf_offset_, | ||
| 1878 | + pending_len); | ||
| 1879 | + memcpy(static_cast<char*>(new_bs->Data()) + pending_len, | ||
| 1880 | + bs->Data(), | ||
| 1881 | + nread); | ||
| 1882 | + | ||
| 1883 | + bs = std::move(new_bs); | ||
| 1884 | + nread = bs->ByteLength(); | ||
| 1864 | 1885 | stream_buf_offset_ = 0; | |
| 1865 | 1886 | stream_buf_ab_.Reset(); | |
| 1866 | 1887 | ||
@@ -1873,12 +1894,13 @@ void Http2Session::OnStreamRead(ssize_t nread, const uv_buf_t& buf_) { | |||
| 1873 | 1894 | ||
| 1874 | 1895 | // Remember the current buffer, so that OnDataChunkReceived knows the | |
| 1875 | 1896 | // offset of a DATA frame's data into the socket read buffer. | |
| 1876 | - stream_buf_ = uv_buf_init(buf.data(), static_cast<unsigned int>(nread)); | ||
| 1897 | + stream_buf_ = uv_buf_init(static_cast<char*>(bs->Data()), | ||
| 1898 | + static_cast<unsigned int>(nread)); | ||
| 1877 | 1899 | ||
| 1878 | 1900 | // Store this so we can create an ArrayBuffer for read data from it. | |
| 1879 | 1901 | // DATA frames will be emitted as slices of that ArrayBuffer to avoid having | |
| 1880 | 1902 | // to copy memory. | |
| 1881 | - stream_buf_allocation_ = std::move(buf); | ||
| 1903 | + stream_buf_allocation_ = std::move(bs); | ||
| 1882 | 1904 | ||
| 1883 | 1905 | ConsumeHTTP2Data(); | |
| 1884 | 1906 | ||
@@ -2023,7 +2045,7 @@ void Http2Stream::Close(int32_t code) { | |||
| 2023 | 2045 | Debug(this, "closed with code %d", code); | |
| 2024 | 2046 | } | |
| 2025 | 2047 | ||
| 2026 | - ShutdownWrap* Http2Stream::CreateShutdownWrap(v8::Local<v8::Object> object) { | ||
| 2048 | + ShutdownWrap* Http2Stream::CreateShutdownWrap(Local<Object> object) { | ||
| 2027 | 2049 | // DoShutdown() always finishes synchronously, so there's no need to create | |
| 2028 | 2050 | // a structure to store asynchronous context. | |
| 2029 | 2051 | return nullptr; | |
@@ -3049,7 +3071,7 @@ void Http2Ping::Done(bool ack, const uint8_t* payload) { | |||
| 3049 | 3071 | } | |
| 3050 | 3072 | ||
| 3051 | 3073 | Local<Value> argv[] = { | |
| 3052 | - ack ? v8::True(isolate) : v8::False(isolate), | ||
| 3074 | + ack ? True(isolate) : False(isolate), | ||
| 3053 | 3075 | Number::New(isolate, duration_ms), | |
| 3054 | 3076 | buf | |
| 3055 | 3077 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | #include "nghttp2/nghttp2.h" | |
| 9 | 9 | ||
| 10 | 10 | #include "env.h" | |
| 11 | - #include "allocated_buffer.h" | ||
| 12 | 11 | #include "aliased_struct.h" | |
| 13 | 12 | #include "node_http2_state.h" | |
| 14 | 13 | #include "node_http_common.h" | |
@@ -897,7 +896,7 @@ class Http2Session : public AsyncWrap, | |||
| 897 | 896 | // When processing input data, either stream_buf_ab_ or stream_buf_allocation_ | |
| 898 | 897 | // will be set. stream_buf_ab_ is lazily created from stream_buf_allocation_. | |
| 899 | 898 | v8::Global<v8::ArrayBuffer> stream_buf_ab_; | |
| 900 | - AllocatedBuffer stream_buf_allocation_; | ||
| 899 | + std::unique_ptr<v8::BackingStore> stream_buf_allocation_; | ||
| 901 | 900 | size_t stream_buf_offset_ = 0; | |
| 902 | 901 | // Custom error code for errors that originated inside one of the callbacks | |
| 903 | 902 | // called by nghttp2_session_mem_recv. | |
@@ -1040,7 +1039,7 @@ class Origins { | |||
| 1040 | 1039 | ~Origins() = default; | |
| 1041 | 1040 | ||
| 1042 | 1041 | const nghttp2_origin_entry* operator*() const { | |
| 1043 | - return reinterpret_cast<const nghttp2_origin_entry*>(buf_.data()); | ||
| 1042 | + return static_cast<const nghttp2_origin_entry*>(bs_->Data()); | ||
| 1044 | 1043 | } | |
| 1045 | 1044 | ||
| 1046 | 1045 | size_t length() const { | |
@@ -1049,7 +1048,7 @@ class Origins { | |||
| 1049 | 1048 | ||
| 1050 | 1049 | private: | |
| 1051 | 1050 | size_t count_; | |
| 1052 | - AllocatedBuffer buf_; | ||
| 1051 | + std::unique_ptr<v8::BackingStore> bs_; | ||
| 1053 | 1052 | }; | |
| 1054 | 1053 | ||
| 1055 | 1054 | #define HTTP2_HIDDEN_CONSTANTS(V) \ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments