Struct Connection

Source
pub struct Connection {
    pub buffer: BytesMut,
    pub session: Arc<dyn ClickHouseSession>,
    /* private fields */
}
Expand description

Send and receive Packet values from a remote peer.

When implementing networking protocols, a message on that protocol is often composed of several smaller messages known as frames. The purpose of Connection is to read and write frames on the underlying TcpStream.

To read frames, the Connection uses an internal buffer, which is filled up until there are enough bytes to create a full frame. Once this happens, the Connection creates the frame and returns it to the caller.

When sending frames, the frame is first encoded into the write buffer. The contents of the write buffer are then written to the socket.

Fields§

§buffer: BytesMut§session: Arc<dyn ClickHouseSession>

Implementations§

Source§

impl Connection

Source

pub fn new( stream: TcpStream, session: Arc<dyn ClickHouseSession>, timezone: String, ) -> Result<Connection>

Create a new Connection, backed by socket. Read and write buffers are initialized.

Source

pub async fn read_packet( &mut self, ctx: &mut CHContext, ) -> Result<Option<Packet>>

Read a single Packet value from the underlying stream.

The function waits until it has retrieved enough data to parse a frame. Any data remaining in the read buffer after the frame has been parsed is kept there for the next call to read_packet.

§Returns

On success, the received frame is returned. If the TcpStream is closed in a way that doesn’t break a frame in half, it returns None. Otherwise, an error is returned.

Source

pub async fn write_block(&mut self, block: &Block) -> Result<()>

Source

pub async fn write_progress( &mut self, progress: Progress, client_revision: u64, ) -> Result<()>

Source

pub async fn write_end_of_stream(&mut self) -> Result<()>

Source

pub async fn write_error(&mut self, err: &Error) -> Result<()>

Source

pub async fn write_bytes(&mut self, bytes: Vec<u8>) -> Result<()>

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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.