summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2025-08-01 19:23:57 -0400
committerLLLL Colonq <llll@colonq>2025-08-01 19:23:57 -0400
commit42add4b3e62027bb1943bdcf99bbf67f3f312241 (patch)
tree9bcee2e173961583d882718014b52c00d96ef185 /crates
parent95abe342ac041eee529d756888ddf568660e3fca (diff)
Blocking client
Diffstat (limited to 'crates')
-rw-r--r--crates/teleia/src/fig.rs22
-rw-r--r--crates/teleia/src/framebuffer.rs10
2 files changed, 29 insertions, 3 deletions
diff --git a/crates/teleia/src/fig.rs b/crates/teleia/src/fig.rs
index e12a24c..bb5d579 100644
--- a/crates/teleia/src/fig.rs
+++ b/crates/teleia/src/fig.rs
@@ -70,20 +70,36 @@ impl Default for BinaryClientState {
}
pub struct BinaryClient {
state: BinaryClientState,
+ writer: std::net::TcpStream,
reader: std::io::BufReader<std::net::TcpStream>,
}
impl BinaryClient {
- pub fn new(addr: &str, subs: &[&[u8]]) -> Self {
+ pub fn new(addr: &str, blocking: bool, subs: &[&[u8]]) -> Self {
let mut socket = std::net::TcpStream::connect(addr).expect("failed to connect to message bus");
- socket.set_nonblocking(true).expect("failed to set message bus socket nonblocking");
+ socket.set_nonblocking(!blocking).expect("failed to set message bus socket nonblocking");
for s in subs {
write!(socket, "s").expect("failed to send subscribe message to bus");
socket.write_u32::<byteorder::LE>(s.len() as u32).expect("failed to send subscribe message length to bus");
socket.write_all(s).expect("failed to send subscribe message to bus");
}
socket.flush().expect("failed to flush bus connection");
+ let writer = socket.try_clone().expect("failed to clone socket");
let reader = std::io::BufReader::new(socket);
- Self { state: BinaryClientState::PartialEventLength { buf_len: 0, buf: [0; 4] }, reader }
+ Self {
+ state: BinaryClientState::PartialEventLength { buf_len: 0, buf: [0; 4] },
+ writer,
+ reader,
+ }
+ }
+ fn write_length_prefixed(&mut self, buf: &[u8]) {
+ self.writer.write_u32::<byteorder::LE>(buf.len() as u32).expect("failed to send message");
+ self.writer.write_all(buf).expect("failed to send message");
+
+ }
+ pub fn publish(&mut self, ev: &[u8], data: &[u8]) {
+ write!(self.writer, "p").expect("failed to send publish message to bus");
+ self.write_length_prefixed(ev);
+ self.write_length_prefixed(data);
}
fn read(reader: &mut std::io::BufReader<std::net::TcpStream>, buf: &mut [u8]) -> Option<usize> {
match reader.read(buf) {
diff --git a/crates/teleia/src/framebuffer.rs b/crates/teleia/src/framebuffer.rs
index 3542b0f..f382611 100644
--- a/crates/teleia/src/framebuffer.rs
+++ b/crates/teleia/src/framebuffer.rs
@@ -143,4 +143,14 @@ impl Framebuffer {
}
}
}
+
+ pub fn get_pixels_raw(&self, ctx: &context::Context, buf: &mut [u8]) {
+ unsafe {
+ ctx.gl.bind_texture(glow::TEXTURE_2D, self.tex);
+ ctx.gl.get_tex_image(
+ glow::TEXTURE_2D, 0, glow::RGBA, glow::UNSIGNED_BYTE,
+ glow::PixelPackData::Slice(buf),
+ );
+ }
+ }
}