UdpSocket

Struct UdpSocket 

Source
pub struct UdpSocket {
    local_addr: RwLock<Option<SocketAddress>>,
    remote_addr: RwLock<Option<SocketAddress>>,
    send_buffer: Mutex<Vec<Vec<u8>>>,
    recv_buffer: Mutex<Vec<Vec<u8>>>,
    state: RwLock<SocketState>,
    udp_layer: Arc<UdpLayer>,
    self_weak: Weak<UdpSocket>,
    recv_waker: Mutex<Option<Arc<Waker>>>,
    send_waker: Mutex<Option<Arc<Waker>>>,
    blocking_mode: Mutex<bool>,
}
Expand description

UDP socket

Implements SocketObject for UDP datagram communication.

Fields§

§local_addr: RwLock<Option<SocketAddress>>

Local address

§remote_addr: RwLock<Option<SocketAddress>>

Remote address (for connected sockets)

§send_buffer: Mutex<Vec<Vec<u8>>>

Send buffer

§recv_buffer: Mutex<Vec<Vec<u8>>>

Receive buffer

§state: RwLock<SocketState>

Socket state

§udp_layer: Arc<UdpLayer>

Reference to UDP layer

§self_weak: Weak<UdpSocket>

Weak self reference for registration

§recv_waker: Mutex<Option<Arc<Waker>>>

Receive waker for blocking I/O

§send_waker: Mutex<Option<Arc<Waker>>>

Send waker for blocking I/O

§blocking_mode: Mutex<bool>

Blocking mode (default: true)

Implementations§

Source§

impl UdpSocket

Source

pub fn new(udp_layer: Arc<UdpLayer>) -> Arc<Self>

Create a new UDP socket

Source

pub fn deliver_datagram(&self, data: Vec<u8>)

Deliver received datagram to this socket

Trait Implementations§

Source§

impl CloneOps for UdpSocket

Source§

fn custom_clone(&self) -> KernelObject

Perform a custom clone operation and return the cloned object Read more
Source§

impl Selectable for UdpSocket

Source§

fn current_ready(&self, interest: ReadyInterest) -> ReadySet

Return current readiness for the given interest set.
Source§

fn wait_until_ready( &self, interest: ReadyInterest, trapframe: &mut Trapframe, timeout_ticks: Option<u64>, ) -> SelectWaitOutcome

Block the current task using the provided trapframe until the interest becomes ready or the optional timeout (in ticks) expires. Read more
Source§

fn set_nonblocking(&self, enabled: bool)

Enable or disable non-blocking I/O semantics on this object. Read more
Source§

fn is_nonblocking(&self) -> bool

Query whether non-blocking I/O semantics are enabled on this object.
Source§

impl SocketControl for UdpSocket

Source§

fn bind(&self, address: &SocketAddress) -> Result<(), SocketError>

Bind socket to an address
Source§

fn connect(&self, address: &SocketAddress) -> Result<(), SocketError>

Connect to a remote address
Source§

fn listen(&self, _backlog: usize) -> Result<(), SocketError>

Listen for incoming connections (for stream sockets)
Source§

fn accept(&self) -> Result<Arc<dyn SocketObject>, SocketError>

Accept an incoming connection (for listening sockets) Returns a new socket for the accepted connection
Source§

fn getpeername(&self) -> Result<SocketAddress, SocketError>

Get socket peer address
Source§

fn getsockname(&self) -> Result<SocketAddress, SocketError>

Get socket local address
Source§

fn shutdown(&self, _how: ShutdownHow) -> Result<(), SocketError>

Shutdown socket for reading, writing, or both
Source§

fn is_connected(&self) -> bool

Check if socket is connected
Source§

fn state(&self) -> SocketState

Get socket state
Source§

impl SocketObject for UdpSocket

Source§

fn socket_type(&self) -> SocketType

Get socket type (Stream, Datagram, etc.)
Source§

fn socket_domain(&self) -> SocketDomain

Get socket domain (Local, Inet, Inet6, etc.)
Source§

fn socket_protocol(&self) -> SocketProtocol

Get socket protocol
Source§

fn as_any(&self) -> &dyn Any

Cast to Any for safe downcasting
Source§

fn sendto( &self, data: &[u8], address: &SocketAddress, _flags: u32, ) -> Result<usize, SocketError>

Send data to a specific address (for datagram sockets) For stream sockets, address is ignored and data is sent to connected peer
Source§

fn recvfrom( &self, buffer: &mut [u8], _flags: u32, ) -> Result<(usize, SocketAddress), SocketError>

Receive data with source address (for datagram sockets) For stream sockets, returns Unspecified address
Source§

fn as_selectable(&self) -> Option<&dyn Selectable>

Optional capability: expose select/pselect readiness/wait interface
Source§

fn as_control_ops(&self) -> Option<&dyn ControlOps>

Optional capability: expose control operations interface
Source§

impl StreamIpcOps for UdpSocket

Source§

fn is_connected(&self) -> bool

Check if the stream IPC object is still connected/valid
Source§

fn peer_count(&self) -> usize

Get the number of active peers (readers/writers/endpoints)
Source§

fn description(&self) -> String

Get a human-readable description of this IPC object
Source§

impl StreamOps for UdpSocket

Source§

fn read(&self, buffer: &mut [u8]) -> Result<usize, StreamError>

Read data from the stream
Source§

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

Write data to the stream

Auto Trait Implementations§

§

impl !Freeze for UdpSocket

§

impl !RefUnwindSafe for UdpSocket

§

impl Send for UdpSocket

§

impl Sync for UdpSocket

§

impl Unpin for UdpSocket

§

impl !UnwindSafe for UdpSocket

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.