Skip to content

Commit

Permalink
fix sizeof usize assumed to be 8 (#143)
Browse files Browse the repository at this point in the history
closes #141
  • Loading branch information
feschber committed Jun 8, 2024
1 parent 5fd3b71 commit 460baca
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ once_cell = "1.19.0"
num_enum = "0.7.2"
hostname = "0.4.0"
slab = "0.4.9"
endi = "1.1.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2.148"
Expand Down
9 changes: 4 additions & 5 deletions src/frontend/gtk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::{
use crate::frontend::{gtk::window::Window, FrontendRequest};

use adw::Application;
use endi::{Endian, ReadBytes};
use gtk::{
gdk::Display, glib::clone, prelude::*, subclass::prelude::ObjectSubclassIsExt, IconTheme,
};
Expand Down Expand Up @@ -85,16 +86,14 @@ fn build_ui(app: &Application) {
gio::spawn_blocking(move || {
match loop {
// read length
let mut len = [0u8; 8];
match rx.read_exact(&mut len) {
Ok(_) => (),
let len = match rx.read_u64(Endian::Big) {
Ok(l) => l,
Err(e) if e.kind() == ErrorKind::UnexpectedEof => break Ok(()),
Err(e) => break Err(e),
};
let len = usize::from_be_bytes(len);

// read payload
let mut buf = vec![0u8; len];
let mut buf = vec![0u8; len as usize];
match rx.read_exact(&mut buf) {
Ok(_) => (),
Err(e) if e.kind() == ErrorKind::UnexpectedEof => break Ok(()),
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/gtk/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::net::TcpStream;

use adw::prelude::*;
use adw::subclass::prelude::*;
use endi::{Endian, WriteBytes};
use glib::{clone, Object};
use gtk::{
gio,
Expand Down Expand Up @@ -265,8 +266,7 @@ impl Window {
let mut stream = self.imp().stream.borrow_mut();
let stream = stream.as_mut().unwrap();
let bytes = json.as_bytes();
let len = bytes.len().to_be_bytes();
if let Err(e) = stream.write(&len) {
if let Err(e) = stream.write_u64(Endian::Big, bytes.len() as u64) {
log::error!("error sending message: {e}");
};
if let Err(e) = stream.write(bytes) {
Expand Down

0 comments on commit 460baca

Please sign in to comment.