Skip to main content

SharedContainerAttach

Struct SharedContainerAttach 

Source
pub(crate) struct SharedContainerAttach {
    read_half_rx: Receiver<Bytes>,
    read_half_tx: Sender<Bytes>,
    output: Arc<OutputState>,
    stdin_closed: CancellationToken,
    stop_after_stdin_eof: Arc<AtomicBool>,
    terminal: bool,
    output_stopped: CancellationToken,
    listeners: Arc<Mutex<HashMap<PathBuf, AttachListener>>>,
}
Expand description

A shared container attach abstraction.

Fields§

§read_half_rx: Receiver<Bytes>§read_half_tx: Sender<Bytes>§output: Arc<OutputState>

The output towards the attach clients.

§stdin_closed: CancellationToken

Cancelled once a client with stop_after_stdin_eof closed its stdin, which closes the stdin of the container for good. It is separate from the token of the container, which only the exit may cancel.

§stop_after_stdin_eof: Arc<AtomicBool>§terminal: bool§output_stopped: CancellationToken

Cancelled once nothing takes the output anymore, see SharedContainerAttach::stop_output.

§listeners: Arc<Mutex<HashMap<PathBuf, AttachListener>>>

The listening attach sockets by path.

Implementations§

Source§

impl SharedContainerAttach

Source

pub(crate) fn new(terminal: bool) -> Self

Create a new shared container attach instance for a container with or without a terminal.

Source

pub(crate) fn add( &self, socket_path: &Path, token: CancellationToken, stop_after_stdin_eof: bool, ) -> Result<()>

Add a new attach endpoint to this shared container attach instance. The token of the container stops it on exit.

Source

pub(crate) async fn read(&self) -> Result<Bytes>

Read from all attach endpoints standard input and return the first result.

Source

pub(crate) fn try_read(&self) -> Result<Bytes>

Try to read from all attach endpoints standard input and return the first result.

Source

pub(crate) async fn send_stdin(&self, data: Bytes)

Send data to the container stdin. This waits while the container does not keep up, and drops the data once nothing reads the stdin anymore.

Source

pub(crate) fn close_stdin(&self)

Close the stdin channel once nothing reads it anymore, so that senders stop waiting for it. Queued data can still be read.

Source

pub(crate) fn write(&self, m: Message)

Write a buffer to all attach endpoints. Sending fails only if the last client went away meanwhile, which is no reason to stop the output.

Source

pub(crate) fn output(&self) -> Arc<AttachOutput> ⓘ

Register the output of a container, which ends once the returned value and all of its clones got dropped. The attach endpoints get the done message only then, otherwise the done of one pipe could cut off the remaining output of another one.

Source

pub(crate) fn is_terminal(&self) -> bool

Whether the container has a terminal.

Source

pub(crate) fn stop_output(&self)

Stop reading the output once nothing takes it anymore, like once it got drained after the exit of the process. A process left behind which holds the pipes or the terminal open would keep the read loops going forever otherwise, and writing to the log after the exit file told that it is complete. Closing them lets its writes fail, like once conmon exited.

Source

pub(crate) fn stop_output_on_exit( &self, exited: CancellationToken, ) -> StopOutput

Stop the output once the consumer of an exec is done with it and the process exited, see StopOutput.

Source

pub(crate) fn has_output(&self) -> bool

Whether an output got registered, which read loops did then.

Source

pub(crate) fn output_stopped(&self) -> &CancellationToken

The token cancelled by SharedContainerAttach::stop_output.

Source

pub(crate) fn stdin_closed(&self) -> &CancellationToken

The token cancelled once an attach client closed the container stdin.

Source

pub(crate) fn close_container_stdin(&self) -> bool

Close the container stdin after an attach client reached EOF. Only that, the container token also drives the exit and OOM handling. A terminal cannot be closed without ending its output, so it stays open and this returns false.

Source

fn remove_listener(&self, path: &Path, id: u64)

Forget a listener which stopped on the exit or an error, and remove its socket if it is still at the path, unless another listener replaced it meanwhile. The caller keeps the listener open, so that the inode number of its socket is not reused yet.

Source

pub(crate) fn subscribe(&self) -> (Receiver<Message>, bool)

Subscribe to the container output sent to the attach endpoints. The returned flag is true if the output already ended, then the done message may have been sent before subscribing and the receiver only gets what is still queued.

Source

pub(crate) fn logging(&self) -> Logging<'_>

Mark output which a read loop got as on its way into the log, until the returned guard gets dropped once the output got broadcast. A slow log driver delays the output, which is no pause of it, see SharedContainerAttach::wait_logged.

Source

pub(crate) fn is_logging(&self) -> bool

Whether a read loop has output on its way into the log.

Source

pub(crate) async fn wait_logged(&self)

Wait until no read loop has output on its way into the log.

Trait Implementations§

Source§

impl Clone for SharedContainerAttach

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SharedContainerAttach

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SharedContainerAttach

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more