1
0
mirror of https://github.com/bspeice/aeron-rs synced 2024-12-22 05:48:10 -05:00

Clean up the client context a bit

We're not ready to make use of most of these options
This commit is contained in:
Bradlee Speice 2019-09-23 23:27:03 -04:00
parent 966db0767f
commit 941c18bf37
4 changed files with 49 additions and 55 deletions

37
src/client.rs Normal file
View File

@ -0,0 +1,37 @@
//! Client library for Aeron. This encapsulates the logic needed to communicate
//! with the media driver, but does not manage the media driver itself.
use std::env;
use std::path::PathBuf;
/// Context used to initialize the Aeron client
pub struct ClientContext {
aeron_dir: PathBuf,
}
impl ClientContext {
fn get_user_name() -> String {
env::var("USER")
.or_else(|_| env::var("USERNAME"))
.unwrap_or("default".to_string())
}
/// Get the default folder used by the Media Driver to interact with clients
pub fn default_aeron_path() -> PathBuf {
let base_path = if cfg!(target_os = "linux") {
PathBuf::from("/dev/shm")
} else {
// Uses TMPDIR on Unix-like and GetTempPath on Windows
env::temp_dir()
};
base_path.join(format!("aeron-{}", ClientContext::get_user_name()))
}
}
impl Default for ClientContext {
fn default() -> Self {
ClientContext {
aeron_dir: ClientContext::default_aeron_path(),
}
}
}

View File

@ -1,44 +0,0 @@
use std::env;
use std::path::PathBuf;
const DEFAULT_MEDIA_DRIVER_TIMEOUT_MS: u16 = 10_000;
const DEFAULT_RESOURCE_LINGER_MS: u16 = 5_000;
pub struct Context {
aeron_dir: PathBuf,
media_driver_timeout_ms: i32,
resource_linger_timeout_ms: i32,
use_conductor_agent_invoker: bool,
pre_touch_mapped_memory: bool,
}
impl Context {
pub fn get_user_name() -> String {
env::var("USER")
.or_else(|_| env::var("USERNAME"))
.unwrap_or("default".to_string())
}
pub fn default_aeron_path() -> PathBuf {
let base_path = if cfg!(target_os = "linux") {
PathBuf::from("/dev/shm")
} else {
// Uses TMPDIR on Unix-like, and GetTempPath on Windows
env::temp_dir()
};
base_path.join(format!("aeron-{}", Context::get_user_name()))
}
}
impl Default for Context {
fn default() -> Self {
Context {
aeron_dir: Context::default_aeron_path(),
media_driver_timeout_ms: DEFAULT_MEDIA_DRIVER_TIMEOUT_MS.into(),
resource_linger_timeout_ms: DEFAULT_RESOURCE_LINGER_MS.into(),
use_conductor_agent_invoker: false,
pre_touch_mapped_memory: false,
}
}
}

View File

@ -79,6 +79,17 @@ impl MediaDriver {
pub fn new() -> Result<Self, DriverError> { pub fn new() -> Result<Self, DriverError> {
Self::with_context(DriverContext::default()) Self::with_context(DriverContext::default())
} }
/// Retrieve the C library version in (major, minor, patch) format
pub fn driver_version() -> (u32, u32, u32) {
unsafe {
(
aeron_version_major() as u32,
aeron_version_minor() as u32,
aeron_version_patch() as u32,
)
}
}
} }
impl Drop for MediaDriver { impl Drop for MediaDriver {

View File

@ -1,15 +1,5 @@
//! [Aeron](https://github.com/real-logic/aeron) client for Rust //! [Aeron](https://github.com/real-logic/aeron) client for Rust
#![deny(missing_docs)] #![deny(missing_docs)]
pub mod client;
pub mod driver; pub mod driver;
/// Retrieve the C library version in (major, minor, patch) format
pub fn aeron_version() -> (u32, u32, u32) {
unsafe {
(
aeron_driver_sys::aeron_version_major() as u32,
aeron_driver_sys::aeron_version_minor() as u32,
aeron_driver_sys::aeron_version_patch() as u32,
)
}
}