1
0
Fork 0
forked from wry/wry

forker: split protocol messages

This commit is contained in:
kossLAN 2026-05-29 19:23:28 -04:00
parent 08b37552e2
commit e78e9bcd4c
No known key found for this signature in database
3 changed files with 43 additions and 37 deletions

View file

@ -1,10 +1,12 @@
mod io; mod io;
mod protocol;
use { use {
crate::{ crate::{
async_engine::{AsyncEngine, SpawnedFuture}, async_engine::{AsyncEngine, SpawnedFuture},
compositor::{DISPLAY, LIBEI_SOCKET, WAYLAND_DISPLAY}, compositor::{DISPLAY, LIBEI_SOCKET, WAYLAND_DISPLAY},
forker::io::{IoIn, IoOut}, forker::io::{IoIn, IoOut},
forker::protocol::{ForkerMessage, ServerMessage, bincode_ops},
io_uring::IoUring, io_uring::IoUring,
state::State, state::State,
utils::{ utils::{
@ -23,7 +25,6 @@ use {
ahash::AHashMap, ahash::AHashMap,
bincode::Options, bincode::Options,
log::Level, log::Level,
serde::{Deserialize, Serialize},
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
env, env,
@ -37,13 +38,6 @@ use {
uapi::{Errno, Fd, IntoUstr, OwnedFd, UstrPtr, c}, uapi::{Errno, Fd, IntoUstr, OwnedFd, UstrPtr, c},
}; };
pub fn bincode_ops() -> impl Options {
bincode::DefaultOptions::new()
.with_fixint_encoding()
.with_little_endian()
.with_no_limit()
}
pub struct ForkerProxy { pub struct ForkerProxy {
pidfd: Rc<OwnedFd>, pidfd: Rc<OwnedFd>,
socket: Rc<OwnedFd>, socket: Rc<OwnedFd>,
@ -299,34 +293,6 @@ impl ForkerProxy {
} }
} }
#[derive(Serialize, Deserialize)]
enum ServerMessage {
SetEnv {
var: Vec<u8>,
val: Option<Vec<u8>>,
},
Spawn {
prog: String,
args: Vec<String>,
env: Vec<(String, Option<String>)>,
fds: Vec<i32>,
pidfd_id: Option<u32>,
},
}
#[derive(Serialize, Deserialize)]
enum ForkerMessage {
Log {
level: usize,
msg: String,
},
PidFd {
id: u32,
success: bool,
pid: c::pid_t,
},
}
struct Forker { struct Forker {
socket: Rc<OwnedFd>, socket: Rc<OwnedFd>,
ae: Rc<AsyncEngine>, ae: Rc<AsyncEngine>,

View file

@ -6,7 +6,7 @@ use {
use { use {
crate::{ crate::{
forker::{ForkerError, bincode_ops}, forker::{ForkerError, protocol::bincode_ops},
io_uring::IoUring, io_uring::IoUring,
utils::{ utils::{
buf::DynamicBuf, buf::DynamicBuf,

40
src/forker/protocol.rs Normal file
View file

@ -0,0 +1,40 @@
use {
bincode::Options,
serde::{Deserialize, Serialize},
uapi::c,
};
pub(super) fn bincode_ops() -> impl Options {
bincode::DefaultOptions::new()
.with_fixint_encoding()
.with_little_endian()
.with_no_limit()
}
#[derive(Serialize, Deserialize)]
pub(super) enum ServerMessage {
SetEnv {
var: Vec<u8>,
val: Option<Vec<u8>>,
},
Spawn {
prog: String,
args: Vec<String>,
env: Vec<(String, Option<String>)>,
fds: Vec<i32>,
pidfd_id: Option<u32>,
},
}
#[derive(Serialize, Deserialize)]
pub(super) enum ForkerMessage {
Log {
level: usize,
msg: String,
},
PidFd {
id: u32,
success: bool,
pid: c::pid_t,
},
}