Skip to main content

NetSocket

Struct NetSocket 

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

Net socket wrapper with optimized settings.

Implementations§

Source§

impl NetSocket

Source

pub async fn new(bind_addr: SocketAddr) -> Result<Self>

Create a new Net socket bound to the given address with default (production) buffer sizes.

Source

pub async fn with_config( bind_addr: SocketAddr, config: SocketBufferConfig, ) -> Result<Self>

Create a new Net socket with custom buffer configuration.

Source

pub fn from_socket(socket: UdpSocket) -> Result<Self>

Create from an existing tokio UdpSocket

Source

pub fn local_addr(&self) -> SocketAddr

Get the local address

Source

pub fn socket(&self) -> &UdpSocket

Get a reference to the underlying socket

Source

pub fn socket_arc(&self) -> Arc<UdpSocket>

Get a clone of the Arc socket

Source

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

Connect to a remote address (for send/recv without address)

Source

pub async fn send_to(&self, packet: &[u8], target: SocketAddr) -> Result<usize>

Send a packet to a specific address

Source

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

Send a packet to the connected address

Source

pub async fn recv_from(&mut self) -> Result<(Bytes, SocketAddr)>

Receive a packet, returning the data and source address.

Routes through tokio’s recv_buf_from(&mut BufMut) for the same reason as PacketReceiver::recv (crypto-session perf #130): the legacy resize(MAX_PACKET_SIZE, 0) + recv_from(&mut [u8]) shape memset ~1500 bytes per packet only for the kernel to overwrite them on the next syscall. recv_buf_from writes directly into the BytesMut’s spare capacity, so the kernel’s bytes are the first writers and no pre-init is needed.

Source

pub async fn recv(&mut self) -> Result<Bytes>

Receive a packet from the connected address.

Routes through tokio’s recv_buf(&mut BufMut) for the same reason as Self::recv_from — see that method’s docs.

Source

pub fn try_recv_from(&mut self) -> Result<Option<(Bytes, SocketAddr)>>

Try to receive a packet without blocking.

Routes through tokio’s try_recv_buf_from(&mut BufMut) for the same reason as Self::recv_from — see that method’s docs.

Trait Implementations§

Source§

impl Debug for NetSocket

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more