Skip to content

Commit

Permalink
update to latest aeron and update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mimran1980 committed Jan 16, 2025
1 parent 0512333 commit e520d39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
4 changes: 2 additions & 2 deletions rusteron-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The **rusteron-client** module acts as a Rust wrapper around the Aeron C client
- **Publication**: Send messages to various Aeron channels.
- **Subscription**: Receive messages from Aeron channels.
- **Callbacks**: Handle events such as new publications, new subscriptions, and errors.
- **Automatic Resource Management**: Resources are automatically managed, except for handlers, which require manual management.
- **Automatic Resource Management (`new` method only)**: The wrappers attempt to automatically manage resources, specifically when using the `new` method. This includes calling the appropriate `xxx_init` method during initialization and automatically invoking `xxx_close` or `xxx_destroy` methods (if one exists) during cleanup. However, this management is partial. For other methods, such as `AeronArchive::set_aeron`, it is the developer's responsibility to ensure that the arguments remain valid and alive during their use. Proper resource management beyond initialization requires manual handling by the user to avoid undefined behavior or resource leaks.
- Updated methods with a single mutable out primitive to return `Result<primitive, AeronCError>`, enhancing usability and consistency by encapsulating return values and error handling.

## General Patterns
Expand All @@ -23,7 +23,7 @@ The **rusteron-client** module follows several general patterns to simplify the

- **Cloneable Wrappers**: All Rust wrappers in **rusteron-client** can be cloned, and they will refer to the same underlying Aeron C instance/resource. This allows you to use multiple references to the same object safely.
- **Mutable and Immutable Operations**: Modifications can be performed directly with `&self`, allowing flexibility without needing additional ownership complexities.
- **Automatic Resource Management**: The wrappers attempt to automatically manage resources, clearing objects and calling the appropriate close, destroy, or remove methods when needed.
- **Automatic Resource Management (`new` method only)**: The wrappers attempt to automatically manage resources, clearing objects and calling the appropriate close, destroy, or remove methods when needed.
- **Manual Handler Management**: Callbacks and handlers require manual management. Handlers are passed into the C bindings using `Handlers::leak(xxx)`, and need to be explicitly released by calling `release()`. This manual process is required due to the complexity of determining when these handlers should be cleaned up once handed off to C.

## Handlers and Callbacks
Expand Down
32 changes: 17 additions & 15 deletions rusteron-media-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,30 @@ impl AeronDriver {
/// if you have existing shm files and its before the driver timeout it will try to reuse it and fail
/// this makes sure that if that is the case it will wait else it proceeds
pub fn wait_for_previous_media_driver_to_timeout(aeron_context: &AeronDriverContext) {
let cnc_file = Path::new(aeron_context.get_dir()).join("cnc.dat");
if !aeron_context.get_dir_delete_on_start() {
let cnc_file = Path::new(aeron_context.get_dir()).join("cnc.dat");

if cnc_file.exists() {
let timeout =
Duration::from_millis(aeron_context.get_driver_timeout_ms() * 2).as_nanos() as i64;
if cnc_file.exists() {
let timeout = Duration::from_millis(aeron_context.get_driver_timeout_ms() * 2)
.as_nanos() as i64;

let mut duration = timeout;
let mut duration = timeout;

if let Ok(md) = cnc_file.metadata() {
if let Ok(modified_time) = md.modified() {
if let Ok(took) = modified_time.elapsed() {
duration = took.as_nanos() as i64;
if let Ok(md) = cnc_file.metadata() {
if let Ok(modified_time) = md.modified() {
if let Ok(took) = modified_time.elapsed() {
duration = took.as_nanos() as i64;
}
}
}
}

let delay = timeout - duration;
let delay = timeout - duration;

if delay > 0 {
let sleep_duration = Duration::from_nanos((delay + 1_000_000) as u64);
info!("cnc file already exists, will need to wait {sleep_duration:?} for timeout [file={cnc_file:?}]");
sleep(sleep_duration);
if delay > 0 {
let sleep_duration = Duration::from_nanos((delay + 1_000_000) as u64);
info!("cnc file already exists, will need to wait {sleep_duration:?} for timeout [file={cnc_file:?}]");
sleep(sleep_duration);
}
}
}
}
Expand Down

0 comments on commit e520d39

Please sign in to comment.