mirror of
https://github.com/bspeice/aeron-rs
synced 2024-12-22 05:48:10 -05:00
Start reading the CnC file
This commit is contained in:
parent
4085574b91
commit
27a8ce0dd4
@ -13,6 +13,7 @@ maintenance = { status = "actively-developed" }
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
aeron_driver-sys = { path = "./aeron_driver-sys" }
|
aeron_driver-sys = { path = "./aeron_driver-sys" }
|
||||||
|
memmap = "0.7"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
clap = "2.33"
|
clap = "2.33"
|
||||||
|
92
src/client/cnc_descriptor.rs
Normal file
92
src/client/cnc_descriptor.rs
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
//! Description of the command and control file used to communicate between the Media Driver
|
||||||
|
//! and its clients.
|
||||||
|
//!
|
||||||
|
//! File layout:
|
||||||
|
//!
|
||||||
|
//! ```text
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | Meta Data |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | to-driver Buffer |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | to-clients Buffer |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | Counters Metadata Buffer |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | Counters Values Buffer |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! | Error Log |
|
||||||
|
//! +-----------------------------+
|
||||||
|
//! ```
|
||||||
|
|
||||||
|
/// The CnC file metadata header. Layout:
|
||||||
|
///
|
||||||
|
/// ```text
|
||||||
|
/// 0 1 2 3
|
||||||
|
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
|
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
/// | Aeron CnC Version |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | to-driver buffer length |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | to-clients buffer length |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Counters Metadata buffer length |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Counters Values buffer length |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Error Log buffer length |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Client Liveness Timeout |
|
||||||
|
/// | |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Driver Start Timestamp |
|
||||||
|
/// | |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// | Driver PID |
|
||||||
|
/// | |
|
||||||
|
/// +---------------------------------------------------------------+
|
||||||
|
/// ```
|
||||||
|
#[repr(C, align(4))]
|
||||||
|
pub struct MetaDataDefinition {
|
||||||
|
cnc_version: i32,
|
||||||
|
_to_driver_buffer_length: i32,
|
||||||
|
_to_client_buffer_length: i32,
|
||||||
|
_counter_metadata_buffer_length: i32,
|
||||||
|
_counter_values_buffer_length: i32,
|
||||||
|
_error_log_buffer_length: i32,
|
||||||
|
_client_liveness_timeout: i64,
|
||||||
|
_start_timestamp: i64,
|
||||||
|
_pid: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::client::cnc_descriptor::MetaDataDefinition;
|
||||||
|
use crate::driver::{DriverContext, MediaDriver};
|
||||||
|
use memmap::MmapOptions;
|
||||||
|
use std::fs::File;
|
||||||
|
use tempfile::tempdir;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn read_cnc_version() {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let dir_path = dir.as_ref().to_path_buf();
|
||||||
|
dir.close().unwrap();
|
||||||
|
|
||||||
|
let context = DriverContext::default().set_aeron_dir(&dir_path);
|
||||||
|
let _driver = MediaDriver::with_context(context).unwrap();
|
||||||
|
|
||||||
|
// Open the CnC location
|
||||||
|
let cnc_path = dir_path.join("cnc.dat");
|
||||||
|
let cnc_file = File::open(&cnc_path).expect("Unable to open CnC file");
|
||||||
|
let mmap = unsafe {
|
||||||
|
MmapOptions::default()
|
||||||
|
.map(&cnc_file)
|
||||||
|
.expect("Unable to memory map CnC file")
|
||||||
|
};
|
||||||
|
|
||||||
|
let metadata: &MetaDataDefinition = unsafe { &*(mmap.as_ptr().cast()) };
|
||||||
|
assert_eq!(metadata.cnc_version, 16);
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ use std::path::PathBuf;
|
|||||||
|
|
||||||
/// Context used to initialize the Aeron client
|
/// Context used to initialize the Aeron client
|
||||||
pub struct ClientContext {
|
pub struct ClientContext {
|
||||||
aeron_dir: PathBuf,
|
_aeron_dir: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientContext {
|
impl ClientContext {
|
||||||
@ -31,7 +31,7 @@ impl ClientContext {
|
|||||||
impl Default for ClientContext {
|
impl Default for ClientContext {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ClientContext {
|
ClientContext {
|
||||||
aeron_dir: ClientContext::default_aeron_path(),
|
_aeron_dir: ClientContext::default_aeron_path(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
5
src/client/mod.rs
Normal file
5
src/client/mod.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
//! Aeron client
|
||||||
|
//!
|
||||||
|
//! These are the modules necessary to construct a functioning Aeron client
|
||||||
|
pub mod cnc_descriptor;
|
||||||
|
pub mod context;
|
Loading…
Reference in New Issue
Block a user