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§
Trait Implementations§
Source§impl CloneOps for UdpSocket
impl CloneOps for UdpSocket
Source§fn custom_clone(&self) -> KernelObject
fn custom_clone(&self) -> KernelObject
Perform a custom clone operation and return the cloned object Read more
Source§impl Selectable for UdpSocket
impl Selectable for UdpSocket
Source§fn current_ready(&self, interest: ReadyInterest) -> ReadySet
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
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)
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
fn is_nonblocking(&self) -> bool
Query whether non-blocking I/O semantics are enabled on this object.
Source§impl SocketControl for UdpSocket
impl SocketControl for UdpSocket
Source§fn bind(&self, address: &SocketAddress) -> Result<(), SocketError>
fn bind(&self, address: &SocketAddress) -> Result<(), SocketError>
Bind socket to an address
Source§fn connect(&self, address: &SocketAddress) -> Result<(), SocketError>
fn connect(&self, address: &SocketAddress) -> Result<(), SocketError>
Connect to a remote address
Source§fn listen(&self, _backlog: usize) -> Result<(), SocketError>
fn listen(&self, _backlog: usize) -> Result<(), SocketError>
Listen for incoming connections (for stream sockets)
Source§fn accept(&self) -> Result<Arc<dyn SocketObject>, SocketError>
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>
fn getpeername(&self) -> Result<SocketAddress, SocketError>
Get socket peer address
Source§fn getsockname(&self) -> Result<SocketAddress, SocketError>
fn getsockname(&self) -> Result<SocketAddress, SocketError>
Get socket local address
Source§fn shutdown(&self, _how: ShutdownHow) -> Result<(), SocketError>
fn shutdown(&self, _how: ShutdownHow) -> Result<(), SocketError>
Shutdown socket for reading, writing, or both
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Check if socket is connected
Source§fn state(&self) -> SocketState
fn state(&self) -> SocketState
Get socket state
Source§impl SocketObject for UdpSocket
impl SocketObject for UdpSocket
Source§fn socket_type(&self) -> SocketType
fn socket_type(&self) -> SocketType
Get socket type (Stream, Datagram, etc.)
Source§fn socket_domain(&self) -> SocketDomain
fn socket_domain(&self) -> SocketDomain
Get socket domain (Local, Inet, Inet6, etc.)
Source§fn socket_protocol(&self) -> SocketProtocol
fn socket_protocol(&self) -> SocketProtocol
Get socket protocol
Source§fn sendto(
&self,
data: &[u8],
address: &SocketAddress,
_flags: u32,
) -> Result<usize, SocketError>
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>
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>
fn as_selectable(&self) -> Option<&dyn Selectable>
Optional capability: expose select/pselect readiness/wait interface
Source§fn as_control_ops(&self) -> Option<&dyn ControlOps>
fn as_control_ops(&self) -> Option<&dyn ControlOps>
Optional capability: expose control operations interface
Source§impl StreamIpcOps for UdpSocket
impl StreamIpcOps for UdpSocket
Source§fn is_connected(&self) -> bool
fn is_connected(&self) -> bool
Check if the stream IPC object is still connected/valid
Source§fn peer_count(&self) -> usize
fn peer_count(&self) -> usize
Get the number of active peers (readers/writers/endpoints)
Source§fn description(&self) -> String
fn description(&self) -> String
Get a human-readable description of this IPC object