LIBWIRE
Next-generation C++17 networking library.
|
Descriptor wrapper for UDP socket. More...
#include <socket.hpp>
Public Member Functions | |
socket (ip ipver) noexcept | |
Create new socket object. More... | |
socket (const socket &)=delete | |
socket (socket &&) noexcept=default | |
~socket () | |
Deallocate socket. More... | |
void | associate (endpoint target, std::error_code &ec) noexcept |
Associate UDP socket with remote endpoint. More... | |
void | close () noexcept |
Deallocate socket. More... | |
void | disassociate () noexcept |
Undo previous call to associate(). More... | |
internal_::socket & | implementation () noexcept |
const internal_::socket & | implementation () const noexcept |
void | listen (endpoint target, std::error_code &ec) noexcept |
Accept datagrams coming on specified endpoint. More... | |
internal_::socket::native_handle_t | native_handle () const noexcept |
Get native handle/descriptor for socket. More... | |
socket & | operator= (const socket &)=delete |
socket & | operator= (socket &&) noexcept=default |
Socket options | |
Several aspects of socket behavior can be changes by setting flags. See tcp::socket documentation for detailed explanation of socket options mechanism. There are no special options for UDP sockets. | |
template<typename Option > | |
auto | option (const Option &) const noexcept |
Query socket option value specified by type tag Option. More... | |
template<typename Option , typename... Args> | |
void | set_option (const Option &, Args &&...args) noexcept |
Set socket option value specified by type tag Option to value value. More... | |
Blocking I/O | |
I/O functions in this category usually block thread until operation is completed. | |
template<typename Buffer = std::vector<uint8_t>> | |
Buffer & | read (size_t bytes_count, Buffer &, std::error_code &, endpoint *source=nullptr) noexcept |
Read pending datagram into buffer. More... | |
template<typename Buffer = std::vector<uint8_t>> | |
Buffer | read (size_t bytes_count, std::error_code &, endpoint *source=nullptr) noexcept |
Same as overload with Buffer argument but return newly allocated buffer every time. More... | |
template<typename Buffer = std::vector<uint8_t>> | |
size_t | write (const Buffer &, std::error_code &, const endpoint &dest=endpoint::invalid) noexcept |
Write contents of buffer to socket. More... | |
Descriptor wrapper for UDP socket.
UDP (User Datagram Protocol) is a lightweight, unreliable, datagram-oriented, connectionless protocol. It can be used when reliability of TCP isn't important.
Definition at line 56 of file socket.hpp.
|
noexcept |
Create new socket object.
If socket allocationf ailed we will set socket to closed state.
|
delete |
|
defaultnoexcept |
libwire::udp::socket::~socket | ( | ) |
Deallocate socket.
|
noexcept |
Associate UDP socket with remote endpoint.
This will allow you to omit target endpoint from further calls to write(). Also, socket will not receive datagrams sent from endpoints other than specified.
ec will be set to error::invalid_argument if passed address object have IP version different from one passed to socket constructor.
|
noexcept |
Deallocate socket.
This makes this instance unusable.
|
noexcept |
Undo previous call to associate().
Have no effect if associate() is not used.
|
noexcept |
|
noexcept |
|
noexcept |
Accept datagrams coming on specified endpoint.
ec will be set if something went wrong.
|
noexcept |
Get native handle/descriptor for socket.
Returned value is undefined if is_open returns false.
|
inlinenoexcept |
Query socket option value specified by type tag Option.
Example:
Definition at line 119 of file socket.hpp.
|
noexcept |
Read pending datagram into buffer.
If buffer is not large enough to fit entire datagram it will be truncated. If buffer is smaller than datagram it will be resized to datagram size.
If src contains non-null pointer, datagram source endpoint will be written to it.
Buffer type requirements:
Buffer must be container that encapsulates dynamic array, so it must have data, size and resize member functions with behavior as in std::vector.
Definition at line 256 of file socket.hpp.
|
noexcept |
Same as overload with Buffer argument but return newly allocated buffer every time.
Definition at line 274 of file socket.hpp.
|
inlinenoexcept |
Set socket option value specified by type tag Option to value value.
Setting option not supported on current platform or specifying invalid value results in undefined behavior. But usually new value just ignored and corresponding option(tag) will return old value.
Example:
Definition at line 141 of file socket.hpp.
|
noexcept |
Write contents of buffer to socket.
Error code will be set if anything went wrong.
dest argument will override destination specified using associate.
Buffer type requirements
Buffer must be container that encapsulates dynamic array, so it must have data and size member functions with behavior as in std::vector.
Definition at line 287 of file socket.hpp.