FabricSocket

Struct FabricSocket 

Source
pub struct FabricSocket { /* private fields */ }
Expand description

A network socket bound to a leased fabric network interface.

Wraps a UDP socket with the bandwidth guarantee from the underlying NetLease. On native targets, delegates to std::net::UdpSocket.

§Example

use grafos_net::FabricSocket;
use grafos_std::net::NetBuilder;

let lease = NetBuilder::new().min_bandwidth(1_000_000_000).acquire()?;
let sock = FabricSocket::new(lease)?;
assert_eq!(sock.bandwidth(), 1_000_000_000);
assert_eq!(sock.interface_name(), "eth0");

Implementations§

Source§

impl FabricSocket

Source

pub fn new(lease: NetLease) -> Result<Self>

Create a new socket bound to the leased interface.

Binds to an ephemeral port on 0.0.0.0. The socket is associated with the given NetLease for lifetime tracking.

§Errors

Returns an I/O error if the bind fails.

Source

pub fn connect(addr: SocketAddr) -> Result<Self>

Create a connected socket using a default (zero-bandwidth) lease.

Acquires a network lease with no bandwidth constraint and connects to the given address.

§Errors

Returns an I/O error if lease acquisition or the connect fails.

§Example
use grafos_net::FabricSocket;
use std::net::SocketAddr;

let addr: SocketAddr = "127.0.0.1:9999".parse().unwrap();
let sock = FabricSocket::connect(addr)?;
assert!(sock.bandwidth() > 0);
Source

pub fn connect_with_bandwidth(addr: SocketAddr, min_bw: u64) -> Result<Self>

Create a connected socket with a minimum bandwidth guarantee.

Acquires a network lease with at least min_bw bits per second, then connects to the given address.

§Errors

Returns an I/O error if the bandwidth requirement cannot be met or if the connect fails.

§Example
use grafos_net::FabricSocket;
use std::net::SocketAddr;

let addr: SocketAddr = "127.0.0.1:9999".parse().unwrap();
let sock = FabricSocket::connect_with_bandwidth(addr, 1_000_000_000)?;
assert!(sock.bandwidth() >= 1_000_000_000);
Source

pub fn connect_to(&self, addr: SocketAddr) -> Result<()>

Connect this socket to a remote address.

After connecting, send and recv operate on the connected peer.

§Errors

Returns an I/O error if the connect fails.

Source

pub fn send(&self, data: &[u8]) -> Result<usize>

Send data through the socket.

The socket must be connected first via connect.

§Errors

Returns an I/O error if the send fails.

Source

pub fn recv(&self, buf: &mut [u8]) -> Result<usize>

Receive data from the socket.

The socket must be connected first via connect.

§Errors

Returns an I/O error if the recv fails.

Source

pub fn local_addr(&self) -> Result<SocketAddr>

Returns the local address this socket is bound to.

§Errors

Returns an I/O error if the address cannot be retrieved.

Source

pub fn bandwidth(&self) -> u64

Returns the guaranteed bandwidth in bits per second.

Source

pub fn interface_name(&self) -> &str

Returns the leased interface name.

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.