mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[wpinet] Wrap a number of newer libuv features (#4260)
This commit is contained in:
@@ -106,4 +106,14 @@ int Stream::TryWrite(span<const Buffer> bufs) {
|
||||
return val;
|
||||
}
|
||||
|
||||
int Stream::TryWrite2(span<const Buffer> bufs, Stream& send) {
|
||||
int val = uv_try_write2(GetRawStream(), bufs.data(), bufs.size(),
|
||||
send.GetRawStream());
|
||||
if (val < 0) {
|
||||
this->ReportError(val);
|
||||
return 0;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
} // namespace wpi::uv
|
||||
|
||||
@@ -167,4 +167,15 @@ void Tcp::Connect6(std::string_view ip, unsigned int port,
|
||||
}
|
||||
}
|
||||
|
||||
void Tcp::CloseReset() {
|
||||
if (!IsClosing()) {
|
||||
uv_tcp_close_reset(GetRaw(), [](uv_handle_t* handle) {
|
||||
Tcp& h = *static_cast<Tcp*>(handle->data);
|
||||
h.closed();
|
||||
h.Release(); // free ourselves
|
||||
});
|
||||
ForceClosed();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace wpi::uv
|
||||
|
||||
@@ -117,6 +117,17 @@ void Udp::SetMembership(std::string_view multicastAddr,
|
||||
interfaceAddrBuf.c_str(), membership);
|
||||
}
|
||||
|
||||
void Udp::SetSourceMembership(std::string_view multicastAddr,
|
||||
std::string_view interfaceAddr,
|
||||
std::string_view sourceAddr,
|
||||
uv_membership membership) {
|
||||
SmallString<128> multicastAddrBuf{multicastAddr};
|
||||
SmallString<128> interfaceAddrBuf{interfaceAddr};
|
||||
SmallString<128> sourceAddrBuf{sourceAddr};
|
||||
Invoke(&uv_udp_set_source_membership, GetRaw(), multicastAddrBuf.c_str(),
|
||||
interfaceAddrBuf.c_str(), sourceAddrBuf.c_str(), membership);
|
||||
}
|
||||
|
||||
void Udp::SetMulticastInterface(std::string_view interfaceAddr) {
|
||||
SmallString<128> interfaceAddrBuf{interfaceAddr};
|
||||
Invoke(&uv_udp_set_multicast_interface, GetRaw(), interfaceAddrBuf.c_str());
|
||||
|
||||
@@ -211,6 +211,34 @@ class Stream : public Handle {
|
||||
return TryWrite({bufs.begin(), bufs.end()});
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as TryWrite() and extended write function for sending handles over a
|
||||
* pipe.
|
||||
*
|
||||
* Try to send a handle is not supported on Windows, where it returns
|
||||
* UV_EAGAIN.
|
||||
*
|
||||
* @param bufs The buffers to be written to the stream.
|
||||
* @param send send stream
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int TryWrite2(span<const Buffer> bufs, Stream& send);
|
||||
|
||||
/**
|
||||
* Same as TryWrite() and extended write function for sending handles over a
|
||||
* pipe.
|
||||
*
|
||||
* Try to send a handle is not supported on Windows, where it returns
|
||||
* UV_EAGAIN.
|
||||
*
|
||||
* @param bufs The buffers to be written to the stream.
|
||||
* @param send send stream
|
||||
* @return Number of bytes written.
|
||||
*/
|
||||
int TryWrite2(std::initializer_list<Buffer> bufs, Stream& send) {
|
||||
return TryWrite2({bufs.begin(), bufs.end()}, send);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the stream is readable.
|
||||
* @return True if the stream is readable, false otherwise.
|
||||
|
||||
@@ -338,6 +338,14 @@ class Tcp final : public NetworkStreamImpl<Tcp, uv_tcp_t> {
|
||||
void Connect6(std::string_view ip, unsigned int port,
|
||||
std::function<void()> callback);
|
||||
|
||||
/**
|
||||
* Resets a TCP connection by sending a RST packet. This is accomplished by
|
||||
* setting the SO_LINGER socket option with a linger interval of zero and then
|
||||
* calling Close(). Due to some platform inconsistencies, mixing of
|
||||
* Shutdown() and CloseReset() calls is not allowed.
|
||||
*/
|
||||
void CloseReset();
|
||||
|
||||
private:
|
||||
Tcp* DoAccept() override;
|
||||
|
||||
|
||||
@@ -125,6 +125,15 @@ class Timer final : public HandleImpl<Timer, uv_timer_t> {
|
||||
*/
|
||||
Time GetRepeat() const { return Time{uv_timer_get_repeat(GetRaw())}; }
|
||||
|
||||
/**
|
||||
* Get the timer due value or 0 if it has expired. The time is relative to
|
||||
* uv_now().
|
||||
*
|
||||
* @return Timer due value in milliseconds (as a
|
||||
* `std::chrono::duration<uint64_t, std::milli>`).
|
||||
*/
|
||||
Time GetDueIn() const { return Time{uv_timer_get_due_in(GetRaw())}; }
|
||||
|
||||
/**
|
||||
* Signal generated when the timeout event occurs.
|
||||
*/
|
||||
|
||||
@@ -172,6 +172,19 @@ class Udp final : public HandleImpl<Udp, uv_udp_t> {
|
||||
void SetMembership(std::string_view multicastAddr,
|
||||
std::string_view interfaceAddr, uv_membership membership);
|
||||
|
||||
/**
|
||||
* Set membership for a source-specific multicast group.
|
||||
*
|
||||
* @param multicastAddr Multicast address to set membership for
|
||||
* @param interfaceAddr Interface address
|
||||
* @param sourceAddr Source address
|
||||
* @param membership Should be UV_JOIN_GROUP or UV_LEAVE_GROUP
|
||||
*/
|
||||
void SetSourceMembership(std::string_view multicastAddr,
|
||||
std::string_view interfaceAddr,
|
||||
std::string_view sourceAddr,
|
||||
uv_membership membership);
|
||||
|
||||
/**
|
||||
* Set IP multicast loop flag. Makes multicast packets loop back to local
|
||||
* sockets.
|
||||
@@ -353,6 +366,13 @@ class Udp final : public HandleImpl<Udp, uv_udp_t> {
|
||||
*/
|
||||
void StopRecv() { Invoke(&uv_udp_recv_stop, GetRaw()); }
|
||||
|
||||
/**
|
||||
* Returns true if the UDP handle was created with the UV_UDP_RECVMMSG flag
|
||||
* and the platform supports recvmmsg(2), false otherwise.
|
||||
* @return True if the UDP handle is using recvmmsg.
|
||||
*/
|
||||
bool IsUsingRecvmmsg() const { return uv_udp_using_recvmmsg(GetRaw()); }
|
||||
|
||||
/**
|
||||
* Gets the amount of queued bytes waiting to be sent.
|
||||
* @return Amount of queued bytes waiting to be sent.
|
||||
|
||||
Reference in New Issue
Block a user