#include <userver/engine/io/socket.hpp>
Socket representation.
It is not thread-safe to concurrently read from socket. It is not thread-safe to concurrently write to socket. However it is safe to concurrently read and write into socket:
Definition at line 37 of file socket.hpp.
Classes | |
struct | RecvFromResult |
Public Member Functions | |
Socket ()=default | |
Constructs an invalid socket. | |
Socket (AddrDomain, SocketType) | |
Constructs a socket for the address domain of specified type. | |
Socket (int fd, AddrDomain domain=AddrDomain::kUnspecified) | |
Adopts an existing socket for specified address domain. | |
operator bool () const | |
Whether the socket is valid. | |
bool | IsValid () const override |
Whether the socket is valid. | |
void | Connect (const Sockaddr &, Deadline) |
Connects the socket to a specified endpoint. | |
void | Bind (const Sockaddr &) |
Binds the socket to the specified endpoint. | |
void | Listen (int backlog=SOMAXCONN) |
Starts listening for connections on a specified socket (must be bound). | |
bool | WaitReadable (Deadline) override |
Suspends current task until the socket has data available. | |
bool | WaitWriteable (Deadline) override |
Suspends current task until the socket can accept more data. | |
size_t | RecvSome (void *buf, size_t len, Deadline deadline) |
Receives at least one byte from the socket. | |
size_t | RecvAll (void *buf, size_t len, Deadline deadline) |
Receives exactly len bytes from the socket. | |
size_t | SendAll (std::initializer_list< IoData > list, Deadline deadline) |
Sends a buffer vector to the socket. | |
size_t | WriteAll (std::initializer_list< IoData > list, Deadline deadline) override |
size_t | SendAll (const IoData *list, std::size_t list_size, Deadline deadline) |
Sends exactly list_size IoData to the socket. | |
size_t | SendAll (const struct iovec *list, std::size_t list_size, Deadline deadline) |
Sends exactly list_size iovec to the socket. | |
size_t | SendAll (const void *buf, size_t len, Deadline deadline) |
Sends exactly len bytes to the socket. | |
Socket | Accept (Deadline) |
Accepts a connection from a listening socket. | |
RecvFromResult | RecvSomeFrom (void *buf, size_t len, Deadline deadline) |
Receives at least one byte from the socket, returning source address. | |
size_t | SendAllTo (const Sockaddr &dest_addr, const void *buf, size_t len, Deadline deadline) |
Sends exactly len bytes to the specified address via the socket. | |
int | Fd () const |
File descriptor corresponding to this socket. | |
const Sockaddr & | Getpeername () |
Address of a remote peer. | |
const Sockaddr & | Getsockname () |
Local socket address. | |
int | Release () &&noexcept |
Releases file descriptor and invalidates the socket. | |
void | Close () |
Closes and invalidates the socket. | |
int | GetOption (int layer, int optname) const |
Retrieves a socket option. | |
void | SetOption (int layer, int optname, int optval) |
Sets a socket option. | |
size_t | ReadSome (void *buf, size_t len, Deadline deadline) override |
Receives at least one byte from the socket. | |
size_t | ReadAll (void *buf, size_t len, Deadline deadline) override |
Receives exactly len bytes from the socket. | |
size_t | WriteAll (const void *buf, size_t len, Deadline deadline) override |
Writes exactly len bytes to the socket. | |
Public Member Functions inherited from engine::io::RwBase | |
ReadableBase & | GetReadableBase () |
WritableBase & | GetWritableBase () |
Public Member Functions inherited from engine::io::ReadableBase | |
impl::ContextAccessor * | TryGetContextAccessor () |
For internal use only. | |
Public Member Functions inherited from engine::io::WritableBase | |
impl::ContextAccessor * | TryGetContextAccessor () |
For internal use only. | |
Additional Inherited Members | |
Protected Member Functions inherited from engine::io::ReadableBase | |
void | SetReadableContextAccessor (impl::ContextAccessor *ca) |
Protected Member Functions inherited from engine::io::WritableBase | |
void | SetWritableContextAccessor (impl::ContextAccessor *ca) |
|
explicit |
Adopts an existing socket for specified address domain.
Accepts a connection from a listening socket.
void engine::io::Socket::Bind | ( | const Sockaddr & | ) |
Binds the socket to the specified endpoint.
void engine::io::Socket::Close | ( | ) |
Closes and invalidates the socket.
Connects the socket to a specified endpoint.
|
overridevirtual |
Whether the socket is valid.
Implements engine::io::ReadableBase.
|
inlineexplicit |
Whether the socket is valid.
Definition at line 55 of file socket.hpp.
|
inlineoverridevirtual |
Receives exactly len bytes from the socket.
Implements engine::io::ReadableBase.
Definition at line 163 of file socket.hpp.
|
inlineoverridevirtual |
Receives at least one byte from the socket.
Implements engine::io::ReadableBase.
Definition at line 156 of file socket.hpp.
size_t engine::io::Socket::RecvAll | ( | void * | buf, |
size_t | len, | ||
Deadline | deadline ) |
Receives exactly len bytes from the socket.
size_t engine::io::Socket::RecvSome | ( | void * | buf, |
size_t | len, | ||
Deadline | deadline ) |
Receives at least one byte from the socket.
RecvFromResult engine::io::Socket::RecvSomeFrom | ( | void * | buf, |
size_t | len, | ||
Deadline | deadline ) |
Receives at least one byte from the socket, returning source address.
size_t engine::io::Socket::SendAll | ( | const IoData * | list, |
std::size_t | list_size, | ||
Deadline | deadline ) |
Sends exactly list_size IoData to the socket.
size_t engine::io::Socket::SendAll | ( | const struct iovec * | list, |
std::size_t | list_size, | ||
Deadline | deadline ) |
Sends exactly list_size iovec to the socket.
size_t engine::io::Socket::SendAll | ( | const void * | buf, |
size_t | len, | ||
Deadline | deadline ) |
Sends exactly len bytes to the socket.
Sends a buffer vector to the socket.
size_t engine::io::Socket::SendAllTo | ( | const Sockaddr & | dest_addr, |
const void * | buf, | ||
size_t | len, | ||
Deadline | deadline ) |
Sends exactly len bytes to the specified address via the socket.
man sendto
.
|
overridevirtual |
Suspends current task until the socket has data available.
Implements engine::io::ReadableBase.
|
overridevirtual |
Suspends current task until the socket can accept more data.
Implements engine::io::WritableBase.
|
inlineoverridevirtual |
Writes exactly len bytes to the socket.
Implements engine::io::WritableBase.
Definition at line 170 of file socket.hpp.
|
inlineoverridevirtual |
Reimplemented from engine::io::WritableBase.
Definition at line 92 of file socket.hpp.