Socket

Trait Socket 

Source
pub trait Socket:
    Send
    + Sync
    + 'static {
    // Required methods
    fn send(&self, packet: &Packet) -> Result<(), Box<dyn Error>>;
    fn send_to(
        &self,
        packet: &Packet,
        to: &SocketAddr,
    ) -> Result<(), Box<dyn Error>>;
    fn recv_with_size(&self, size: usize) -> Result<Packet, Box<dyn Error>>;
    fn recv_from_with_size(
        &self,
        size: usize,
    ) -> Result<(Packet, SocketAddr), Box<dyn Error>>;
    fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>;
    fn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>;
    fn set_write_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>;
    fn set_nonblocking(
        &mut self,
        nonblocking: bool,
    ) -> Result<(), Box<dyn Error>>;

    // Provided methods
    fn recv(&self) -> Result<Packet, Box<dyn Error>> { ... }
    fn recv_from(&self) -> Result<(Packet, SocketAddr), Box<dyn Error>> { ... }
}
Expand description

Socket trait is used to allow building custom sockets to be used for TFTP communication.

Required Methods§

Source

fn send(&self, packet: &Packet) -> Result<(), Box<dyn Error>>

Sends a Packet to the socket’s connected remote Socket.

Source

fn send_to( &self, packet: &Packet, to: &SocketAddr, ) -> Result<(), Box<dyn Error>>

Sends a Packet to the specified remote Socket.

Source

fn recv_with_size(&self, size: usize) -> Result<Packet, Box<dyn Error>>

Receives a data packet from the socket’s connected remote, and returns the parsed Packet. The received packet can actually be of any type, however, this function also allows supplying the buffer size for an incoming request.

Source

fn recv_from_with_size( &self, size: usize, ) -> Result<(Packet, SocketAddr), Box<dyn Error>>

Receives a data packet from any incoming remote request, and returns the parsed Packet and the requesting SocketAddr. The received packet can actually be of any type, however, this function also allows supplying the buffer size for an incoming request.

Source

fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>

Returns the remote SocketAddr if it exists.

Source

fn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Sets the read timeout for the Socket.

Source

fn set_write_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Sets the write timeout for the Socket.

Source

fn set_nonblocking(&mut self, nonblocking: bool) -> Result<(), Box<dyn Error>>

Sets the Socket as blocking or not.

Provided Methods§

Source

fn recv(&self) -> Result<Packet, Box<dyn Error>>

Receives a Packet from the socket’s connected remote Socket. This function cannot handle large data packets due to the limited buffer size, so it is intended for only accepting incoming requests. For handling data packets, see Socket::recv_with_size().

Source

fn recv_from(&self) -> Result<(Packet, SocketAddr), Box<dyn Error>>

Receives a Packet from any remote Socket and returns the SocketAddr of the remote Socket. This function cannot handle large data packets due to the limited buffer size, so it is intended for only accepting incoming requests. For handling data packets, see Socket::recv_from_with_size().

Implementations on Foreign Types§

Source§

impl Socket for UdpSocket

Source§

fn send(&self, packet: &Packet) -> Result<(), Box<dyn Error>>

Source§

fn send_to( &self, packet: &Packet, to: &SocketAddr, ) -> Result<(), Box<dyn Error>>

Source§

fn recv_with_size(&self, size: usize) -> Result<Packet, Box<dyn Error>>

Source§

fn recv_from_with_size( &self, size: usize, ) -> Result<(Packet, SocketAddr), Box<dyn Error>>

Source§

fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>

Source§

fn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Source§

fn set_write_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Source§

fn set_nonblocking(&mut self, nonblocking: bool) -> Result<(), Box<dyn Error>>

Source§

impl<T: Socket + ?Sized> Socket for Box<T>

Source§

fn send(&self, packet: &Packet) -> Result<(), Box<dyn Error>>

Source§

fn send_to( &self, packet: &Packet, to: &SocketAddr, ) -> Result<(), Box<dyn Error>>

Source§

fn recv_with_size(&self, size: usize) -> Result<Packet, Box<dyn Error>>

Source§

fn recv_from_with_size( &self, size: usize, ) -> Result<(Packet, SocketAddr), Box<dyn Error>>

Source§

fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>

Source§

fn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Source§

fn set_write_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>

Source§

fn set_nonblocking(&mut self, nonblocking: bool) -> Result<(), Box<dyn Error>>

Implementors§