pub struct Socket { /* private fields */ }Expand description
An owned socket file descriptor. Closes itself on drop via our own close.
Implementations§
Source§impl Socket
impl Socket
Sourcepub unsafe fn from_raw_fd(fd: i32) -> Socket
pub unsafe fn from_raw_fd(fd: i32) -> Socket
Wrap an already-open fd (e.g. one accepted by io_uring) into an owning
Socket that closes it on drop.
§Safety
fd must be a valid open descriptor whose ownership is transferred here.
Sourcepub fn accept(&self) -> Result<Socket>
pub fn accept(&self) -> Result<Socket>
Accept one inbound connection. On a non-blocking listener with no pending
connection this returns Err with kind WouldBlock.
Sourcepub fn read(&self, buf: &mut [u8]) -> Result<usize>
pub fn read(&self, buf: &mut [u8]) -> Result<usize>
Read into buf, returning the byte count (0 == EOF). Retries on EINTR.
On a non-blocking socket with no data, returns WouldBlock.
Sourcepub fn write(&self, buf: &[u8]) -> Result<usize>
pub fn write(&self, buf: &[u8]) -> Result<usize>
A single write syscall; may write fewer bytes than requested, or return
WouldBlock on a full non-blocking socket. Retries on EINTR.
Sourcepub fn write_all(&self, buf: &[u8]) -> Result<()>
pub fn write_all(&self, buf: &[u8]) -> Result<()>
Write the whole buffer (blocking-socket convenience).
Sourcepub fn set_nonblocking(&self) -> Result<()>
pub fn set_nonblocking(&self) -> Result<()>
Put the socket into non-blocking mode (O_NONBLOCK).
Sourcepub fn set_nodelay(&self) -> Result<()>
pub fn set_nodelay(&self) -> Result<()>
Disable Nagle’s algorithm (TCP_NODELAY) for low-latency replies.
Sourcepub fn local_port(&self) -> Result<u16>
pub fn local_port(&self) -> Result<u16>
The local port this socket is bound to (host byte order).