From fc6530cc458e78f19ea1a17f88d7891f7338ecd9 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 3 Nov 2023 14:36:43 -0400 Subject: [PATCH] ?this is fine? --- .../Testing/Temporary/LastTest.log | 4 +- cmake-build-debug/bigdata.txt | 2 +- src/main.cpp | 46 ++++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/cmake-build-debug/Testing/Temporary/LastTest.log b/cmake-build-debug/Testing/Temporary/LastTest.log index 2299319..fda6b4b 100644 --- a/cmake-build-debug/Testing/Temporary/LastTest.log +++ b/cmake-build-debug/Testing/Temporary/LastTest.log @@ -1,3 +1,3 @@ -Start testing: Nov 02 16:40 EDT +Start testing: Nov 03 13:32 EDT ---------------------------------------------------------- -End testing: Nov 02 16:40 EDT +End testing: Nov 03 13:32 EDT diff --git a/cmake-build-debug/bigdata.txt b/cmake-build-debug/bigdata.txt index 6978634..c9e6848 100644 --- a/cmake-build-debug/bigdata.txt +++ b/cmake-build-debug/bigdata.txt @@ -1 +1 @@ -hello this is big data how may i help you? \ No newline at end of file +hello this is big data how may i help you? hey hey hey u \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 699d1a6..12a0e5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,5 @@ /* - * Mail file containing the program entry point. I really want to name all this all femboy themed + * Main file containing the program entry point. I really want to name all this all femboy themed * Copyright (C) 2023 Brett Terpstra * * This program is free software: you can redistribute it and/or modify @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include constexpr size_t PACKET_SIZE = 512; @@ -126,7 +129,46 @@ void mangle(packet& packet) } } -void process_packets(const std::vector packets) +class pipe +{ + private: + std::random_device dev{}; + std::mt19937_64 engine{dev()}; + std::uniform_real_distribution dist{0.0, 1.0}; + + packet buffer; + std::atomic is_written{false}; + public: + pipe() = default; + + void send(packet packet) + { + while (is_written.load(std::memory_order::memory_order_acquire)) + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + + // 10% chance to drop the packet all together + if (dist(engine) < 0.1) + return; + + buffer = std::move(packet); + + is_written.store(true, std::memory_order::memory_order_release); + } + + void receive(packet& out) + { + while (!is_written.load(std::memory_order::memory_order_acquire)) + std::this_thread::sleep_for(std::chrono::milliseconds(1)); + + out = packet(buffer); + + mangle(out); + + is_written.store(false, std::memory_order::memory_order_release); + } +}; + +void process_packets(const std::vector& packets) { }