Expand description
The attach sockets themselves: accepting the clients, reading their stdin and writing the output to them.
ConstantsΒ§
- DONE_
PACKET π - The packet indicating that weβre done writing.
- PACKET_
BUF_ πSIZE - The most data of an output packet, after its pipe byte. Like for conmon, CRI-O and the Go client read one byte more than this, so that a full read of a pipe goes out as one packet.
- STDIN_
PACKET_ πMAX_ SIZE - The maximum size of a stdin packet from an attach client, a larger one
gets truncated. The Go client writes at most 32 KiB at once, like CRI-O
does for conmon, plus the start of a detach key sequence which it held
back, a few bytes which the extra KiB leaves room for. The scratch buffer
of the thread keeps this size after the first stdin, see
with_scratch.
FunctionsΒ§
- accept_
connections π - Accept connections until the container exits, which cancels
token, or another listener replaces this one, which cancelsstop. - client_
gone π - Whether a send failed because the client closed its end. A client which leaves output unread gets the connection reset.
- create_
listener π - Listen on the attach socket at
path, unless a listener of this server does already. - hangup π
- Wait until the client closed the connection. Without output, a send never notices, and a client which only closed its write side still receives the output. The hangup gets reported by an epoll instance of its own, which watches the socket for nothing but the hangups and errors epoll always reports. Neither input nor output wakes it up, and its readiness is separate from the one of the socket, which the read and write loops use. If that fails, only a failing send ends the loop.
- input_
ended π - Check if no more input will arrive after a zero byte read. That is the case once the peer closed its write side, which a SOCK_SEQPACKET socket reports as POLLRDHUP, and no data is queued anymore. Checking the flag first makes sure that no data arrives in between.
- next_
message π - The next output message, bounded by the drain once the container exited. If the output did not end after the exit, the client gets the done packet anyway.
- read_
loop π - Forward the stdin of a client until it closes, the stdin of the
container got closed or the container exited, which cancels
token. - recv_
stdin π - Receive a stdin packet into the scratch buffer of the thread, see
with_scratch, and copy it out, so that a connection holds no buffer while it waits and the queued stdin only the data of the packets. Stdin is binary, null bytes are part of the data. Returns whether the packet got truncated as well. - send_
packet π - Send a packet, false if the client went away or does not take it in
time. A client which does not read keeps a send waiting, until it
hangs up or, once the container exited, for at most
DRAIN_MAX_WAIT. Each packet gets that long, so that a slow client still gets the output which was there already. - write_
loop π - Forward the container output of
attachto a client until the output ended or the client went away. Once the container exited, which cancelstoken, a process left behind may keep the output open, so forward only what arrives shortly after the exit, seeDrain::recv_attach.