├── .gitignore ├── Cargo.toml ├── README.md └── src └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | *db 2 | *conf 3 | *snap.* 4 | *grind.out* 5 | vgcore* 6 | *.bk 7 | *orig 8 | tags 9 | perf* 10 | *folded 11 | *out 12 | *perf 13 | *svg 14 | *txt 15 | experiments 16 | target 17 | Cargo.lock 18 | *swp 19 | *swo 20 | *.proptest-regressions 21 | corpus 22 | artifacts 23 | .idea 24 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sludge" 3 | version = "0.0.0" 4 | authors = ["Tyler Neely "] 5 | edition = "2018" 6 | description = "sled + io_uring + SIMD web microframework" 7 | license = "GPL-3.0" 8 | homepage = "https://github.com/spacejam/sludge" 9 | repository = "https://github.com/spacejam/sludge" 10 | keywords = ["networking", "io-uring", "io_uring", "uring", "io"] 11 | categories = ["asynchronous", "concurrency", "filesystem", "network-programming", "os"] 12 | documentation = "https://docs.rs/sludge/" 13 | readme = "README.md" 14 | 15 | [badges] 16 | maintenance = { status = "actively-developed" } 17 | 18 | [profile.release] 19 | debug = true 20 | 21 | [profile.dev] 22 | debug = true 23 | 24 | [dependencies] 25 | libc = "0.2.66" 26 | extreme = "*" 27 | sled = "*" 28 | rio = "*" 29 | 30 | [features] 31 | no_metrics = [] 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sludge 2 | 3 | a cute showcase of using sled + io_uring 4 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! slow as lightning web thing [SLUDGE] 2 | use std::{ 3 | //cmp::Reverse, 4 | //collections::BinaryHeap, 5 | sync::{Arc, Condvar, Mutex}, 6 | task::{ 7 | Context, Poll, RawWaker, RawWakerVTable, Waker, 8 | }, 9 | pin::Pin, 10 | future::Future, 11 | io::Result, 12 | net::TcpStream, 13 | }; 14 | 15 | /// a web thing or something 16 | pub struct Sludge; 17 | 18 | #[derive(Default)] 19 | struct Scheduler { 20 | readable: Vec>>, 21 | writable: Vec>>, 22 | acceptaz: Vec>>, 23 | } 24 | 25 | struct RioAccept<'a>(rio::Completion<'a, TcpStream>); 26 | 27 | impl<'a> Future for RioAccept <'a>{ 28 | type Output = Result; 29 | 30 | fn poll( 31 | self: Pin<&mut Self>, 32 | _cx: &mut Context<'_>, 33 | ) -> Poll { 34 | Poll::Pending 35 | } 36 | } 37 | 38 | impl Sludge { 39 | pub async fn run() -> sled::Result<()> { 40 | let mut scheduler = Scheduler::default(); 41 | let mut scheduler = unsafe { 42 | std::pin::Pin::new_unchecked(&mut scheduler) 43 | }; 44 | 45 | let _rio = rio::new()?; 46 | let _db = sled::open("sludge_db")?; 47 | 48 | loop { 49 | let mut work = false; 50 | 51 | while let Some(_) = scheduler.writable.pop() { 52 | // write into socketz 53 | work = true; 54 | } 55 | while let Some(_) = scheduler.readable.pop() { 56 | // read off of socketz 57 | work = true; 58 | } 59 | 60 | if !work && scheduler.acceptaz.len() > 0 { 61 | // accept some more work 62 | } 63 | } 64 | } 65 | } 66 | 67 | #[derive(Default)] 68 | struct Park(Mutex, Condvar); 69 | 70 | fn unpark(park: &Park) { 71 | *park.0.lock().unwrap() = true; 72 | park.1.notify_one(); 73 | } 74 | 75 | static VTABLE: RawWakerVTable = RawWakerVTable::new( 76 | |clone_me| unsafe { 77 | let arc = Arc::from_raw(clone_me as *const Park); 78 | std::mem::forget(arc.clone()); 79 | RawWaker::new( 80 | Arc::into_raw(arc) as *const (), 81 | &VTABLE, 82 | ) 83 | }, 84 | |wake_me| unsafe { 85 | unpark(&Arc::from_raw(wake_me as *const Park)) 86 | }, 87 | |wake_by_ref_me| unsafe { 88 | unpark(&*(wake_by_ref_me as *const Park)) 89 | }, 90 | |drop_me| unsafe { 91 | drop(Arc::from_raw(drop_me as *const Park)) 92 | }, 93 | ); 94 | 95 | /// Run a `Future`. 96 | pub fn run(mut f: F) -> F::Output { 97 | let mut f = 98 | unsafe { std::pin::Pin::new_unchecked(&mut f) }; 99 | let park = Arc::new(Park::default()); 100 | let sender = Arc::into_raw(park.clone()); 101 | let raw_waker = 102 | RawWaker::new(sender as *const _, &VTABLE); 103 | let waker = unsafe { Waker::from_raw(raw_waker) }; 104 | let mut cx = Context::from_waker(&waker); 105 | 106 | loop { 107 | match f.as_mut().poll(&mut cx) { 108 | Poll::Pending => { 109 | let mut runnable = park.0.lock().unwrap(); 110 | while !*runnable { 111 | runnable = 112 | park.1.wait(runnable).unwrap(); 113 | } 114 | *runnable = false; 115 | } 116 | Poll::Ready(val) => return val, 117 | } 118 | } 119 | } 120 | --------------------------------------------------------------------------------