Skip to content

Commit

Permalink
[eclipse-iceoryx#361] Add timeout to zero copy connection and dynamic…
Browse files Browse the repository at this point in the history
… storage
  • Loading branch information
elfenpiff committed Aug 29, 2024
1 parent 70872c1 commit 0210700
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion iceoryx2-cal/src/zero_copy_connection/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub mod details {
max_borrowed_samples: usize,
sample_size: usize,
number_of_samples: usize,
timeout: Duration,
config: Configuration<Storage>,
}

Expand All @@ -238,6 +239,7 @@ pub mod details {
Storage,
>>::new(&self.name)
.config(&dynamic_storage_config)
.timeout(self.timeout)
.supplementary_size(supplementary_size)
.initializer(|data, allocator| {
fatal_panic!(from self, when unsafe { data.submission_channel.init(allocator) },
Expand Down Expand Up @@ -274,8 +276,14 @@ pub mod details {
fail!(from self, with ZeroCopyCreationError::VersionMismatch,
"{} since the version of the connection does not match.", msg);
}
Err(DynamicStorageOpenOrCreateError::DynamicStorageOpenError(
DynamicStorageOpenError::InitializationNotYetFinalized,
)) => {
fail!(from self, with ZeroCopyCreationError::InitializationNotYetFinalized,
"{} since the initialization of the zero copy connection is not finalized.", msg);
}
Err(e) => {
fail!(from self, with ZeroCopyCreationError::VersionMismatch,
fail!(from self, with ZeroCopyCreationError::InternalError,
"{} due to an internal failure ({:?}).", msg, e);
}
};
Expand Down Expand Up @@ -364,6 +372,7 @@ pub mod details {
sample_size: 0,
number_of_samples: 0,
config: Configuration::default(),
timeout: Duration::ZERO,
}
}

Expand All @@ -381,6 +390,11 @@ pub mod details {
self
}

fn timeout(mut self, value: Duration) -> Self {
self.timeout = value;
self
}

fn enable_safe_overflow(mut self, value: bool) -> Self {
self.enable_safe_overflow = value;
self
Expand Down
8 changes: 8 additions & 0 deletions iceoryx2-cal/src/zero_copy_connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod process_local;
pub mod used_chunk_list;

use std::fmt::Debug;
use std::time::Duration;

pub use crate::shared_memory::PointerOffset;
use crate::static_storage::file::{NamedConcept, NamedConceptBuilder, NamedConceptMgmt};
Expand All @@ -30,6 +31,7 @@ pub enum ZeroCopyCreationError {
VersionMismatch,
ConnectionMaybeCorrupted,
InvalidSampleSize,
InitializationNotYetFinalized,
IncompatibleBufferSize,
IncompatibleMaxBorrowedSampleSetting,
IncompatibleOverflowSetting,
Expand Down Expand Up @@ -108,6 +110,12 @@ pub trait ZeroCopyConnectionBuilder<C: ZeroCopyConnection>: NamedConceptBuilder<
fn enable_safe_overflow(self, value: bool) -> Self;
fn receiver_max_borrowed_samples(self, value: usize) -> Self;
fn number_of_samples(self, value: usize) -> Self;
/// The timeout defines how long the [`ZeroCopyConnectionBuilder`] should wait for
/// concurrent
/// [`ZeroCopyConnectionBuilder::create_sender()`] or
/// [`ZeroCopyConnectionBuilder::create_receiver()`] call to finalize its initialization.
/// By default it is set to [`Duration::ZERO`] for no timeout.
fn timeout(self, value: Duration) -> Self;

fn create_sender(self, sample_size: usize) -> Result<C::Sender, ZeroCopyCreationError>;
fn create_receiver(self, sample_size: usize) -> Result<C::Receiver, ZeroCopyCreationError>;
Expand Down
1 change: 1 addition & 0 deletions iceoryx2/src/port/details/publisher_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<Service: service::Service> Connection<Service> {
.receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples)
.enable_safe_overflow(this.static_config.enable_safe_overflow)
.number_of_samples(details.number_of_samples)
.timeout(this.service_state.shared_node.config().global.service.creation_timeout)
.create_receiver(this.static_config.message_type_details().sample_layout(details.max_slice_len).size()),
"{} since the zero copy connection could not be established.", msg);

Expand Down
1 change: 1 addition & 0 deletions iceoryx2/src/port/details/subscriber_connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl<Service: service::Service> Connection<Service> {
.receiver_max_borrowed_samples(this.static_config.subscriber_max_borrowed_samples)
.enable_safe_overflow(this.static_config.enable_safe_overflow)
.number_of_samples(number_of_samples)
.timeout(this.shared_node.config().global.service.creation_timeout)
.create_sender(this.static_config.message_type_details().sample_layout(max_slice_len).size()),
"{}.", msg);

Expand Down
1 change: 1 addition & 0 deletions iceoryx2/src/service/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ impl<ServiceType: service::Service> BuilderWithServiceType<ServiceType> {
>>::Builder<'_> as NamedConceptBuilder<
ServiceType::DynamicStorage,
>>::new(&self.service_config.service_id().0.into())
.timeout(self.shared_node.config().global.service.creation_timeout)
.config(&dynamic_config_storage_config::<ServiceType>(self.shared_node.config()))
.has_ownership(false)
.open(),
Expand Down

0 comments on commit 0210700

Please sign in to comment.