From 1fdf79af8b40fab1a491ca677b67a07a8d11c20a Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 22 Sep 2019 17:56:52 -0400 Subject: [PATCH] Start work on the client context --- Cargo.toml | 4 +++- README.md | 6 ++++- aeron_driver-sys/bindings.h | 1 + src/context.rs | 44 +++++++++++++++++++++++++++++++++++++ src/lib.rs | 4 +++- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/context.rs diff --git a/Cargo.toml b/Cargo.toml index c352206..c5b60c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,10 @@ edition = "2018" repository = "https://github.com/bspeice/aeron-rs" readme = "README.md" license = "Apache-2.0" + +[badges] travis-ci = { repository = "bspeice/aeron-rs", branch = "master" } maintenance = { status = "actively-developed" } [dependencies] -aeron_driver-sys = { path = "./aeron_driver-sys" } \ No newline at end of file +aeron_driver-sys = { path = "./aeron_driver-sys" } diff --git a/README.md b/README.md index ab2fe79..a9f83ae 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,8 @@ ![](https://img.shields.io/travis/bspeice/aeron-rs?style=flat-square) -A Rust port of the [Aeron client](https://github.com/real-logic/Aeron). \ No newline at end of file + + +[Aeron](https://github.com/real-logic/aeron) client for Rust + + diff --git a/aeron_driver-sys/bindings.h b/aeron_driver-sys/bindings.h index f9b4222..39072ee 100644 --- a/aeron_driver-sys/bindings.h +++ b/aeron_driver-sys/bindings.h @@ -1,2 +1,3 @@ #include +#include #include diff --git a/src/context.rs b/src/context.rs new file mode 100644 index 0000000..0c1e5a9 --- /dev/null +++ b/src/context.rs @@ -0,0 +1,44 @@ +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, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index d195ab8..966a11a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ -//! Aeron client for Rust +//! [Aeron](https://github.com/real-logic/aeron) client for Rust #![deny(missing_docs)] +mod context; + /// Retrieve the C library version in (major, minor, patch) format pub fn aeron_version() -> (u32, u32, u32) { unsafe {