mirror of
https://github.com/bspeice/aeron-rs
synced 2024-12-22 05:48:10 -05:00
Finally able to terminate a driver.
Need to write a test for it, but it's working locally.
This commit is contained in:
parent
143e21bf0a
commit
f4c2fcf0c5
@ -6,6 +6,7 @@ use aeron_rs::util::IndexT;
|
|||||||
use memmap::MmapOptions;
|
use memmap::MmapOptions;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
use aeron_rs::client::cnc_descriptor;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let path = ClientContext::default_aeron_path();
|
let path = ClientContext::default_aeron_path();
|
||||||
@ -22,8 +23,8 @@ fn main() {
|
|||||||
println!("MMap len: {}", mmap.len());
|
println!("MMap len: {}", mmap.len());
|
||||||
|
|
||||||
// When creating the buffer, we need to offset by the CnC metadata
|
// When creating the buffer, we need to offset by the CnC metadata
|
||||||
let cnc_metadata_len = size_of::<MetaDataDefinition>();
|
let cnc_metadata_len = cnc_descriptor::META_DATA_LENGTH;
|
||||||
println!("Buffer len: {}", mmap[cnc_metadata_len..].len());
|
println!("Buffer start: {}", cnc_metadata_len);
|
||||||
|
|
||||||
// Read metadata to get buffer length
|
// Read metadata to get buffer length
|
||||||
let buffer_len = {
|
let buffer_len = {
|
||||||
@ -31,6 +32,7 @@ fn main() {
|
|||||||
let metadata = atomic_buffer.overlay::<MetaDataDefinition>(0).unwrap();
|
let metadata = atomic_buffer.overlay::<MetaDataDefinition>(0).unwrap();
|
||||||
metadata.to_driver_buffer_length
|
metadata.to_driver_buffer_length
|
||||||
};
|
};
|
||||||
|
println!("Buffer len: {}", buffer_len);
|
||||||
|
|
||||||
let buffer_end = cnc_metadata_len + buffer_len as usize;
|
let buffer_end = cnc_metadata_len + buffer_len as usize;
|
||||||
let atomic_buffer = AtomicBuffer::wrap(&mut mmap[cnc_metadata_len..buffer_end]);
|
let atomic_buffer = AtomicBuffer::wrap(&mut mmap[cnc_metadata_len..buffer_end]);
|
||||||
@ -43,6 +45,7 @@ fn main() {
|
|||||||
let mut source_buffer = AtomicBuffer::wrap(&mut terminate_bytes);
|
let mut source_buffer = AtomicBuffer::wrap(&mut terminate_bytes);
|
||||||
let client_id = ring_buffer.next_correlation_id();
|
let client_id = ring_buffer.next_correlation_id();
|
||||||
source_buffer.put_i64_ordered(0, client_id).unwrap();
|
source_buffer.put_i64_ordered(0, client_id).unwrap();
|
||||||
|
source_buffer.put_i64_ordered(8, -1).unwrap();
|
||||||
|
|
||||||
let term_id: i32 = 0x0E;
|
let term_id: i32 = 0x0E;
|
||||||
ring_buffer
|
ring_buffer
|
||||||
|
@ -19,6 +19,9 @@
|
|||||||
//! +-----------------------------+
|
//! +-----------------------------+
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
|
use crate::util::bit;
|
||||||
|
use std::mem::size_of;
|
||||||
|
|
||||||
/// The CnC file metadata header. Layout:
|
/// The CnC file metadata header. Layout:
|
||||||
///
|
///
|
||||||
/// ```text
|
/// ```text
|
||||||
@ -61,6 +64,10 @@ pub struct MetaDataDefinition {
|
|||||||
_pid: i64,
|
_pid: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Length of the metadata block in a CnC file. Note that it's not equivalent
|
||||||
|
/// to the actual struct length.
|
||||||
|
pub const META_DATA_LENGTH: usize = bit::align_usize(size_of::<MetaDataDefinition>(), bit::CACHE_LINE_LENGTH * 2);
|
||||||
|
|
||||||
/// Version code for the Aeron CnC file format
|
/// Version code for the Aeron CnC file format
|
||||||
pub const CNC_VERSION: i32 = crate::sematic_version_compose(0, 0, 16);
|
pub const CNC_VERSION: i32 = crate::sematic_version_compose(0, 0, 16);
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ use crate::util::{bit, AeronError, IndexT, Result};
|
|||||||
/// Description of the Ring Buffer schema.
|
/// Description of the Ring Buffer schema.
|
||||||
pub mod buffer_descriptor {
|
pub mod buffer_descriptor {
|
||||||
use crate::client::concurrent::atomic_buffer::AtomicBuffer;
|
use crate::client::concurrent::atomic_buffer::AtomicBuffer;
|
||||||
use crate::util::bit::is_power_of_two;
|
use crate::util::bit::{is_power_of_two, CACHE_LINE_LENGTH};
|
||||||
use crate::util::AeronError::IllegalArgument;
|
use crate::util::AeronError::IllegalArgument;
|
||||||
use crate::util::{IndexT, Result, CACHE_LINE_LENGTH};
|
use crate::util::{IndexT, Result};
|
||||||
|
|
||||||
// QUESTION: Why are these offsets so large when we only ever use i64 types?
|
// QUESTION: Why are these offsets so large when we only ever use i64 types?
|
||||||
|
|
||||||
|
11
src/util.rs
11
src/util.rs
@ -6,9 +6,6 @@
|
|||||||
// QUESTION: Can this just be updated to be `usize` in Rust?
|
// QUESTION: Can this just be updated to be `usize` in Rust?
|
||||||
pub type IndexT = i32;
|
pub type IndexT = i32;
|
||||||
|
|
||||||
/// Length of the data blocks used by the CPU cache sub-system in bytes
|
|
||||||
pub const CACHE_LINE_LENGTH: usize = 64;
|
|
||||||
|
|
||||||
/// Error types from operations in the Aeron client. Synonymous with the exceptions
|
/// Error types from operations in the Aeron client. Synonymous with the exceptions
|
||||||
/// generated by the C++ client.
|
/// generated by the C++ client.
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@ -29,6 +26,9 @@ pub mod bit {
|
|||||||
use crate::util::IndexT;
|
use crate::util::IndexT;
|
||||||
use num::PrimInt;
|
use num::PrimInt;
|
||||||
|
|
||||||
|
/// Length of the data blocks used by the CPU cache sub-system in bytes
|
||||||
|
pub const CACHE_LINE_LENGTH: usize = 64;
|
||||||
|
|
||||||
/// Helper method for quick verification that `IndexT` is a positive power of two
|
/// Helper method for quick verification that `IndexT` is a positive power of two
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
@ -56,4 +56,9 @@ pub mod bit {
|
|||||||
{
|
{
|
||||||
(val + (alignment - T::one())) & !(alignment - T::one())
|
(val + (alignment - T::one())) & !(alignment - T::one())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Align a `usize` value. See `align` for similar functionality on general types.
|
||||||
|
pub const fn align_usize(val: usize, alignment: usize) -> usize {
|
||||||
|
(val + (alignment - 1)) & !(alignment - 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user