mod shm;
use std::thread;
use std::time::Duration;
use shared_mem_queue::byte_queue::ByteQueue;
use shm::ShmHandle;
use libc::{O_CREAT, O_RDWR, O_TRUNC};
const SHM_RW_CR: &str = "shm_byte_queue";
const SHM_RW_CR_SIZE: usize = 128;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mode: libc::mode_t = 0o666;
let mut shm_handle =
ShmHandle::new(SHM_RW_CR, SHM_RW_CR_SIZE, O_CREAT | O_RDWR | O_TRUNC, mode)?;
let mut writer = unsafe { ByteQueue::create(shm_handle.as_mut_ptr_u8(), SHM_RW_CR_SIZE) };
let mut tx: [u8; 21] = [0; 21];
for (i, elem) in tx.iter_mut().enumerate() {
*elem = i as u8;
}
loop {
writer.write_blocking(&mut tx);
thread::sleep(Duration::from_secs(1));
tx[0] += 1;
}
}