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§
Sourcefn recv_with_size(&self, size: usize) -> Result<Packet, Box<dyn Error>>
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.
Sourcefn recv_from_with_size(
&self,
size: usize,
) -> Result<(Packet, SocketAddr), Box<dyn Error>>
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.
Sourcefn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>
fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>
Returns the remote SocketAddr if it exists.
Sourcefn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>
fn set_read_timeout(&mut self, dur: Duration) -> Result<(), Box<dyn Error>>
Sets the read timeout for the Socket.
Provided Methods§
Sourcefn recv(&self) -> Result<Packet, Box<dyn Error>>
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().
Sourcefn recv_from(&self) -> Result<(Packet, SocketAddr), Box<dyn Error>>
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().