mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -85,7 +85,7 @@ void HttpServerConnection::BuildHeader(raw_ostream& os, int code,
|
||||
os << "\r\n"; // header ends with a blank line
|
||||
}
|
||||
|
||||
void HttpServerConnection::SendData(span<const uv::Buffer> bufs,
|
||||
void HttpServerConnection::SendData(std::span<const uv::Buffer> bufs,
|
||||
bool closeAfter) {
|
||||
m_stream.Write(bufs, [closeAfter, stream = &m_stream](auto bufs, uv::Error) {
|
||||
for (auto&& buf : bufs) {
|
||||
|
||||
@@ -132,7 +132,7 @@ HttpPath::HttpPath(std::string_view path) {
|
||||
}
|
||||
|
||||
bool HttpPath::startswith(size_t start,
|
||||
span<const std::string_view> match) const {
|
||||
std::span<const std::string_view> match) const {
|
||||
if (m_pathEnds.size() < (start + match.size())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ void ParallelTcpConnector::Close() {
|
||||
}
|
||||
|
||||
void ParallelTcpConnector::SetServers(
|
||||
wpi::span<const std::pair<std::string, unsigned int>> servers) {
|
||||
std::span<const std::pair<std::string, unsigned int>> servers) {
|
||||
m_servers.assign(servers.begin(), servers.end());
|
||||
if (!IsConnected()) {
|
||||
Connect();
|
||||
|
||||
@@ -134,7 +134,7 @@ void UDPClient::shutdown() {
|
||||
}
|
||||
}
|
||||
|
||||
int UDPClient::send(span<const uint8_t> data, std::string_view server,
|
||||
int UDPClient::send(std::span<const uint8_t> data, std::string_view server,
|
||||
int port) {
|
||||
// server must be a resolvable IP address
|
||||
struct sockaddr_in addr;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace {
|
||||
class WebSocketWriteReq : public uv::WriteReq {
|
||||
public:
|
||||
explicit WebSocketWriteReq(
|
||||
std::function<void(span<uv::Buffer>, uv::Error)> callback)
|
||||
std::function<void(std::span<uv::Buffer>, uv::Error)> callback)
|
||||
: m_callback{std::move(callback)} {
|
||||
finish.connect([this](uv::Error err) {
|
||||
for (auto&& buf : m_internalBufs) {
|
||||
@@ -34,7 +34,7 @@ class WebSocketWriteReq : public uv::WriteReq {
|
||||
});
|
||||
}
|
||||
|
||||
std::function<void(span<uv::Buffer>, uv::Error)> m_callback;
|
||||
std::function<void(std::span<uv::Buffer>, uv::Error)> m_callback;
|
||||
SmallVector<uv::Buffer, 4> m_internalBufs;
|
||||
SmallVector<uv::Buffer, 4> m_userBufs;
|
||||
};
|
||||
@@ -105,7 +105,7 @@ WebSocket::~WebSocket() = default;
|
||||
|
||||
std::shared_ptr<WebSocket> WebSocket::CreateClient(
|
||||
uv::Stream& stream, std::string_view uri, std::string_view host,
|
||||
span<const std::string_view> protocols, const ClientOptions& options) {
|
||||
std::span<const std::string_view> protocols, const ClientOptions& options) {
|
||||
auto ws = std::make_shared<WebSocket>(stream, false, private_init{});
|
||||
stream.SetData(ws);
|
||||
ws->StartClient(uri, host, protocols, options);
|
||||
@@ -147,7 +147,7 @@ void WebSocket::Terminate(uint16_t code, std::string_view reason) {
|
||||
}
|
||||
|
||||
void WebSocket::StartClient(std::string_view uri, std::string_view host,
|
||||
span<const std::string_view> protocols,
|
||||
std::span<const std::string_view> protocols,
|
||||
const ClientOptions& options) {
|
||||
// Create client handshake data
|
||||
m_clientHandshake = std::make_unique<ClientHandshakeData>();
|
||||
@@ -323,7 +323,7 @@ void WebSocket::SendClose(uint16_t code, std::string_view reason) {
|
||||
raw_uv_ostream os{bufs, 4096};
|
||||
const uint8_t codeMsb[] = {static_cast<uint8_t>((code >> 8) & 0xff),
|
||||
static_cast<uint8_t>(code & 0xff)};
|
||||
os << span{codeMsb};
|
||||
os << std::span{codeMsb};
|
||||
os << reason;
|
||||
}
|
||||
Send(kFlagFin | kOpClose, bufs, [](auto bufs, uv::Error) {
|
||||
@@ -465,7 +465,7 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) {
|
||||
m_header[m_headerSize - 4], m_header[m_headerSize - 3],
|
||||
m_header[m_headerSize - 2], m_header[m_headerSize - 1]};
|
||||
int n = 0;
|
||||
for (uint8_t& ch : span{m_payload}.subspan(m_frameStart)) {
|
||||
for (uint8_t& ch : std::span{m_payload}.subspan(m_frameStart)) {
|
||||
ch ^= key[n++];
|
||||
if (n >= 4) {
|
||||
n = 0;
|
||||
@@ -596,7 +596,7 @@ void WebSocket::HandleIncoming(uv::Buffer& buf, size_t size) {
|
||||
|
||||
static void WriteFrame(WebSocketWriteReq& req,
|
||||
SmallVectorImpl<uv::Buffer>& bufs, bool server,
|
||||
uint8_t opcode, span<const uv::Buffer> data) {
|
||||
uint8_t opcode, std::span<const uv::Buffer> data) {
|
||||
SmallVector<uv::Buffer, 4> internalBufs;
|
||||
raw_uv_ostream os{internalBufs, 4096};
|
||||
|
||||
@@ -633,7 +633,7 @@ static void WriteFrame(WebSocketWriteReq& req,
|
||||
os << static_cast<unsigned char>((server ? 0x00 : kFlagMasking) | 126);
|
||||
const uint8_t sizeMsb[] = {static_cast<uint8_t>((size >> 8) & 0xff),
|
||||
static_cast<uint8_t>(size & 0xff)};
|
||||
os << span{sizeMsb};
|
||||
os << std::span{sizeMsb};
|
||||
} else {
|
||||
os << static_cast<unsigned char>((server ? 0x00 : kFlagMasking) | 127);
|
||||
const uint8_t sizeMsb[] = {static_cast<uint8_t>((size >> 56) & 0xff),
|
||||
@@ -644,7 +644,7 @@ static void WriteFrame(WebSocketWriteReq& req,
|
||||
static_cast<uint8_t>((size >> 16) & 0xff),
|
||||
static_cast<uint8_t>((size >> 8) & 0xff),
|
||||
static_cast<uint8_t>(size & 0xff)};
|
||||
os << span{sizeMsb};
|
||||
os << std::span{sizeMsb};
|
||||
}
|
||||
|
||||
// clients need to mask the input data
|
||||
@@ -657,7 +657,7 @@ static void WriteFrame(WebSocketWriteReq& req,
|
||||
for (uint8_t& v : key) {
|
||||
v = dist(gen);
|
||||
}
|
||||
os << span<const uint8_t>{key, 4};
|
||||
os << std::span<const uint8_t>{key, 4};
|
||||
// copy and mask data
|
||||
int n = 0;
|
||||
for (auto&& buf : data) {
|
||||
@@ -680,8 +680,8 @@ static void WriteFrame(WebSocketWriteReq& req,
|
||||
}
|
||||
|
||||
void WebSocket::SendFrames(
|
||||
span<const Frame> frames,
|
||||
std::function<void(span<uv::Buffer>, uv::Error)> callback) {
|
||||
std::span<const Frame> frames,
|
||||
std::function<void(std::span<uv::Buffer>, uv::Error)> callback) {
|
||||
// If we're not open, emit an error and don't send the data
|
||||
if (m_state != OPEN) {
|
||||
int err;
|
||||
|
||||
@@ -47,7 +47,7 @@ WebSocketServerHelper::WebSocketServerHelper(HttpParser& req) {
|
||||
}
|
||||
|
||||
std::pair<bool, std::string_view> WebSocketServerHelper::MatchProtocol(
|
||||
span<const std::string_view> protocols) {
|
||||
std::span<const std::string_view> protocols) {
|
||||
if (protocols.empty() && m_protocols.empty()) {
|
||||
return {true, {}};
|
||||
}
|
||||
@@ -62,7 +62,7 @@ std::pair<bool, std::string_view> WebSocketServerHelper::MatchProtocol(
|
||||
}
|
||||
|
||||
WebSocketServer::WebSocketServer(uv::Stream& stream,
|
||||
span<const std::string_view> protocols,
|
||||
std::span<const std::string_view> protocols,
|
||||
ServerOptions options, const private_init&)
|
||||
: m_stream{stream},
|
||||
m_helper{m_req},
|
||||
@@ -139,7 +139,7 @@ WebSocketServer::WebSocketServer(uv::Stream& stream,
|
||||
}
|
||||
|
||||
std::shared_ptr<WebSocketServer> WebSocketServer::Create(
|
||||
uv::Stream& stream, span<const std::string_view> protocols,
|
||||
uv::Stream& stream, std::span<const std::string_view> protocols,
|
||||
const ServerOptions& options) {
|
||||
auto server = std::make_shared<WebSocketServer>(stream, protocols, options,
|
||||
private_init{});
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
namespace wpi::uv {
|
||||
|
||||
std::shared_ptr<Process> Process::SpawnArray(Loop& loop, std::string_view file,
|
||||
span<const Option> options) {
|
||||
std::span<const Option> options) {
|
||||
// convert Option array to libuv structure
|
||||
uv_process_options_t coptions;
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ using namespace wpi::uv;
|
||||
namespace {
|
||||
class CallbackWriteReq : public WriteReq {
|
||||
public:
|
||||
CallbackWriteReq(span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback)
|
||||
CallbackWriteReq(std::span<const Buffer> bufs,
|
||||
std::function<void(std::span<Buffer>, Error)> callback)
|
||||
: m_bufs{bufs.begin(), bufs.end()} {
|
||||
finish.connect(
|
||||
[this, f = std::move(callback)](Error err) { f(m_bufs, err); });
|
||||
@@ -77,7 +77,7 @@ void Stream::StartRead() {
|
||||
});
|
||||
}
|
||||
|
||||
void Stream::Write(span<const Buffer> bufs,
|
||||
void Stream::Write(std::span<const Buffer> bufs,
|
||||
const std::shared_ptr<WriteReq>& req) {
|
||||
if (Invoke(&uv_write, req->GetRaw(), GetRawStream(), bufs.data(), bufs.size(),
|
||||
[](uv_write_t* r, int status) {
|
||||
@@ -92,12 +92,12 @@ void Stream::Write(span<const Buffer> bufs,
|
||||
}
|
||||
}
|
||||
|
||||
void Stream::Write(span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
void Stream::Write(std::span<const Buffer> bufs,
|
||||
std::function<void(std::span<Buffer>, Error)> callback) {
|
||||
Write(bufs, std::make_shared<CallbackWriteReq>(bufs, std::move(callback)));
|
||||
}
|
||||
|
||||
int Stream::TryWrite(span<const Buffer> bufs) {
|
||||
int Stream::TryWrite(std::span<const Buffer> bufs) {
|
||||
int val = uv_try_write(GetRawStream(), bufs.data(), bufs.size());
|
||||
if (val < 0) {
|
||||
this->ReportError(val);
|
||||
@@ -106,7 +106,7 @@ int Stream::TryWrite(span<const Buffer> bufs) {
|
||||
return val;
|
||||
}
|
||||
|
||||
int Stream::TryWrite2(span<const Buffer> bufs, Stream& send) {
|
||||
int Stream::TryWrite2(std::span<const Buffer> bufs, Stream& send) {
|
||||
int val = uv_try_write2(GetRawStream(), bufs.data(), bufs.size(),
|
||||
send.GetRawStream());
|
||||
if (val < 0) {
|
||||
|
||||
@@ -18,8 +18,8 @@ using namespace wpi::uv;
|
||||
|
||||
class CallbackUdpSendReq : public UdpSendReq {
|
||||
public:
|
||||
CallbackUdpSendReq(span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback)
|
||||
CallbackUdpSendReq(std::span<const Buffer> bufs,
|
||||
std::function<void(std::span<Buffer>, Error)> callback)
|
||||
: m_bufs{bufs.begin(), bufs.end()} {
|
||||
complete.connect(
|
||||
[this, f = std::move(callback)](Error err) { f(m_bufs, err); });
|
||||
@@ -133,7 +133,7 @@ void Udp::SetMulticastInterface(std::string_view interfaceAddr) {
|
||||
Invoke(&uv_udp_set_multicast_interface, GetRaw(), interfaceAddrBuf.c_str());
|
||||
}
|
||||
|
||||
void Udp::Send(const sockaddr& addr, span<const Buffer> bufs,
|
||||
void Udp::Send(const sockaddr& addr, std::span<const Buffer> bufs,
|
||||
const std::shared_ptr<UdpSendReq>& req) {
|
||||
if (Invoke(&uv_udp_send, req->GetRaw(), GetRaw(), bufs.data(), bufs.size(),
|
||||
&addr, [](uv_udp_send_t* r, int status) {
|
||||
@@ -148,13 +148,13 @@ void Udp::Send(const sockaddr& addr, span<const Buffer> bufs,
|
||||
}
|
||||
}
|
||||
|
||||
void Udp::Send(const sockaddr& addr, span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
void Udp::Send(const sockaddr& addr, std::span<const Buffer> bufs,
|
||||
std::function<void(std::span<Buffer>, Error)> callback) {
|
||||
Send(addr, bufs,
|
||||
std::make_shared<CallbackUdpSendReq>(bufs, std::move(callback)));
|
||||
}
|
||||
|
||||
void Udp::Send(span<const Buffer> bufs,
|
||||
void Udp::Send(std::span<const Buffer> bufs,
|
||||
const std::shared_ptr<UdpSendReq>& req) {
|
||||
if (Invoke(&uv_udp_send, req->GetRaw(), GetRaw(), bufs.data(), bufs.size(),
|
||||
nullptr, [](uv_udp_send_t* r, int status) {
|
||||
@@ -169,8 +169,8 @@ void Udp::Send(span<const Buffer> bufs,
|
||||
}
|
||||
}
|
||||
|
||||
void Udp::Send(span<const Buffer> bufs,
|
||||
std::function<void(span<Buffer>, Error)> callback) {
|
||||
void Udp::Send(std::span<const Buffer> bufs,
|
||||
std::function<void(std::span<Buffer>, Error)> callback) {
|
||||
Send(bufs, std::make_shared<CallbackUdpSendReq>(bufs, std::move(callback)));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user