Skip to content

Commit

Permalink
Made it compile using unsafe call to borrow_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
rrasmuss4200 committed Sep 5, 2024
1 parent 4205af3 commit 285741d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ex3_obc_fsw/cmd_dispatcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use nix::sys::socket::accept;
use nix::unistd::{read, write, close};
use nix::Error;
use strum::IntoEnumIterator;
use std::os::fd::{AsFd, RawFd, AsRawFd};
use std::os::fd::{AsRawFd, BorrowedFd};

use ipc::{IpcClient, IpcServer, IPC_BUFFER_SIZE};
use common::component_ids::ComponentIds;
use message_structure::MsgHeaderNew;

const ARRAY_REPEAT_VALUE: Option<IpcClient> = None;

fn main() {
let component_streams: [Option<IpcClient>; ComponentIds::LAST as usize];
let mut component_streams: [Option<IpcClient>; ComponentIds::LAST as usize] = [ARRAY_REPEAT_VALUE; ComponentIds::LAST as usize];
for x in 0..(ComponentIds::LAST as usize) {
component_streams[x] = {
match ComponentIds::try_from(x as u8) {
Expand Down Expand Up @@ -67,7 +68,9 @@ fn main() {
Ok(payload) => {
match &component_streams[dest as usize] {
Some(client) => {
write(client.fd, &buffer)
unsafe {
write(BorrowedFd::borrow_raw(client.fd.as_raw_fd()), &buffer)
}
},
None => {
eprintln!("No payload: {payload}!");
Expand Down

0 comments on commit 285741d

Please sign in to comment.