| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -335,7 +335,7 @@ void BindingData::OnFlushCheck() { | |||
| 335 | 335 | // pending_flush_sessions_ and are picked up on the next check tick. | |
| 336 | 336 | auto sessions = std::move(pending_flush_sessions_); | |
| 337 | 337 | for (auto& session : sessions) { | |
| 338 | - session->pending_flush_ = false; | ||
| 338 | + session->flags_.pending_flush = false; | ||
| 339 | 339 | if (!session->is_destroyed()) { | |
| 340 | 340 | session->FlushPendingData(); | |
| 341 | 341 | } | |
@@ -437,28 +437,28 @@ JS_METHOD_IMPL(BindingData::SetCallbacks) { | |||
| 437 | 437 | } | |
| 438 | 438 | ||
| 439 | 439 | NgTcp2CallbackScope::NgTcp2CallbackScope(Session* session) : session(session) { | |
| 440 | - CHECK(!session->in_ngtcp2_callback_scope_); | ||
| 441 | - session->in_ngtcp2_callback_scope_ = true; | ||
| 440 | + CHECK(!session->flags_.in_ngtcp2_callback_scope); | ||
| 441 | + session->flags_.in_ngtcp2_callback_scope = true; | ||
| 442 | 442 | } | |
| 443 | 443 | ||
| 444 | 444 | NgTcp2CallbackScope::~NgTcp2CallbackScope() { | |
| 445 | - session->in_ngtcp2_callback_scope_ = false; | ||
| 446 | - if (session->destroy_deferred_) { | ||
| 447 | - session->destroy_deferred_ = false; | ||
| 445 | + session->flags_.in_ngtcp2_callback_scope = false; | ||
| 446 | + if (session->flags_.destroy_deferred) { | ||
| 447 | + session->flags_.destroy_deferred = false; | ||
| 448 | 448 | session->Destroy(); | |
| 449 | 449 | } | |
| 450 | 450 | } | |
| 451 | 451 | ||
| 452 | 452 | NgHttp3CallbackScope::NgHttp3CallbackScope(Session* session) | |
| 453 | 453 | : session(session) { | |
| 454 | - CHECK(!session->in_nghttp3_callback_scope_); | ||
| 455 | - session->in_nghttp3_callback_scope_ = true; | ||
| 454 | + CHECK(!session->flags_.in_nghttp3_callback_scope); | ||
| 455 | + session->flags_.in_nghttp3_callback_scope = true; | ||
| 456 | 456 | } | |
| 457 | 457 | ||
| 458 | 458 | NgHttp3CallbackScope::~NgHttp3CallbackScope() { | |
| 459 | - session->in_nghttp3_callback_scope_ = false; | ||
| 460 | - if (session->destroy_deferred_) { | ||
| 461 | - session->destroy_deferred_ = false; | ||
| 459 | + session->flags_.in_nghttp3_callback_scope = false; | ||
| 460 | + if (session->flags_.destroy_deferred) { | ||
| 461 | + session->flags_.destroy_deferred = false; | ||
| 462 | 462 | session->Destroy(); | |
| 463 | 463 | } | |
| 464 | 464 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,7 +137,9 @@ Store Store::CopyFrom(Local<ArrayBuffer> buffer) { | |||
| 137 | 137 | auto backing = buffer->GetBackingStore(); | |
| 138 | 138 | auto length = buffer->ByteLength(); | |
| 139 | 139 | auto dest = ArrayBuffer::NewBackingStore( | |
| 140 | - isolate, length, BackingStoreInitializationMode::kUninitialized, | ||
| 140 | + isolate, | ||
| 141 | + length, | ||
| 142 | + BackingStoreInitializationMode::kUninitialized, | ||
| 141 | 143 | BackingStoreOnFailureMode::kReturnNull); | |
| 142 | 144 | if (!dest) { | |
| 143 | 145 | THROW_ERR_MEMORY_ALLOCATION_FAILED(Environment::GetCurrent(isolate)); | |
@@ -154,7 +156,9 @@ Store Store::CopyFrom(Local<ArrayBufferView> view) { | |||
| 154 | 156 | auto length = view->ByteLength(); | |
| 155 | 157 | auto offset = view->ByteOffset(); | |
| 156 | 158 | auto dest = ArrayBuffer::NewBackingStore( | |
| 157 | - isolate, length, BackingStoreInitializationMode::kUninitialized, | ||
| 159 | + isolate, | ||
| 160 | + length, | ||
| 161 | + BackingStoreInitializationMode::kUninitialized, | ||
| 158 | 162 | BackingStoreOnFailureMode::kReturnNull); | |
| 159 | 163 | // copy content | |
| 160 | 164 | if (!dest) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -378,7 +378,7 @@ Endpoint::UDP::~UDP() { | |||
| 378 | 378 | } | |
| 379 | 379 | ||
| 380 | 380 | int Endpoint::UDP::Bind(const Options& options) { | |
| 381 | - if (is_bound_) return UV_EALREADY; | ||
| 381 | + if (flags_.is_bound) return UV_EALREADY; | ||
| 382 | 382 | if (is_closed_or_closing()) return UV_EBADF; | |
| 383 | 383 | ||
| 384 | 384 | int flags = 0; | |
@@ -389,7 +389,7 @@ int Endpoint::UDP::Bind(const Options& options) { | |||
| 389 | 389 | int size; | |
| 390 | 390 | ||
| 391 | 391 | if (!err) { | |
| 392 | - is_bound_ = true; | ||
| 392 | + flags_.is_bound = true; | ||
| 393 | 393 | size = static_cast<int>(options.udp_receive_buffer_size); | |
| 394 | 394 | if (size > 0) { | |
| 395 | 395 | err = uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(&impl_->handle_), | |
@@ -428,34 +428,34 @@ void Endpoint::UDP::Unref() { | |||
| 428 | 428 | ||
| 429 | 429 | int Endpoint::UDP::Start() { | |
| 430 | 430 | if (is_closed_or_closing()) return UV_EBADF; | |
| 431 | - if (is_started_) return 0; | ||
| 431 | + if (flags_.is_started) return 0; | ||
| 432 | 432 | int err = uv_udp_recv_start(&impl_->handle_, Impl::OnAlloc, Impl::OnReceive); | |
| 433 | - is_started_ = (err == 0); | ||
| 433 | + flags_.is_started = (err == 0); | ||
| 434 | 434 | return err; | |
| 435 | 435 | } | |
| 436 | 436 | ||
| 437 | 437 | void Endpoint::UDP::Stop() { | |
| 438 | - if (is_closed_or_closing() || !is_started_) return; | ||
| 438 | + if (is_closed_or_closing() || !flags_.is_started) return; | ||
| 439 | 439 | USE(uv_udp_recv_stop(&impl_->handle_)); | |
| 440 | - is_started_ = false; | ||
| 440 | + flags_.is_started = false; | ||
| 441 | 441 | } | |
| 442 | 442 | ||
| 443 | 443 | void Endpoint::UDP::Close() { | |
| 444 | 444 | if (is_closed_or_closing()) return; | |
| 445 | 445 | DCHECK(impl_); | |
| 446 | 446 | Stop(); | |
| 447 | - is_bound_ = false; | ||
| 448 | - is_closed_ = true; | ||
| 447 | + flags_.is_bound = false; | ||
| 448 | + flags_.is_closed = true; | ||
| 449 | 449 | impl_->Close(); | |
| 450 | 450 | impl_.reset(); | |
| 451 | 451 | } | |
| 452 | 452 | ||
| 453 | 453 | bool Endpoint::UDP::is_bound() const { | |
| 454 | - return is_bound_; | ||
| 454 | + return flags_.is_bound; | ||
| 455 | 455 | } | |
| 456 | 456 | ||
| 457 | 457 | bool Endpoint::UDP::is_closed() const { | |
| 458 | - return is_closed_; | ||
| 458 | + return flags_.is_closed; | ||
| 459 | 459 | } | |
| 460 | 460 | ||
| 461 | 461 | bool Endpoint::UDP::is_closed_or_closing() const { | |
@@ -1295,8 +1295,8 @@ void Endpoint::Receive(const uint8_t* data, | |||
| 1295 | 1295 | } | |
| 1296 | 1296 | // Schedule the session for deferred SendPendingData if it hasn't | |
| 1297 | 1297 | // been scheduled already in this burst. | |
| 1298 | - if (!session->is_destroyed() && !session->pending_flush_) { | ||
| 1299 | - session->pending_flush_ = true; | ||
| 1298 | + if (!session->is_destroyed() && !session->flags_.pending_flush) { | ||
| 1299 | + session->flags_.pending_flush = true; | ||
| 1300 | 1300 | BindingData::Get(env()).ScheduleSessionFlush( | |
| 1301 | 1301 | BaseObjectPtr<Session>(session)); | |
| 1302 | 1302 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,9 +349,12 @@ class Endpoint final : public AsyncWrap, public Packet::Listener { | |||
| 349 | 349 | class Impl; | |
| 350 | 350 | ||
| 351 | 351 | BaseObjectWeakPtr<Impl> impl_; | |
| 352 | - bool is_bound_ = false; | ||
| 353 | - bool is_started_ = false; | ||
| 354 | - bool is_closed_ = false; | ||
| 352 | + struct Flags { | ||
| 353 | + uint8_t is_bound : 1 = 0; | ||
| 354 | + uint8_t is_started : 1 = 0; | ||
| 355 | + uint8_t is_closed : 1 = 0; | ||
| 356 | + }; | ||
| 357 | + Flags flags_; | ||
| 355 | 358 | }; | |
| 356 | 359 | ||
| 357 | 360 | bool is_closed() const; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,7 @@ | |||
| 13 | 13 | #include "node_external_reference.h" | |
| 14 | 14 | ||
| 15 | 15 | #include <ngtcp2/ngtcp2_crypto_ossl.h> | |
| 16 | - #include <mutex> | ||
| 16 | + | ||
| 17 | 17 | namespace node { | |
| 18 | 18 | ||
| 19 | 19 | using v8::Context; | |
@@ -25,7 +25,11 @@ using v8::Value; | |||
| 25 | 25 | namespace quic { | |
| 26 | 26 | ||
| 27 | 27 | namespace { | |
| 28 | - std::once_flag crypto_init_flag; | ||
| 28 | + uv_once_t crypto_init_flag = UV_ONCE_INIT; | ||
| 29 | + | ||
| 30 | + void InitNgtcp2CryptoOnce() { | ||
| 31 | + ngtcp2_crypto_ossl_init(); | ||
| 32 | + } | ||
| 29 | 33 | } // namespace | |
| 30 | 34 | ||
| 31 | 35 | void CreatePerIsolateProperties(IsolateData* isolate_data, | |
@@ -39,8 +43,8 @@ void CreatePerContextProperties(Local<Object> target, | |||
| 39 | 43 | Local<Value> unused, | |
| 40 | 44 | Local<Context> context, | |
| 41 | 45 | void* priv) { | |
| 46 | + uv_once(&crypto_init_flag, InitNgtcp2CryptoOnce); | ||
| 42 | 47 | Realm* realm = Realm::GetCurrent(context); | |
| 43 | - std::call_once(crypto_init_flag, ngtcp2_crypto_ossl_init); | ||
| 44 | 48 | BindingData::InitPerContext(realm, target); | |
| 45 | 49 | Endpoint::InitPerContext(realm, target); | |
| 46 | 50 | Session::InitPerContext(realm, target); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1818,7 +1818,7 @@ bool Session::is_server() const { | |||
| 1818 | 1818 | } | |
| 1819 | 1819 | ||
| 1820 | 1820 | bool Session::is_destroyed() const { | |
| 1821 | - return !impl_ || destroy_deferred_; | ||
| 1821 | + return !impl_ || flags_.destroy_deferred; | ||
| 1822 | 1822 | } | |
| 1823 | 1823 | ||
| 1824 | 1824 | bool Session::is_destroyed_or_closing() const { | |
@@ -1996,9 +1996,9 @@ void Session::Destroy() { | |||
| 1996 | 1996 | // destroy impl_ now because the callback is executing methods on | |
| 1997 | 1997 | // objects owned by impl_ (e.g., the Application). Defer the | |
| 1998 | 1998 | // destruction until the scope exits. | |
| 1999 | - if (in_ngtcp2_callback_scope_ || in_nghttp3_callback_scope_) { | ||
| 1999 | + if (flags_.in_ngtcp2_callback_scope || flags_.in_nghttp3_callback_scope) { | ||
| 2000 | 2000 | Debug(this, "Session destroy deferred (in callback scope)"); | |
| 2001 | - destroy_deferred_ = true; | ||
| 2001 | + flags_.destroy_deferred = true; | ||
| 2002 | 2002 | return; | |
| 2003 | 2003 | } | |
| 2004 | 2004 | ||
@@ -2139,8 +2139,8 @@ void Session::EmitQlog(uint32_t flags, std::string_view data) { | |||
| 2139 | 2139 | if (is_destroyed()) { | |
| 2140 | 2140 | auto isolate = env()->isolate(); | |
| 2141 | 2141 | Global<Object> recv(isolate, object()); | |
| 2142 | - Global<Function> cb( | ||
| 2143 | - isolate, BindingData::Get(env()).session_qlog_callback()); | ||
| 2142 | + Global<Function> cb(isolate, | ||
| 2143 | + BindingData::Get(env()).session_qlog_callback()); | ||
| 2144 | 2144 | std::string buf(data); | |
| 2145 | 2145 | env()->SetImmediate([recv = std::move(recv), | |
| 2146 | 2146 | cb = std::move(cb), | |
@@ -2389,7 +2389,7 @@ void Session::SendBatch(Packet::Ptr* packets, | |||
| 2389 | 2389 | if (primary_count == 0) return; | |
| 2390 | 2390 | ||
| 2391 | 2391 | // Use batched send for the primary endpoint. | |
| 2392 | - if (prefer_try_send_) { | ||
| 2392 | + if (flags_.prefer_try_send) { | ||
| 2393 | 2393 | endpoint().SendBatch(primary_packets, primary_count); | |
| 2394 | 2394 | } else { | |
| 2395 | 2395 | // Non-flush path: send individually via async uv_udp_send. | |
@@ -2404,9 +2404,9 @@ void Session::FlushPendingData() { | |||
| 2404 | 2404 | if (impl_->application_) { | |
| 2405 | 2405 | // Prefer synchronous sends during the deferred flush to avoid the | |
| 2406 | 2406 | // one-tick latency of async uv_udp_send from the uv_check callback. | |
| 2407 | - prefer_try_send_ = true; | ||
| 2407 | + flags_.prefer_try_send = true; | ||
| 2408 | 2408 | application().SendPendingData(); | |
| 2409 | - prefer_try_send_ = false; | ||
| 2409 | + flags_.prefer_try_send = false; | ||
| 2410 | 2410 | } | |
| 2411 | 2411 | } | |
| 2412 | 2412 | ||
@@ -2430,7 +2430,7 @@ void Session::Send(Packet::Ptr packet) { | |||
| 2430 | 2430 | // prefer synchronous send to avoid the one-tick latency of async | |
| 2431 | 2431 | // uv_udp_send. SendOrTrySend uses uv_udp_try_send first, falling | |
| 2432 | 2432 | // back to uv_udp_send on EAGAIN. | |
| 2433 | - if (prefer_try_send_) { | ||
| 2433 | + if (flags_.prefer_try_send) { | ||
| 2434 | 2434 | Debug(this, "Session is sending (try_send) %s", packet->ToString()); | |
| 2435 | 2435 | endpoint().SendOrTrySend(std::move(packet)); | |
| 2436 | 2436 | return; | |
@@ -2865,7 +2865,7 @@ bool Session::can_send_packets() const { | |||
| 2865 | 2865 | // or closing period. The callback scope check is per-session so that | |
| 2866 | 2866 | // one session's ngtcp2 callback does not block unrelated sessions | |
| 2867 | 2867 | // from sending. | |
| 2868 | - return !is_destroyed() && !in_ngtcp2_callback_scope_ && | ||
| 2868 | + return !is_destroyed() && !flags_.in_ngtcp2_callback_scope && | ||
| 2869 | 2869 | !is_in_draining_period() && !is_in_closing_period(); | |
| 2870 | 2870 | } | |
| 2871 | 2871 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -606,25 +606,30 @@ class Session final : public AsyncWrap, private SessionTicket::AppData::Source { | |||
| 606 | 606 | Side side_; | |
| 607 | 607 | const ngtcp2_mem* allocator_; | |
| 608 | 608 | std::unique_ptr<Impl> impl_; | |
| 609 | - // These flags live on Session (not Impl) so that the NgTcp2CallbackScope | ||
| 610 | - // and NgHttp3CallbackScope destructors can safely clear them even after | ||
| 611 | - // Impl has been destroyed via MakeCallback re-entrancy during a callback. | ||
| 612 | - // The scope is placed at the ngtcp2/nghttp3 entry point (e.g. Receive, | ||
| 613 | - // OnTimeout) rather than on individual callbacks, so the deferred destroy | ||
| 614 | - // only fires after all callbacks for that entry point have completed. | ||
| 615 | - bool in_ngtcp2_callback_scope_ = false; | ||
| 616 | - bool in_nghttp3_callback_scope_ = false; | ||
| 617 | - bool destroy_deferred_ = false; | ||
| 618 | - // Set when this session is in BindingData's pending_flush_sessions_ vector. | ||
| 619 | - // Cleared by the flush callback before calling SendPendingData. | ||
| 620 | - // Provides O(1) dedup so a session receiving multiple packets in one I/O | ||
| 621 | - // burst is only scheduled for flush once. | ||
| 622 | - bool pending_flush_ = false; | ||
| 623 | - // When true, Session::Send prefers synchronous delivery via | ||
| 624 | - // Endpoint::SendOrTrySend (uv_udp_try_send with async fallback). | ||
| 625 | - // Set during FlushPendingData to avoid the one-tick latency of | ||
| 626 | - // async-only sends from the uv_check callback. | ||
| 627 | - bool prefer_try_send_ = false; | ||
| 609 | + | ||
| 610 | + struct Flags { | ||
| 611 | + // These flags live on Session (not Impl) so that the NgTcp2CallbackScope | ||
| 612 | + // and NgHttp3CallbackScope destructors can safely clear them even after | ||
| 613 | + // Impl has been destroyed via MakeCallback re-entrancy during a callback. | ||
| 614 | + // The scope is placed at the ngtcp2/nghttp3 entry point (e.g. Receive, | ||
| 615 | + // OnTimeout) rather than on individual callbacks, so the deferred destroy | ||
| 616 | + // only fires after all callbacks for that entry point have completed. | ||
| 617 | + uint8_t in_ngtcp2_callback_scope : 1 = 0; | ||
| 618 | + uint8_t in_nghttp3_callback_scope : 1 = 0; | ||
| 619 | + uint8_t destroy_deferred : 1 = 0; | ||
| 620 | + // Set when this session is in BindingData's pending_flush_sessions_ vector. | ||
| 621 | + // Cleared by the flush callback before calling SendPendingData. | ||
| 622 | + // Provides O(1) dedup so a session receiving multiple packets in one I/O | ||
| 623 | + // burst is only scheduled for flush once. | ||
| 624 | + uint8_t pending_flush : 1 = 0; | ||
| 625 | + // When true, Session::Send prefers synchronous delivery via | ||
| 626 | + // Endpoint::SendOrTrySend (uv_udp_try_send with async fallback). | ||
| 627 | + // Set during FlushPendingData to avoid the one-tick latency of | ||
| 628 | + // async-only sends from the uv_check callback. | ||
| 629 | + uint8_t prefer_try_send : 1 = 0; | ||
| 630 | + }; | ||
| 631 | + Flags flags_; | ||
| 632 | + | ||
| 628 | 633 | QuicConnectionPointer connection_; | |
| 629 | 634 | std::unique_ptr<TLSSession> tls_session_; | |
| 630 | 635 | friend struct NgTcp2CallbackScope; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments