|
uvco 0.1
|
A UDP socket. More...
#include <udp.h>

Classes | |
| struct | RecvAwaiter_ |
| struct | SendAwaiter_ |
Public Member Functions | |
| Udp (const Loop &loop) | |
| Set up a UDP object. | |
| Udp (Udp &&other)=default | |
| Udp & | operator= (Udp &&other)=default |
| Udp (const Udp &)=delete | |
| Udp & | operator= (const Udp &)=delete |
| ~Udp () | |
| Promise< void > | bind (std::string_view address, uint16_t port, unsigned int flag=0) |
| Bind UDP socket to address. | |
| Promise< void > | bind (const AddressHandle &address, unsigned int flag=0) |
| Promise< void > | connect (std::string_view address, uint16_t port, bool ipv6only=false) |
| Connect UDP socket to address. | |
| Promise< void > | connect (const AddressHandle &address) |
| Promise< void > | send (std::span< const char > buffer, std::optional< AddressHandle > address={}) |
| Promise< std::string > | receiveOne () |
| Promise< std::pair< std::string, AddressHandle > > | receiveOneFrom () |
| MultiPromise< std::pair< std::string, AddressHandle > > | receiveMany () |
| void | stopReceiveMany (MultiPromise< std::pair< std::string, AddressHandle > > &packets) |
| void | setBroadcast (bool enabled) |
| Enable sending to broadcast addresses. | |
| void | setTtl (uint8_t ttl) |
| Set TTL on sent packets. TTL must be between 1 and 255. | |
| void | setMulticastInterface (const std::string &interfaceAddress) |
| Set multicast interface for sending or receiving data. | |
| void | setMulticastLoop (bool enabled) |
| void | joinMulticast (const std::string &address, const std::string &interface) |
| Join a multicast group. | |
| void | leaveMulticast (const std::string &address, const std::string &interface) |
| Leave multicast group. | |
| AddressHandle | getSockname () const |
| Obtain locally bound name of socket. | |
| std::optional< AddressHandle > | getPeername () const |
| Obtain peer name if connected. | |
| void | close () |
Private Member Functions | |
| int | udpStartReceive () |
| void | udpStopReceive () |
Static Private Member Functions | |
| static void | onSendDone (uv_udp_send_t *req, uv_status status) |
| static void | onReceiveOne (uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned int flags) |
Private Attributes | |
| const Loop * | loop_ |
| std::unique_ptr< uv_udp_t > | udp_ |
| bool | connected_ = false |
A UDP socket.
|
explicit |
Set up a UDP object.
|
default |
|
delete |
| uvco::Udp::~Udp | ( | ) |
| Promise< void > uvco::Udp::bind | ( | const AddressHandle & | address, |
| unsigned int | flag = 0 ) |
| Promise< void > uvco::Udp::bind | ( | std::string_view | address, |
| uint16_t | port, | ||
| unsigned int | flag = 0 ) |
Bind UDP socket to address.
| void uvco::Udp::close | ( | ) |
Close UDP socket. The socket is not closed immediately; it typically takes another turn of the libuv event loop before the closing operation is finished. In most cases you don't need to care about that.
| Promise< void > uvco::Udp::connect | ( | const AddressHandle & | address | ) |
| Promise< void > uvco::Udp::connect | ( | std::string_view | address, |
| uint16_t | port, | ||
| bool | ipv6only = false ) |
Connect UDP socket to address.
|
nodiscard |
Obtain peer name if connected.
|
nodiscard |
Obtain locally bound name of socket.
| void uvco::Udp::joinMulticast | ( | const std::string & | address, |
| const std::string & | interface ) |
| void uvco::Udp::leaveMulticast | ( | const std::string & | address, |
| const std::string & | interface ) |
|
staticprivate |
|
staticprivate |
| MultiPromise< std::pair< std::string, AddressHandle > > uvco::Udp::receiveMany | ( | ) |
Generate packets received on socket. Call stopReceiveMany() when no more packets are desired; otherwise this will continue indefinitely.
Only one coroutine can be receiving at a time. This is currently enforced by assertions.
| Promise< std::string > uvco::Udp::receiveOne | ( | ) |
Receive a single UDP packet.
TODO: use a better-suited buffer type.
Only one coroutine can be receiving at a time. This is currently enforced by assertions.
| Promise< std::pair< std::string, AddressHandle > > uvco::Udp::receiveOneFrom | ( | ) |
Receive a single UDP packet and also return the sender's address.
Only one coroutine can be receiving at a time. This is currently enforced by assertions.
| Promise< void > uvco::Udp::send | ( | std::span< const char > | buffer, |
| std::optional< AddressHandle > | address = {} ) |
Send to address, or send to connected peer. Must be a mutable buffer because libuv requires it - the buffer will not be modified.
| void uvco::Udp::setBroadcast | ( | bool | enabled | ) |
| void uvco::Udp::setMulticastInterface | ( | const std::string & | interfaceAddress | ) |
| void uvco::Udp::setMulticastLoop | ( | bool | enabled | ) |
| void uvco::Udp::setTtl | ( | uint8_t | ttl | ) |
| void uvco::Udp::stopReceiveMany | ( | MultiPromise< std::pair< std::string, AddressHandle > > & | packets | ) |
Stop receiving with receiveMany() by cancelling the receiving generator coroutine. Supply the MultiPromise obtained from receiveMany() in order to guarantee a complete clean-up.
|
private |
|
private |
|
private |
|
private |
|
private |