Trait gdbstub::conn::Connection

source ·
pub trait Connection {
    type Error;

    // Required methods
    fn write(&mut self, byte: u8) -> Result<(), Self::Error>;
    fn flush(&mut self) -> Result<(), Self::Error>;

    // Provided methods
    fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { ... }
    fn on_session_start(&mut self) -> Result<(), Self::Error> { ... }
}
Expand description

A trait to perform in-order, serial, byte-wise I/O.

When the std feature is enabled, this trait is automatically implemented for TcpStream and UnixStream (on unix systems).

Required Associated Types§

source

type Error

Transport-specific error type.

Required Methods§

source

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

Write a single byte.

source

fn flush(&mut self) -> Result<(), Self::Error>

Flush this Connection, ensuring that all intermediately buffered contents reach their destination.

Note: Not all Connections have internal buffering (e.g: writing data to a UART TX register with FIFOs disabled). In these cases, it’s fine to simply return Ok(()).

Provided Methods§

source

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write the entire buffer, blocking until complete.

This method’s default implementation calls self.write() on each byte in the buffer. This can be quite inefficient, so if a more efficient implementation exists (such as calling write_all() on an underlying std::io::Write object), this method should be overwritten.

source

fn on_session_start(&mut self) -> Result<(), Self::Error>

Called at the start of a debugging session before any GDB packets have been sent/received.

This method’s default implementation is a no-op.

Example

The on_session_start implementation for TcpStream ensures that set_nodelay(true) is called. The GDB remote serial protocol requires sending/receiving many small packets, so forgetting to enable TCP_NODELAY can result in a massively degraded debugging experience.

Trait Implementations§

source§

impl<E> Connection for &mut dyn Connection<Error = E>

§

type Error = E

Transport-specific error type.
source§

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

Write a single byte.
source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write the entire buffer, blocking until complete. Read more
source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush this Connection, ensuring that all intermediately buffered contents reach their destination. Read more
source§

fn on_session_start(&mut self) -> Result<(), Self::Error>

Called at the start of a debugging session before any GDB packets have been sent/received. Read more
source§

impl<E> Connection for Box<dyn Connection<Error = E>>

§

type Error = E

Transport-specific error type.
source§

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

Write a single byte.
source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

Write the entire buffer, blocking until complete. Read more
source§

fn flush(&mut self) -> Result<(), Self::Error>

Flush this Connection, ensuring that all intermediately buffered contents reach their destination. Read more
source§

fn on_session_start(&mut self) -> Result<(), Self::Error>

Called at the start of a debugging session before any GDB packets have been sent/received. Read more

Implementations on Foreign Types§

source§

impl<E> Connection for Box<dyn ConnectionExt<Error = E>>

§

type Error = E

source§

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

fn on_session_start(&mut self) -> Result<(), Self::Error>

source§

impl Connection for TcpStream

§

type Error = Error

source§

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

fn on_session_start(&mut self) -> Result<(), Self::Error>

source§

impl<E> Connection for Box<dyn Connection<Error = E>>

§

type Error = E

source§

fn write(&mut self, byte: u8) -> Result<(), Self::Error>

source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error>

source§

fn flush(&mut self) -> Result<(), Self::Error>

source§

fn on_session_start(&mut self) -> Result<(), Self::Error>

Implementors§

source§

impl<E> Connection for &mut dyn Connection<Error = E>

§

type Error = E

source§

impl<E> Connection for &mut dyn ConnectionExt<Error = E>

§

type Error = E