Commit 0d01b614 authored by jan.koester's avatar jan.koester
Browse files

speed

parent ce3eb367
Loading
Loading
Loading
Loading
+16 −5
Changes for src/quic.cpp: 16 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2344,7 +2344,7 @@ void quic::handshake_after_accept() {
    // Dispatch stream callbacks outside the lock
    if (!dispatches.empty() && _stream_callback) {
        for (auto& pd : dispatches) {
            _stream_callback(this, pd.stream_id, pd.data, pd.fin);
            invokeStreamCallback(pd);
        }
    }
}
@@ -2367,7 +2367,7 @@ void quic::scheduleDispatches(std::shared_ptr<quic> self,
        // retroactively.
        auto t0 = std::chrono::steady_clock::now();
        for (auto& pd : dispatches) {
            self->_stream_callback(self.get(), pd.stream_id, pd.data, pd.fin);
            self->invokeStreamCallback(pd);
        }
        if (std::chrono::steady_clock::now() - t0 > kSlowDispatchThreshold) {
            self->_dispatch_promoted.store(true);
@@ -2392,6 +2392,17 @@ void quic::scheduleDispatches(std::shared_ptr<quic> self,
    }
}

void quic::invokeStreamCallback(const PendingDispatch &pd) noexcept {
    try {
        _stream_callback(this, pd.stream_id, pd.data, pd.fin);
    } catch (const std::exception &e) {
        QUIC_DBG("stream callback threw on stream %llu: %s",
                 (unsigned long long)pd.stream_id, e.what());
    } catch (...) {
        QUIC_DBG("stream callback threw on stream %llu", (unsigned long long)pd.stream_id);
    }
}

void quic::runDispatchQueue(std::shared_ptr<quic> self) {
    for (;;) {
        std::vector<PendingDispatch> batch;
@@ -2405,7 +2416,7 @@ void quic::runDispatchQueue(std::shared_ptr<quic> self) {
            _dispatch_queue.pop_front();
        }
        for (auto& pd : batch) {
            _stream_callback(this, pd.stream_id, pd.data, pd.fin);
            invokeStreamCallback(pd);
        }
    }
    // `self` (kept alive across the whole loop, including while the queue
@@ -4777,7 +4788,7 @@ size_t quic::recvData(buffer& data, int flags) {
    // Dispatch stream callbacks inline (mutex already released).
    if (!dispatches.empty() && _stream_callback) {
        for (auto& pd : dispatches) {
            _stream_callback(this, pd.stream_id, pd.data, pd.fin);
            invokeStreamCallback(pd);
        }
    }

@@ -4850,7 +4861,7 @@ size_t quic::pumpNetwork(int flags) {
    // Dispatch stream callbacks outside the lock
    if (!dispatches.empty() && _stream_callback) {
        for (auto& pd : dispatches) {
            _stream_callback(this, pd.stream_id, pd.data, pd.fin);
            invokeStreamCallback(pd);
        }
    }

+7 −0
Changes for src/socket.h: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2069,6 +2069,13 @@ namespace netplus {
		static constexpr std::chrono::microseconds kSlowDispatchThreshold{2000};
		static void scheduleDispatches(std::shared_ptr<quic> self,
		                                std::vector<PendingDispatch> dispatches);
		// Calls _stream_callback for one dispatch and never lets an
		// exception out: thrown inside runDispatchQueue() it used to end
		// the loop with _dispatch_running still true, so that connection's
		// later dispatches were queued and never run (a request the peer
		// waits for until its own timeout); thrown in an inline batch it
		// dropped the rest of the batch.
		void invokeStreamCallback(const PendingDispatch &pd) noexcept;
		void runDispatchQueue(std::shared_ptr<quic> self);

		// F50: _dispatch_promoted is polled by whichever thread just