ServerSocket

Struct ServerSocket 

Source
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

Source

pub fn new(socket: UdpSocket, remote: SocketAddr, timeout: Duration) -> Self

Creates a new ServerSocket from a UdpSocket and a remote SocketAddr.

Source

pub fn sender(&self) -> Sender<Packet>

Returns a Sender for sending Packets to the remote Socket.

Trait Implementations§

Source§

impl Socket for ServerSocket

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.
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().

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.