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: CancellationTokenCancelled 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: CancellationTokenCancelled once nothing takes the output anymore, see
SharedContainerAttach::stop_output.
listeners: Arc<Mutex<HashMap<PathBuf, AttachListener>>>The listening attach sockets by path.
Implementations§
Sourcepub(crate) fn new(terminal: bool) -> Self
pub(crate) fn new(terminal: bool) -> Self
Create a new shared container attach instance for a container with or without a terminal.
Sourcepub(crate) fn add(
&self,
socket_path: &Path,
token: CancellationToken,
stop_after_stdin_eof: bool,
) -> Result<()>
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.
Sourcepub(crate) async fn read(&self) -> Result<Bytes>
pub(crate) async fn read(&self) -> Result<Bytes>
Read from all attach endpoints standard input and return the first result.
Sourcepub(crate) fn try_read(&self) -> Result<Bytes>
pub(crate) fn try_read(&self) -> Result<Bytes>
Try to read from all attach endpoints standard input and return the first result.
Sourcepub(crate) async fn send_stdin(&self, data: Bytes)
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.
Sourcepub(crate) fn close_stdin(&self)
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.
Sourcepub(crate) fn write(&self, m: Message)
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.
Sourcepub(crate) fn output(&self) -> Arc<AttachOutput> ⓘ
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.
Sourcepub(crate) fn is_terminal(&self) -> bool
pub(crate) fn is_terminal(&self) -> bool
Whether the container has a terminal.
Sourcepub(crate) fn stop_output(&self)
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.
Sourcepub(crate) fn stop_output_on_exit(
&self,
exited: CancellationToken,
) -> StopOutput
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.
Sourcepub(crate) fn has_output(&self) -> bool
pub(crate) fn has_output(&self) -> bool
Whether an output got registered, which read loops did then.
Sourcepub(crate) fn output_stopped(&self) -> &CancellationToken
pub(crate) fn output_stopped(&self) -> &CancellationToken
The token cancelled by SharedContainerAttach::stop_output.
Sourcepub(crate) fn stdin_closed(&self) -> &CancellationToken
pub(crate) fn stdin_closed(&self) -> &CancellationToken
The token cancelled once an attach client closed the container stdin.
Sourcepub(crate) fn close_container_stdin(&self) -> bool
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.
Sourcefn remove_listener(&self, path: &Path, id: u64)
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.
Sourcepub(crate) fn subscribe(&self) -> (Receiver<Message>, bool)
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.
Sourcepub(crate) fn logging(&self) -> Logging<'_>
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.
Sourcepub(crate) fn is_logging(&self) -> bool
pub(crate) fn is_logging(&self) -> bool
Whether a read loop has output on its way into the log.
Sourcepub(crate) async fn wait_logged(&self)
pub(crate) async fn wait_logged(&self)
Wait until no read loop has output on its way into the log.
Trait Implementations§
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].