From a1e4641e82a42a8ae2c7555960e9b96329e708d5 Mon Sep 17 00:00:00 2001 From: kossLAN Date: Fri, 29 May 2026 11:07:43 -0400 Subject: [PATCH] wire: move message buffers into workspace crates --- Cargo.lock | 21 ++++++ Cargo.toml | 4 ++ src/ei/ei_object.rs | 30 +------- src/globals.rs | 31 ++------- src/macros.rs | 4 +- src/object.rs | 24 +------ src/utils/buffd.rs | 44 +----------- wire-buf/Cargo.toml | 17 +++++ {src/utils/buffd => wire-buf/src}/buf_in.rs | 10 +-- {src/utils/buffd => wire-buf/src}/buf_out.rs | 13 ++-- .../buffd => wire-buf/src}/ei_formatter.rs | 7 +- .../utils/buffd => wire-buf/src}/ei_parser.rs | 3 +- .../utils/buffd => wire-buf/src}/formatter.rs | 11 +-- wire-buf/src/lib.rs | 43 ++++++++++++ {src/utils/buffd => wire-buf/src}/parser.rs | 6 +- .../utils/buffd => wire-buf/src}/wl_buf_in.rs | 12 ++-- wire-types/Cargo.toml | 5 ++ wire-types/src/lib.rs | 68 +++++++++++++++++++ 18 files changed, 187 insertions(+), 166 deletions(-) create mode 100644 wire-buf/Cargo.toml rename {src/utils/buffd => wire-buf/src}/buf_in.rs (94%) rename {src/utils/buffd => wire-buf/src}/buf_out.rs (95%) rename {src/utils/buffd => wire-buf/src}/ei_formatter.rs (94%) rename {src/utils/buffd => wire-buf/src}/ei_parser.rs (97%) rename {src/utils/buffd => wire-buf/src}/formatter.rs (94%) create mode 100644 wire-buf/src/lib.rs rename {src/utils/buffd => wire-buf/src}/parser.rs (97%) rename {src/utils/buffd => wire-buf/src}/wl_buf_in.rs (95%) create mode 100644 wire-types/Cargo.toml create mode 100644 wire-types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 7e6d4c1e..91fc6921 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -707,6 +707,8 @@ dependencies = [ "jay-tracy", "jay-units", "jay-utils", + "jay-wire-buf", + "jay-wire-types", "jay-xcon", "kbvm", "libloading", @@ -884,6 +886,25 @@ dependencies = [ "uapi", ] +[[package]] +name = "jay-wire-buf" +version = "0.1.0" +dependencies = [ + "bstr", + "jay-io-uring", + "jay-time", + "jay-units", + "jay-utils", + "jay-wire-types", + "smallvec", + "thiserror", + "uapi", +] + +[[package]] +name = "jay-wire-types" +version = "0.1.0" + [[package]] name = "jay-xcon" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 3393b9c8..de33725f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,8 @@ members = [ "bufio", "dbus-core", "xcon", + "wire-types", + "wire-buf", "toml-config", "algorithms", "toml-spec", @@ -65,6 +67,8 @@ jay-io-uring = { version = "0.1.0", path = "io-uring" } jay-bufio = { version = "0.1.0", path = "bufio" } jay-dbus-core = { version = "0.1.0", path = "dbus-core" } jay-xcon = { version = "0.1.0", path = "xcon" } +jay-wire-types = { version = "0.1.0", path = "wire-types" } +jay-wire-buf = { version = "0.1.0", path = "wire-buf" } uapi = "0.2.13" thiserror = "2.0.11" diff --git a/src/ei/ei_object.rs b/src/ei/ei_object.rs index c79c78a3..701ff3dd 100644 --- a/src/ei/ei_object.rs +++ b/src/ei/ei_object.rs @@ -9,41 +9,13 @@ use { }, std::{ cmp::Ordering, - fmt::{Display, Formatter, LowerHex}, rc::Rc, }, }; +pub use jay_wire_types::EiObjectId; pub const EI_HANDSHAKE_ID: EiHandshakeId = EiHandshakeId::from_raw(0); -#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] -pub struct EiObjectId(u64); - -impl EiObjectId { - #[expect(dead_code)] - pub const NONE: Self = EiObjectId(0); - - pub fn from_raw(raw: u64) -> Self { - Self(raw) - } - - pub fn raw(self) -> u64 { - self.0 - } -} - -impl Display for EiObjectId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(&self.0, f) - } -} - -impl LowerHex for EiObjectId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - LowerHex::fmt(&self.0, f) - } -} - pub trait EiObjectBase { fn id(&self) -> EiObjectId; fn version(&self) -> EiVersion; diff --git a/src/globals.rs b/src/globals.rs index 4b828a10..f27155ca 100644 --- a/src/globals.rs +++ b/src/globals.rs @@ -85,14 +85,10 @@ use { }, arrayvec::ArrayVec, linearize::{Linearize, StaticMap}, - std::{ - cell::Cell, - error::Error, - fmt::{Display, Formatter}, - rc::Rc, - }, + std::{cell::Cell, error::Error, rc::Rc}, thiserror::Error, }; +pub use jay_wire_types::GlobalName; #[derive(Debug, Error)] pub enum GlobalsError { @@ -112,25 +108,6 @@ pub struct GlobalError { pub error: Box, } -#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] -pub struct GlobalName(u32); - -impl GlobalName { - pub fn from_raw(id: u32) -> Self { - Self(id) - } - - pub fn raw(self) -> u32 { - self.0 - } -} - -impl Display for GlobalName { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(&self.0, f) - } -} - pub trait GlobalBase { fn name(&self) -> GlobalName; fn bind<'a>( @@ -275,7 +252,7 @@ impl Globals { removed: CopyHashMap::new(), outputs: Default::default(), seats: Default::default(), - singletons: StaticMap::from_fn(|_| GlobalName(0)), + singletons: StaticMap::from_fn(|_| GlobalName::from_raw(0)), exposed: Default::default(), }; add_singletons(&mut slf); @@ -293,7 +270,7 @@ impl Globals { if id == 0 { panic!("Global names overflowed"); } - GlobalName(id) + GlobalName::from_raw(id) } fn insert_no_broadcast<'a>(&'a self, global: Rc) { diff --git a/src/macros.rs b/src/macros.rs index e9f6f4eb..90561b17 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -109,7 +109,7 @@ macro_rules! id { #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] pub struct $name(u32); - #[expect(dead_code)] + #[allow(dead_code)] impl $name { pub const NONE: Self = $name(0); @@ -639,7 +639,7 @@ macro_rules! ei_id { #[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] pub struct $name(u64); - #[expect(dead_code)] + #[allow(dead_code)] impl $name { pub const NONE: Self = $name(0); diff --git a/src/object.rs b/src/object.rs index 24005b66..3d85dea2 100644 --- a/src/object.rs +++ b/src/object.rs @@ -7,35 +7,13 @@ use { std::{ any::Any, cmp::Ordering, - fmt::{Display, Formatter}, rc::Rc, }, }; +pub use jay_wire_types::ObjectId; pub const WL_DISPLAY_ID: WlDisplayId = WlDisplayId::from_raw(1); -#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] -pub struct ObjectId(u32); - -impl ObjectId { - #[expect(dead_code)] - pub const NONE: Self = ObjectId(0); - - pub fn from_raw(raw: u32) -> Self { - Self(raw) - } - - pub fn raw(self) -> u32 { - self.0 - } -} - -impl Display for ObjectId { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - Display::fmt(&self.0, f) - } -} - pub trait ObjectBase: Any { fn id(&self) -> ObjectId; fn version(&self) -> Version; diff --git a/src/utils/buffd.rs b/src/utils/buffd.rs index bbb8a67e..f97b85c4 100644 --- a/src/utils/buffd.rs +++ b/src/utils/buffd.rs @@ -1,43 +1 @@ -use {crate::io_uring::IoUringError, thiserror::Error}; -pub use { - buf_in::BufFdIn, - buf_out::{BufFdOut, OutBuffer, OutBufferSwapchain}, - ei_formatter::EiMsgFormatter, - ei_parser::{EiMsgParser, EiMsgParserError}, - formatter::MsgFormatter, - parser::{MsgParser, MsgParserError}, - wl_buf_in::{WlBufFdIn, WlMessage}, -}; - -mod buf_in; -mod buf_out; -mod ei_formatter; -mod ei_parser; -mod formatter; -mod parser; -mod wl_buf_in; - -#[derive(Debug, Error)] -pub enum BufFdError { - #[error("An IO error occurred")] - Io(#[source] IoUringError), - #[error("An io-uring error occurred")] - Ring(#[from] IoUringError), - #[error("The peer did not send a file descriptor")] - NoFd, - #[error("The peer sent too many file descriptors")] - TooManyFds, - #[error("The peer closed the connection")] - Closed, - #[error("The connection timed out")] - Timeout, - #[error("Message size is not a multiple of 4")] - UnalignedMessageSize, - #[error("Message size is larger than 4096")] - MessageTooLarge, - #[error("Message size is smaller than 8")] - MessageTooSmall, -} - -const BUF_SIZE: usize = 4096; -const MAX_IN_FD: usize = 32; +pub use jay_wire_buf::*; diff --git a/wire-buf/Cargo.toml b/wire-buf/Cargo.toml new file mode 100644 index 00000000..09dc7b1d --- /dev/null +++ b/wire-buf/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "jay-wire-buf" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" + +[dependencies] +jay-io-uring = { version = "0.1.0", path = "../io-uring" } +jay-time = { version = "0.1.0", path = "../time" } +jay-units = { version = "0.1.0", path = "../units" } +jay-utils = { version = "0.1.0", path = "../utils" } +jay-wire-types = { version = "0.1.0", path = "../wire-types" } + +bstr = { version = "1.9.0", default-features = false, features = ["std"] } +smallvec = { version = "1.11.1", features = ["const_generics", "const_new", "union"] } +thiserror = "2.0.11" +uapi = "0.2.13" diff --git a/src/utils/buffd/buf_in.rs b/wire-buf/src/buf_in.rs similarity index 94% rename from src/utils/buffd/buf_in.rs rename to wire-buf/src/buf_in.rs index d4c06295..568d73b2 100644 --- a/src/utils/buffd/buf_in.rs +++ b/wire-buf/src/buf_in.rs @@ -1,11 +1,7 @@ use { - crate::{ - io_uring::IoUring, - utils::{ - buf::Buf, - buffd::{BUF_SIZE, BufFdError, MAX_IN_FD}, - }, - }, + crate::{BUF_SIZE, BufFdError, MAX_IN_FD}, + jay_io_uring::IoUring, + jay_utils::buf::Buf, smallvec::SmallVec, std::{collections::VecDeque, mem::MaybeUninit, rc::Rc}, uapi::{OwnedFd, Pod}, diff --git a/src/utils/buffd/buf_out.rs b/wire-buf/src/buf_out.rs similarity index 95% rename from src/utils/buffd/buf_out.rs rename to wire-buf/src/buf_out.rs index b28e5dc9..1bed2d95 100644 --- a/src/utils/buffd/buf_out.rs +++ b/wire-buf/src/buf_out.rs @@ -1,13 +1,8 @@ use { - crate::{ - io_uring::{IoUring, IoUringError}, - time::Time, - utils::{ - buf::Buf, - buffd::{BUF_SIZE, BufFdError}, - oserror::OsError, - }, - }, + crate::{BUF_SIZE, BufFdError}, + jay_io_uring::{IoUring, IoUringError}, + jay_time::Time, + jay_utils::{buf::Buf, oserror::OsError}, std::{ collections::VecDeque, mem::{self}, diff --git a/src/utils/buffd/ei_formatter.rs b/wire-buf/src/ei_formatter.rs similarity index 94% rename from src/utils/buffd/ei_formatter.rs rename to wire-buf/src/ei_formatter.rs index af71f627..0652101c 100644 --- a/src/utils/buffd/ei_formatter.rs +++ b/wire-buf/src/ei_formatter.rs @@ -1,8 +1,6 @@ use { - crate::{ - ei::ei_object::EiObjectId, - utils::buffd::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta}, - }, + crate::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta}, + jay_wire_types::EiObjectId, std::{mem, rc::Rc}, uapi::OwnedFd, }; @@ -42,7 +40,6 @@ impl<'a> EiMsgFormatter<'a> { self } - #[expect(dead_code)] pub fn long(&mut self, int: i64) -> &mut Self { self.write(uapi::as_bytes(&int)); self diff --git a/src/utils/buffd/ei_parser.rs b/wire-buf/src/ei_parser.rs similarity index 97% rename from src/utils/buffd/ei_parser.rs rename to wire-buf/src/ei_parser.rs index 361e6523..9ed0eae2 100644 --- a/src/utils/buffd/ei_parser.rs +++ b/wire-buf/src/ei_parser.rs @@ -1,5 +1,6 @@ use { - crate::{ei::ei_object::EiObjectId, utils::buffd::BufFdIn}, + crate::BufFdIn, + jay_wire_types::EiObjectId, std::{ptr, rc::Rc}, thiserror::Error, uapi::OwnedFd, diff --git a/src/utils/buffd/formatter.rs b/wire-buf/src/formatter.rs similarity index 94% rename from src/utils/buffd/formatter.rs rename to wire-buf/src/formatter.rs index 2ad83618..cde9642f 100644 --- a/src/utils/buffd/formatter.rs +++ b/wire-buf/src/formatter.rs @@ -1,9 +1,7 @@ use { - crate::{ - fixed::Fixed, - object::ObjectId, - utils::buffd::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta}, - }, + crate::buf_out::{MsgFds, OUT_BUF_SIZE, OutBuffer, OutBufferMeta}, + jay_units::Fixed, + jay_wire_types::ObjectId, std::{mem, rc::Rc}, uapi::{OwnedFd, Packed}, }; @@ -48,13 +46,11 @@ impl<'a> MsgFormatter<'a> { self } - #[expect(dead_code)] pub fn u64(&mut self, int: u64) -> &mut Self { self.uint((int >> 32) as u32); self.uint(int as u32) } - #[expect(dead_code)] pub fn u64_rev(&mut self, int: u64) -> &mut Self { self.uint(int as u32); self.uint((int >> 32) as u32) @@ -96,7 +92,6 @@ impl<'a> MsgFormatter<'a> { self.object(obj).uint(event) } - #[expect(dead_code)] pub fn array)>(&mut self, f: F) -> &mut Self { let pos = self.meta.write_pos; self.uint(0); diff --git a/wire-buf/src/lib.rs b/wire-buf/src/lib.rs new file mode 100644 index 00000000..3166180c --- /dev/null +++ b/wire-buf/src/lib.rs @@ -0,0 +1,43 @@ +use {jay_io_uring::IoUringError, thiserror::Error}; +pub use { + buf_in::BufFdIn, + buf_out::{BufFdOut, OutBuffer, OutBufferSwapchain}, + ei_formatter::EiMsgFormatter, + ei_parser::{EiMsgParser, EiMsgParserError}, + formatter::MsgFormatter, + parser::{MsgParser, MsgParserError}, + wl_buf_in::{WlBufFdIn, WlMessage}, +}; + +mod buf_in; +mod buf_out; +mod ei_formatter; +mod ei_parser; +mod formatter; +mod parser; +mod wl_buf_in; + +#[derive(Debug, Error)] +pub enum BufFdError { + #[error("An IO error occurred")] + Io(#[source] IoUringError), + #[error("An io-uring error occurred")] + Ring(#[from] IoUringError), + #[error("The peer did not send a file descriptor")] + NoFd, + #[error("The peer sent too many file descriptors")] + TooManyFds, + #[error("The peer closed the connection")] + Closed, + #[error("The connection timed out")] + Timeout, + #[error("Message size is not a multiple of 4")] + UnalignedMessageSize, + #[error("Message size is larger than 4096")] + MessageTooLarge, + #[error("Message size is smaller than 8")] + MessageTooSmall, +} + +const BUF_SIZE: usize = 4096; +const MAX_IN_FD: usize = 32; diff --git a/src/utils/buffd/parser.rs b/wire-buf/src/parser.rs similarity index 97% rename from src/utils/buffd/parser.rs rename to wire-buf/src/parser.rs index 7ae74118..cc5b0f3c 100644 --- a/src/utils/buffd/parser.rs +++ b/wire-buf/src/parser.rs @@ -1,6 +1,7 @@ use { - crate::{fixed::Fixed, globals::GlobalName, object::ObjectId}, bstr::{BStr, ByteSlice}, + jay_units::Fixed, + jay_wire_types::{GlobalName, ObjectId}, std::{collections::VecDeque, ptr, rc::Rc}, thiserror::Error, uapi::{OwnedFd, Pod}, @@ -55,14 +56,12 @@ impl<'a, 'b> MsgParser<'a, 'b> { self.int().map(|i| i as u32) } - #[expect(dead_code)] pub fn u64(&mut self) -> Result { let hi = self.uint()?; let lo = self.uint()?; Ok(((hi as u64) << 32) | lo as u64) } - #[expect(dead_code)] pub fn u64_rev(&mut self) -> Result { let lo = self.uint()?; let hi = self.uint()?; @@ -76,7 +75,6 @@ impl<'a, 'b> MsgParser<'a, 'b> { self.int().map(|i| ObjectId::from_raw(i as u32).into()) } - #[expect(dead_code)] pub fn global(&mut self) -> Result { self.int().map(|i| GlobalName::from_raw(i as u32)) } diff --git a/src/utils/buffd/wl_buf_in.rs b/wire-buf/src/wl_buf_in.rs similarity index 95% rename from src/utils/buffd/wl_buf_in.rs rename to wire-buf/src/wl_buf_in.rs index 8bca5956..9a1e5914 100644 --- a/src/utils/buffd/wl_buf_in.rs +++ b/wire-buf/src/wl_buf_in.rs @@ -1,12 +1,8 @@ use { - crate::{ - io_uring::IoUring, - object::ObjectId, - utils::{ - buf::Buf, - buffd::{BufFdError, MAX_IN_FD}, - }, - }, + crate::{BufFdError, MAX_IN_FD}, + jay_io_uring::IoUring, + jay_utils::buf::Buf, + jay_wire_types::ObjectId, std::{collections::VecDeque, ptr, rc::Rc, slice}, uapi::OwnedFd, }; diff --git a/wire-types/Cargo.toml b/wire-types/Cargo.toml new file mode 100644 index 00000000..8c5cc5aa --- /dev/null +++ b/wire-types/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "jay-wire-types" +version = "0.1.0" +edition = "2024" +license = "GPL-3.0-only" diff --git a/wire-types/src/lib.rs b/wire-types/src/lib.rs new file mode 100644 index 00000000..11434980 --- /dev/null +++ b/wire-types/src/lib.rs @@ -0,0 +1,68 @@ +use std::fmt::{Display, Formatter, LowerHex}; + +#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] +pub struct ObjectId(u32); + +impl ObjectId { + pub const NONE: Self = ObjectId(0); + + pub fn from_raw(raw: u32) -> Self { + Self(raw) + } + + pub fn raw(self) -> u32 { + self.0 + } +} + +impl Display for ObjectId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Display::fmt(&self.0, f) + } +} + +#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] +pub struct GlobalName(u32); + +impl GlobalName { + pub fn from_raw(id: u32) -> Self { + Self(id) + } + + pub fn raw(self) -> u32 { + self.0 + } +} + +impl Display for GlobalName { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Display::fmt(&self.0, f) + } +} + +#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] +pub struct EiObjectId(u64); + +impl EiObjectId { + pub const NONE: Self = EiObjectId(0); + + pub fn from_raw(raw: u64) -> Self { + Self(raw) + } + + pub fn raw(self) -> u64 { + self.0 + } +} + +impl Display for EiObjectId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Display::fmt(&self.0, f) + } +} + +impl LowerHex for EiObjectId { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + LowerHex::fmt(&self.0, f) + } +}