[−][src]Struct posix_socket::Socket
A POSIX socket.
Implementations
impl Socket[src]
pub fn new(domain: c_int, kind: c_int, protocol: c_int) -> Result<Self>[src]
Create a new socket with the specified domain, type and protocol.
The created socket has the close-on-exec flag set.
The flag will be set atomically when the socket is created if the platform supports it.
See man socket for more information.
pub fn pair(domain: c_int, kind: c_int, protocol: c_int) -> Result<(Self, Self)>[src]
Create a connected pair of socket with the specified domain, type and protocol.
The created sockets have the close-on-exec flag set.
The flag will be set atomically when the sockets are created if the platform supports it.
See man socketpair and man socket for more information.
pub fn try_clone(&self) -> Result<Self>[src]
Try to clone the socket.
This is implemented by duplicating the file descriptor.
The returned Socket refers to the same kernel object.
The underlying file descriptor of the new socket will have the close-on-exec flag set.
If the platform supports it, the flag will be set atomically when the file descriptor is duplicated.
pub unsafe fn from_raw_fd(fd: RawFd) -> Self[src]
Wrap a raw file descriptor in a Socket.
This function sets no flags or options on the file descriptor or socket.
It is your own responsibility to make sure the close-on-exec flag is already set,
and that the SO_NOSIGPIPE option is set on Apple platforms.
pub fn as_raw_fd(&self) -> RawFd[src]
Get the raw file descriptor.
This function does not release ownership of the underlying file descriptor.
The file descriptor will still be closed when the FileDesc is dropped.
pub fn into_raw_fd(self) -> RawFd[src]
Release and get the raw file descriptor.
This function releases ownership of the underlying file descriptor. The file descriptor will not be closed.
pub fn set_nonblocking(&self, non_blocking: bool) -> Result<()>[src]
Put the socket in blocking or non-blocking mode.
pub fn get_nonblocking(&self) -> Result<bool>[src]
Check if the socket in blocking or non-blocking mode.
pub fn take_error(&self) -> Result<Option<Error>>[src]
Gets the value of the SO_ERROR option on this socket.
This will retrieve the stored error in the underlying socket, clearing the field in the process. This can be useful for checking errors between calls.
pub fn send_msg(
&self,
data: &[IoSlice],
cdata: Option<&[u8]>,
flags: c_int
) -> Result<usize>[src]
&self,
data: &[IoSlice],
cdata: Option<&[u8]>,
flags: c_int
) -> Result<usize>
Send a message over the socket to the connected peer.
pub fn send_msg_to<Address: AsSocketAddress>(
&self,
address: &Address,
data: &[IoSlice],
cdata: Option<&[u8]>,
flags: c_int
) -> Result<usize>[src]
&self,
address: &Address,
data: &[IoSlice],
cdata: Option<&[u8]>,
flags: c_int
) -> Result<usize>
Send a message over the socket to the specified address.
This is only valid for connection-less protocols such as UDP or unix datagram sockets.
pub fn recv_msg(
&self,
data: &[IoSliceMut],
cdata: Option<&mut [u8]>,
flags: c_int
) -> Result<(usize, c_int)>[src]
&self,
data: &[IoSliceMut],
cdata: Option<&mut [u8]>,
flags: c_int
) -> Result<(usize, c_int)>
Receive a message on the socket from the connected peer.
pub fn recv_msg_from<Address: AsSocketAddress>(
&self,
data: &[IoSliceMut],
cdata: Option<&mut [u8]>,
flags: c_int
) -> Result<(Address, usize, c_int)>[src]
&self,
data: &[IoSliceMut],
cdata: Option<&mut [u8]>,
flags: c_int
) -> Result<(Address, usize, c_int)>
Receive a message on the socket from any address.
The address of the sender is given in the return value.
This is only valid for connection-less protocols such as UDP or unix datagram sockets.
Trait Implementations
impl AsRawFd for Socket[src]
impl<'_> AsRawFd for &'_ Socket[src]
impl FromRawFd for Socket[src]
unsafe fn from_raw_fd(fd: RawFd) -> Self[src]
impl IntoRawFd for Socket[src]
fn into_raw_fd(self) -> RawFd[src]
Auto Trait Implementations
impl RefUnwindSafe for Socket
impl Send for Socket
impl Sync for Socket
impl Unpin for Socket
impl UnwindSafe for Socket
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
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>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,