Commit 71fb59b6 authored by jan.koester's avatar jan.koester
Browse files

test

parent ac0b0dcb
Loading
Loading
Loading
Loading
+1 −0
Changes for src/posix/udp.cpp: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*******************************************************************************/

#include <memory>
#include <sys/mman.h>
#include "socket.h"
#include "exception.h"
#include "error.h"
+8 −0
Changes for src/socket.h: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -78,6 +78,14 @@

namespace netplus {

	// Releases (returns to the OS) the calling thread's per-thread network
	// scratch memory, e.g. the recvmmsg receive buffer. Cheap; the memory is
	// re-populated on the thread's next receive. Called by ThreadPool workers
	// after a while without work. Invalidates DatagramViews obtained on this
	// thread (they are only valid until the thread's next receive anyway).
	void releaseThreadScratch();


	// Forward-declared (defined in eventapi.h, which itself includes this
	// header) so `quic` can hold one via unique_ptr without a circular
	// #include — see quic::_cc_socketwait's comment.
+14 −1
Changes for src/threadpool.h: 14 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include <chrono>

namespace netplus {
    void releaseThreadScratch();   // socket.h

// Minimal fixed-size worker pool for offloading tasks that don't belong on
// whatever thread submits them (e.g. a caller-supplied callback that may
@@ -114,12 +115,24 @@ public:
    }

private:
    static constexpr std::chrono::seconds IDLE_RELEASE{10};

    void workerLoop() {
        for (;;) {
            std::function<void()> task;
            {
                std::unique_lock<std::mutex> lk(_mtx);
                _cv.wait(lk, [this] { return _stopping || !_tasks.empty(); });
                // After IDLE_RELEASE without work, give this thread's network
                // scratch memory back (several MB per worker otherwise stay
                // resident for the life of the process).
                bool released = false;
                while (!_cv.wait_for(lk, IDLE_RELEASE, [this] { return _stopping || !_tasks.empty(); })) {
                    if (released) continue;
                    released = true;
                    lk.unlock();
                    releaseThreadScratch();
                    lk.lock();
                }
                if (_tasks.empty()) {
                    // Only reachable via _stopping — drain fully before exiting
                    // (queued work still runs; shutdown just stops accepting
+5 −0
Changes for src/windows/udp.cpp: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -548,4 +548,9 @@ size_t udp::recvBatchAddrViews(std::vector<DatagramView>& out,
    return out.size();
}


// POSIX counterpart returns the thread's recvmmsg scratch pages to the OS;
// the Windows receive path keeps no such per-thread buffer.
void releaseThreadScratch() {}

} // namespace netplus