pub struct ServerSocket { /* private fields */ }Expand description
ServerSocket struct is used as an abstraction layer for a server
Socket. This struct is used for abstraction of single socket
communication.
§Example
use std::net::{SocketAddr, UdpSocket};
use std::str::FromStr;
use tftpd::{Socket, ServerSocket, Packet};
use std::time::Duration;
let socket = ServerSocket::new(
UdpSocket::bind("127.0.0.1:0").unwrap(),
SocketAddr::from_str("127.0.0.1:50000").unwrap(),
Duration::from_secs(3)
);
socket.send(&Packet::Ack(1)).unwrap();Implementations§
Source§impl ServerSocket
impl ServerSocket
Sourcepub fn new(socket: UdpSocket, remote: SocketAddr, timeout: Duration) -> Self
pub fn new(socket: UdpSocket, remote: SocketAddr, timeout: Duration) -> Self
Creates a new ServerSocket from a UdpSocket and a remote SocketAddr.
Trait Implementations§
Source§impl Socket for ServerSocket
impl Socket for ServerSocket
Source§fn 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.Source§fn 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.Source§fn remote_addr(&self) -> Result<SocketAddr, Box<dyn Error>>
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>>
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>>
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>>
fn set_nonblocking(&mut self, nonblocking: bool) -> Result<(), Box<dyn Error>>
Sets the
Socket as blocking or not.Source§fn 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().Source§fn 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().Auto Trait Implementations§
impl !Freeze for ServerSocket
impl RefUnwindSafe for ServerSocket
impl Send for ServerSocket
impl Sync for ServerSocket
impl Unpin for ServerSocket
impl UnwindSafe for ServerSocket
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more