Struct lazy_socket::raw::Socket
[−]
[src]
pub struct Socket { /* fields omitted */ }
Raw socket
Methods
impl Socket
[src]
fn new(family: c_int, _type: c_int, protocol: c_int) -> Result<Socket>
[src]
Initializes new socket.
Corresponds to C connect()
fn raw(&self) -> c_int
[src]
Returns underlying socket descriptor.
Note: ownership is not transferred.
fn name(&self) -> Result<SocketAddr>
[src]
Retrieves socket name i.e. address
Wraps getsockname()
Available for binded/connected sockets.
fn bind(&self, addr: &SocketAddr) -> Result<()>
[src]
Binds socket to address.
fn listen(&self, backlog: c_int) -> Result<()>
[src]
Listens for incoming connections on this socket.
fn recv(&self, buf: &mut [u8], flags: c_int) -> Result<usize>
[src]
Receives some bytes from socket
Number of received bytes is returned on success
fn recv_from(&self, buf: &mut [u8], flags: c_int) -> Result<(usize, SocketAddr)>
[src]
Receives some bytes from socket
Number of received bytes and remote address are returned on success.
fn send(&self, buf: &[u8], flags: c_int) -> Result<usize>
[src]
Sends some bytes through socket.
Number of sent bytes is returned.
fn send_to(
&self,
buf: &[u8],
peer_addr: &SocketAddr,
flags: c_int
) -> Result<usize>
[src]
&self,
buf: &[u8],
peer_addr: &SocketAddr,
flags: c_int
) -> Result<usize>
Sends some bytes through socket toward specified peer.
Number of sent bytes is returned.
Note: the socket will be bound, if it isn't already.
Use method name
to determine address.
fn accept4(&self, flags: AcceptFlags) -> Result<(Socket, SocketAddr)>
[src]
Accept a new incoming client connection and return its files descriptor and address.
By default the newly created socket will be inheritable by child processes and created
in blocking I/O mode. This behaviour can be customized using the flags
parameter:
AcceptFlags::NON_BLOCKING
– Mark the newly created socket as non-blockingAcceptFlags::NON_INHERITABLE
– Mark the newly created socket as not inheritable by client processes
Depending on the operating system's availability of the accept4(2)
system call this call
either pass the flags on to the operating system or emulate the call using accept(2)
.
fn accept(&self) -> Result<(Socket, SocketAddr)>
[src]
Accept a new incoming client connection and return its files descriptor and address.
As this uses the classic accept(2)
system call internally, you are strongly advised to
use the .accept4()
method instead to get defined blocking and inheritance semantics for
the created file descriptor.
fn connect(&self, addr: &SocketAddr) -> Result<()>
[src]
Connects socket with remote address.
fn get_opt<T>(&self, level: c_int, name: c_int) -> Result<T>
[src]
Retrieves socket option.
fn set_opt<T>(&self, level: c_int, name: c_int, value: T) -> Result<()>
[src]
Sets socket option
Value is generally integer or C struct.
fn ioctl(&self, request: c_ulong, value: c_ulong) -> Result<()>
[src]
Sets I/O parameters of socket.
fn set_blocking(&self, value: bool) -> Result<()>
[src]
Sets non-blocking mode.
fn set_inheritable(&self, value: bool) -> Result<()>
[src]
Sets whether this socket will be inherited by newly created processes or not.
Internally this is implemented by calling fcntl(fd, F_GETFD)
and fcntl(fd, F_SETFD)
to update the FD_CLOEXEC
flag. (In the future this might use ioctl(2)
on some
platforms instead.)
This means that the socket will still be available to forked off child processes until it
calls execve(2)
to complete the creation of a new process. A forking server application
(or similar) should therefore not expect this flag to have any effect on spawned off workers;
you're advised to manually call .close()
on the socket instance in the worker process
instead. The standard library's std::process
facility is not impacted by this however.
fn get_inheritable(&self) -> Result<bool>
[src]
Returns whether this will be inherited by newly created processes or not.
See set_inheritable
for a detailed description of what this means.
fn shutdown(&self, direction: ShutdownType) -> Result<()>
[src]
Stops receive and/or send over socket.
fn close(&self) -> Result<()>
[src]
Closes socket.
Note: on Drop
socket will be closed on its own.
There is no need to close it explicitly.
Trait Implementations
impl Drop for Socket
[src]
impl AsRawFd for Socket
[src]
impl FromRawFd for Socket
[src]
unsafe fn from_raw_fd(sock: c_int) -> Self
[src]
Constructs a new instance of Self
from the given raw file descriptor. Read more
impl IntoRawFd for Socket
[src]
fn into_raw_fd(self) -> c_int
[src]
Consumes this object, returning the raw underlying file descriptor. Read more