Finally able to terminate a driver.

Need to write a test for it, but it's working locally.
pull/6/head
Bradlee Speice 2019-10-06 21:37:38 -04:00
parent 143e21bf0a
commit f4c2fcf0c5
4 changed files with 22 additions and 7 deletions

View File

@ -6,6 +6,7 @@ use aeron_rs::util::IndexT;
use memmap::MmapOptions;
use std::fs::OpenOptions;
use std::mem::size_of;
use aeron_rs::client::cnc_descriptor;
fn main() {
let path = ClientContext::default_aeron_path();
@ -22,8 +23,8 @@ fn main() {
println!("MMap len: {}", mmap.len());
// When creating the buffer, we need to offset by the CnC metadata
let cnc_metadata_len = size_of::<MetaDataDefinition>();
println!("Buffer len: {}", mmap[cnc_metadata_len..].len());
let cnc_metadata_len = cnc_descriptor::META_DATA_LENGTH;
println!("Buffer start: {}", cnc_metadata_len);
// Read metadata to get buffer length
let buffer_len = {
@ -31,6 +32,7 @@ fn main() {
let metadata = atomic_buffer.overlay::<MetaDataDefinition>(0).unwrap();
metadata.to_driver_buffer_length
};
println!("Buffer len: {}", buffer_len);
let buffer_end = cnc_metadata_len + buffer_len as usize;
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 client_id = ring_buffer.next_correlation_id();
source_buffer.put_i64_ordered(0, client_id).unwrap();
source_buffer.put_i64_ordered(8, -1).unwrap();
let term_id: i32 = 0x0E;
ring_buffer

View File

@ -19,6 +19,9 @@
//! +-----------------------------+
//! ```
use crate::util::bit;
use std::mem::size_of;
/// The CnC file metadata header. Layout:
///
/// ```text
@ -61,6 +64,10 @@ pub struct MetaDataDefinition {
_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
pub const CNC_VERSION: i32 = crate::sematic_version_compose(0, 0, 16);

View File

@ -5,9 +5,9 @@ use crate::util::{bit, AeronError, IndexT, Result};
/// Description of the Ring Buffer schema.
pub mod buffer_descriptor {
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::{IndexT, Result, CACHE_LINE_LENGTH};
use crate::util::{IndexT, Result};
// QUESTION: Why are these offsets so large when we only ever use i64 types?

View File

@ -6,9 +6,6 @@
// QUESTION: Can this just be updated to be `usize` in Rust?
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
/// generated by the C++ client.
#[derive(Debug, PartialEq)]
@ -29,6 +26,9 @@ pub mod bit {
use crate::util::IndexT;
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
///
/// ```rust
@ -56,4 +56,9 @@ pub mod bit {
{
(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)
}
}