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>
Initializes new socket.
Corresponds to C connect()
fn raw(&self) -> c_int
Returns underlying socket descriptor.
Note: ownership is not transferred.
fn name(&self) -> Result<SocketAddr>
Retrieves socket name i.e. address
Wraps getsockname()
Available for binded/connected sockets.
fn bind(&self, addr: &SocketAddr) -> Result<()>
Binds socket to address.
fn listen(&self, backlog: c_int) -> Result<()>
Listens for incoming connections on this socket.
fn recv(&self, buf: &mut [u8]) -> Result<usize>
Receives some bytes from socket
Number of received bytes is returned on success
fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, SocketAddr)>
Receives some bytes from socket
Number of received bytes and remote address are returned on success.
fn send(&self, buf: &[u8]) -> Result<usize>
Sends some bytes through socket.
Number of sent bytes is returned.
fn send_to(&self, buf: &[u8], peer_addr: &SocketAddr) -> 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 accept(&self) -> Result<(Socket, SocketAddr)>
Accepts incoming connection.
fn connect(&self, addr: &SocketAddr) -> Result<()>
Connects socket with remote address.
fn get_opt<T>(&self, level: c_int, name: c_int) -> Result<T>
Retrieves socket option.
fn set_opt<T>(&self, level: c_int, name: c_int, value: T) -> Result<()>
Sets socket option
Value is generally integer or C struct.
fn ioctl(&self, request: c_ulong, value: c_ulong) -> Result<()>
Sets I/O parameters of socket.
It uses ioctlsocket under hood.
fn set_nonblocking(&self, value: bool) -> Result<()>
Sets non-blocking mode.
fn shutdown(&self, direction: ShutdownType) -> Result<()>
Stops receive and/or send over socket.
fn close(&self) -> Result<()>
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
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
Consumes this object, returning the raw underlying file descriptor. Read more