WPILibC++
2019.1.1-beta-4-17-g300eeb3
|
UDP handle. More...
#include <Udp.h>
Public Member Functions | |
Udp (const private_init &) | |
void | Open (uv_os_sock_t sock) |
Open an existing file descriptor or SOCKET as a UDP handle. More... | |
void | Bind (const sockaddr &addr, unsigned int flags=0) |
Bind the handle to an IPv4 or IPv6 address and port. More... | |
void | Bind (const sockaddr_in &addr, unsigned int flags=0) |
void | Bind (const sockaddr_in6 &addr, unsigned int flags=0) |
void | Bind (const Twine &ip, unsigned int port, unsigned int flags=0) |
Bind the handle to an IPv4 address and port. More... | |
void | Bind6 (const Twine &ip, unsigned int port, unsigned int flags=0) |
Bind the handle to an IPv6 address and port. More... | |
sockaddr_storage | GetSock () |
Get the current address to which the handle is bound. More... | |
void | SetMembership (const Twine &multicastAddr, const Twine &interfaceAddr, uv_membership membership) |
Set membership for a multicast address. More... | |
void | SetMulticastLoop (bool enabled) |
Set IP multicast loop flag. More... | |
void | SetMulticastTtl (int ttl) |
Set the multicast TTL. More... | |
void | SetMulticastInterface (const Twine &interfaceAddr) |
Set the multicast interface to send or receive data on. More... | |
void | SetBroadcast (bool enabled) |
Set broadcast on or off. More... | |
void | SetTtl (int ttl) |
Set the time to live (TTL). More... | |
void | Send (const sockaddr &addr, ArrayRef< Buffer > bufs, const std::shared_ptr< UdpSendReq > &req) |
Send data over the UDP socket. More... | |
void | Send (const sockaddr_in &addr, ArrayRef< Buffer > bufs, const std::shared_ptr< UdpSendReq > &req) |
void | Send (const sockaddr_in6 &addr, ArrayRef< Buffer > bufs, const std::shared_ptr< UdpSendReq > &req) |
void | Send (const sockaddr &addr, ArrayRef< Buffer > bufs, std::function< void(MutableArrayRef< Buffer >, Error)> callback) |
Send data over the UDP socket. More... | |
void | Send (const sockaddr_in &addr, ArrayRef< Buffer > bufs, std::function< void(MutableArrayRef< Buffer >, Error)> callback) |
void | Send (const sockaddr_in6 &addr, ArrayRef< Buffer > bufs, std::function< void(MutableArrayRef< Buffer >, Error)> callback) |
int | TrySend (const sockaddr &addr, ArrayRef< Buffer > bufs) |
Same as Send(), but won't queue a send request if it can't be completed immediately. More... | |
int | TrySend (const sockaddr_in &addr, ArrayRef< Buffer > bufs) |
int | TrySend (const sockaddr_in6 &addr, ArrayRef< Buffer > bufs) |
void | StartRecv () |
Prepare for receiving data. More... | |
void | StopRecv () |
Stop listening for incoming datagrams. | |
size_t | GetSendQueueSize () const noexcept |
Gets the amount of queued bytes waiting to be sent. More... | |
size_t | GetSendQueueCount () const noexcept |
Gets the amount of queued packets waiting to be sent. More... | |
![]() | |
std::shared_ptr< Udp > | shared_from_this () |
std::shared_ptr< const Udp > | shared_from_this () const |
uv_udp_t * | GetRaw () const noexcept |
Get the underlying handle data structure. More... | |
![]() | |
Handle (const Handle &)=delete | |
Handle (Handle &&)=delete | |
Handle & | operator= (const Handle &)=delete |
Handle & | operator= (Handle &&)=delete |
Type | GetType () const noexcept |
Get the type of the handle. More... | |
StringRef | GetTypeName () const noexcept |
Get the name of the type of the handle. More... | |
std::shared_ptr< Loop > | GetLoop () const noexcept |
Get the loop where this handle runs. More... | |
Loop & | GetLoopRef () const noexcept |
Get the loop where this handle runs. More... | |
bool | IsActive () const noexcept |
Check if the handle is active. More... | |
bool | IsClosing () const noexcept |
Check if a handle is closing or closed. More... | |
void | Close () noexcept |
Request handle to be closed. More... | |
void | Reference () noexcept |
Reference the given handle. More... | |
void | Unreference () noexcept |
Unreference the given handle. More... | |
bool | HasReference () const noexcept |
Check if the given handle is referenced. More... | |
size_t | RawSize () const noexcept |
Return the size of the underlying handle type. More... | |
uv_handle_t * | GetRawHandle () const noexcept |
Get the underlying handle data structure. More... | |
void | SetBufferAllocator (std::function< Buffer(size_t)> alloc, std::function< void(Buffer &)> dealloc) |
Set the functions used for allocating and releasing buffers. More... | |
void | FreeBuf (Buffer &buf) const noexcept |
Free a buffer. More... | |
template<typename T = void> | |
std::shared_ptr< T > | GetData () const |
Gets user-defined data. More... | |
void | SetData (std::shared_ptr< void > data) |
Sets user-defined data. More... | |
void | ReportError (int err) |
Report an error. More... | |
Static Public Member Functions | |
static std::shared_ptr< Udp > | Create (Loop &loop, unsigned int flags=AF_UNSPEC) |
Create a UDP handle. More... | |
static std::shared_ptr< Udp > | Create (const std::shared_ptr< Loop > &loop, unsigned int flags=AF_UNSPEC) |
Create a UDP handle. More... | |
Public Attributes | |
sig::Signal< Buffer &, size_t, const sockaddr &, unsigned > | received |
Signal generated for each incoming datagram. More... | |
![]() | |
sig::Signal< Error > | error |
Error signal. | |
sig::Signal | closed |
Closed signal. | |
Additional Inherited Members | |
![]() | |
using | Type = uv_handle_type |
![]() | |
Handle (uv_handle_t *uv_handle) | |
void | Keep () noexcept |
void | Release () noexcept |
void | ForceClosed () noexcept |
template<typename F , typename... Args> | |
bool | Invoke (F &&f, Args &&...args) |
![]() | |
static void | AllocBuf (uv_handle_t *handle, size_t size, uv_buf_t *buf) |
static void | DefaultFreeBuf (Buffer &buf) |
UDP handle.
UDP handles encapsulate UDP communication for both clients and servers.
|
inline |
Bind the handle to an IPv4 or IPv6 address and port.
addr | Initialized sockaddr_in or sockaddr_in6 data structure. |
flags | Optional additional flags. |
void wpi::uv::Udp::Bind | ( | const Twine & | ip, |
unsigned int | port, | ||
unsigned int | flags = 0 |
||
) |
Bind the handle to an IPv4 address and port.
ip | The address to which to bind. |
port | The port to which to bind. |
flags | Optional additional flags. |
void wpi::uv::Udp::Bind6 | ( | const Twine & | ip, |
unsigned int | port, | ||
unsigned int | flags = 0 |
||
) |
Bind the handle to an IPv6 address and port.
ip | The address to which to bind. |
port | The port to which to bind. |
flags | Optional additional flags. |
|
static |
Create a UDP handle.
loop | Loop object where this handle runs. |
flags | Flags |
|
inlinestatic |
Create a UDP handle.
loop | Loop object where this handle runs. |
flags | Flags |
|
inlinenoexcept |
Gets the amount of queued packets waiting to be sent.
|
inlinenoexcept |
Gets the amount of queued bytes waiting to be sent.
sockaddr_storage wpi::uv::Udp::GetSock | ( | ) |
Get the current address to which the handle is bound.
|
inline |
Open an existing file descriptor or SOCKET as a UDP handle.
sock | A valid socket handle (either a file descriptor or a SOCKET). |
void wpi::uv::Udp::Send | ( | const sockaddr & | addr, |
ArrayRef< Buffer > | bufs, | ||
const std::shared_ptr< UdpSendReq > & | req | ||
) |
Send data over the UDP socket.
If the socket has not previously been bound with Bind() it will be bound to 0.0.0.0 (the "all interfaces" IPv4 address) and a random port number.
Data are written in order. The lifetime of the data pointers passed in the bufs
parameter must exceed the lifetime of the send request. The callback can be used to free data after the request completes.
HandleSendComplete() will be called on the request object when the data has been written. HandleSendComplete() is called even if an error occurs. HandleError() will be called on the request object in case of errors.
addr | sockaddr_in or sockaddr_in6 with the address and port of the remote peer. |
bufs | The buffers to be written to the stream. |
req | write request |
void wpi::uv::Udp::Send | ( | const sockaddr & | addr, |
ArrayRef< Buffer > | bufs, | ||
std::function< void(MutableArrayRef< Buffer >, Error)> | callback | ||
) |
Send data over the UDP socket.
If the socket has not previously been bound with Bind() it will be bound to 0.0.0.0 (the "all interfaces" IPv4 address) and a random port number.
Data are written in order. The lifetime of the data pointers passed in the bufs
parameter must exceed the lifetime of the send request. The callback can be used to free data after the request completes.
The callback will be called when the data has been sent. Errors will be reported via the error signal.
addr | sockaddr_in or sockaddr_in6 with the address and port of the remote peer. |
bufs | The buffers to be sent. |
callback | Callback function to call when the data has been sent. |
|
inline |
Set broadcast on or off.
enabled | True for enabled, false for disabled |
void wpi::uv::Udp::SetMembership | ( | const Twine & | multicastAddr, |
const Twine & | interfaceAddr, | ||
uv_membership | membership | ||
) |
Set membership for a multicast address.
multicastAddr | Multicast address to set membership for |
interfaceAddr | Interface address |
membership | Should be UV_JOIN_GROUP or UV_LEAVE_GROUP |
void wpi::uv::Udp::SetMulticastInterface | ( | const Twine & | interfaceAddr | ) |
Set the multicast interface to send or receive data on.
interfaceAddr | Interface address |
|
inline |
Set IP multicast loop flag.
Makes multicast packets loop back to local sockets.
enabled | True for enabled, false for disabled |
|
inline |
Set the multicast TTL.
ttl | Time to live (1-255) |
|
inline |
Set the time to live (TTL).
ttl | Time to live (1-255) |
void wpi::uv::Udp::StartRecv | ( | ) |
Prepare for receiving data.
If the socket has not previously been bound with Bind() it is bound to 0.0.0.0 (the "all interfaces" IPv4 address) and a random port number.
A received signal will be emitted for each received data packet until StopRecv()
is called.
Same as Send(), but won't queue a send request if it can't be completed immediately.
addr | sockaddr_in or sockaddr_in6 with the address and port of the remote peer. |
bufs | The buffers to be send. |
sig::Signal<Buffer&, size_t, const sockaddr&, unsigned> wpi::uv::Udp::received |
Signal generated for each incoming datagram.
Parameters are the buffer, the number of bytes received, the address of the sender, and flags.