diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx index cc2606714..938e243dd 100644 --- a/src/input/plugins/CurlInputPlugin.cxx +++ b/src/input/plugins/CurlInputPlugin.cxx @@ -132,7 +132,7 @@ private: /* virtual methods from CurlResponseHandler */ void OnHeaders(unsigned status, Curl::Headers &&headers) override; - void OnData(ConstBuffer data) override; + void OnData(std::span data) override; void OnEnd() override; void OnError(std::exception_ptr e) noexcept override; @@ -296,21 +296,21 @@ CurlInputStream::OnHeaders(unsigned status, } void -CurlInputStream::OnData(ConstBuffer data) +CurlInputStream::OnData(std::span data) { - assert(data.size > 0); + assert(!data.empty()); const std::scoped_lock protect(mutex); if (IsSeekPending()) SeekDone(); - if (data.size > GetBufferSpace()) { + if (data.size() > GetBufferSpace()) { AsyncInputStream::Pause(); throw CurlResponseHandler::Pause{}; } - AppendToBuffer(data.data, data.size); + AppendToBuffer(data.data(), data.size()); } void diff --git a/src/lib/curl/Adapter.cxx b/src/lib/curl/Adapter.cxx index e41587bff..89595566e 100644 --- a/src/lib/curl/Adapter.cxx +++ b/src/lib/curl/Adapter.cxx @@ -168,7 +168,7 @@ CurlResponseHandlerAdapter::DataReceived(const void *ptr, try { FinishHeaders(); - handler.OnData({ptr, received_size}); + handler.OnData({(const std::byte *)ptr, received_size}); return received_size; } catch (CurlResponseHandler::Pause) { return CURL_WRITEFUNC_PAUSE; diff --git a/src/lib/curl/Delegate.cxx b/src/lib/curl/Delegate.cxx index b6b6dc507..80d338d26 100644 --- a/src/lib/curl/Delegate.cxx +++ b/src/lib/curl/Delegate.cxx @@ -41,7 +41,7 @@ DelegateCurlResponseHandler::OnHeaders(unsigned status, Curl::Headers &&headers) } void -DelegateCurlResponseHandler::OnData(ConstBuffer data) +DelegateCurlResponseHandler::OnData(std::span data) { parser->OnData(data); } diff --git a/src/lib/curl/Delegate.hxx b/src/lib/curl/Delegate.hxx index 95c8576ce..78a074573 100644 --- a/src/lib/curl/Delegate.hxx +++ b/src/lib/curl/Delegate.hxx @@ -64,6 +64,6 @@ protected: public: void OnHeaders(unsigned status, Curl::Headers &&headers) final; - void OnData(ConstBuffer data) final; + void OnData(std::span data) final; void OnEnd() final; }; diff --git a/src/lib/curl/Handler.hxx b/src/lib/curl/Handler.hxx index c0bdeced1..eaad2a661 100644 --- a/src/lib/curl/Handler.hxx +++ b/src/lib/curl/Handler.hxx @@ -30,9 +30,10 @@ #pragma once #include "Headers.hxx" -#include "util/ConstBuffer.hxx" +#include #include +#include /** * Asynchronous response handler for a #CurlRequest. @@ -58,7 +59,7 @@ public: * * May throw #Pause (but nothing else). */ - virtual void OnData(ConstBuffer data) = 0; + virtual void OnData(std::span data) = 0; /** * The response has ended. The method is allowed to delete the diff --git a/src/lib/curl/Parser.hxx b/src/lib/curl/Parser.hxx index 709b4937f..482824d42 100644 --- a/src/lib/curl/Parser.hxx +++ b/src/lib/curl/Parser.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2018 Max Kellermann + * Copyright 2008-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,16 +27,15 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef CURL_PARSER_HXX -#define CURL_PARSER_HXX +#pragma once + +#include template struct ConstBuffer; class CurlResponseParser { public: virtual ~CurlResponseParser() = default; - virtual void OnData(ConstBuffer data) = 0; + virtual void OnData(std::span data) = 0; virtual void OnEnd() = 0; }; - -#endif diff --git a/src/lib/upnp/Discovery.cxx b/src/lib/upnp/Discovery.cxx index e224b28bd..36896966e 100644 --- a/src/lib/upnp/Discovery.cxx +++ b/src/lib/upnp/Discovery.cxx @@ -24,6 +24,7 @@ #include "event/Call.hxx" #include "util/DeleteDisposer.hxx" #include "util/ScopeExit.hxx" +#include "util/SpanCast.hxx" #include "util/RuntimeError.hxx" #include @@ -64,9 +65,9 @@ UPnPDeviceDirectory::Downloader::OnHeaders(unsigned status, } void -UPnPDeviceDirectory::Downloader::OnData(ConstBuffer _data) +UPnPDeviceDirectory::Downloader::OnData(std::span src) { - data.append((const char *)_data.data, _data.size); + data.append(ToStringView(src)); } void diff --git a/src/lib/upnp/Discovery.hxx b/src/lib/upnp/Discovery.hxx index 8052b1a31..b44b0e712 100644 --- a/src/lib/upnp/Discovery.hxx +++ b/src/lib/upnp/Discovery.hxx @@ -114,7 +114,7 @@ class UPnPDeviceDirectory final : UpnpCallback { /* virtual methods from CurlResponseHandler */ void OnHeaders(unsigned status, Curl::Headers &&headers) override; - void OnData(ConstBuffer data) override; + void OnData(std::span data) override; void OnEnd() override; void OnError(std::exception_ptr e) noexcept override; }; diff --git a/src/lib/yajl/ResponseParser.cxx b/src/lib/yajl/ResponseParser.cxx index f8c0b3727..09042a265 100644 --- a/src/lib/yajl/ResponseParser.cxx +++ b/src/lib/yajl/ResponseParser.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2018 Max Kellermann + * Copyright 2008-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,9 +31,9 @@ #include "util/ConstBuffer.hxx" void -YajlResponseParser::OnData(ConstBuffer data) +YajlResponseParser::OnData(std::span data) { - handle.Parse((const unsigned char *)data.data, data.size); + handle.Parse((const unsigned char *)data.data(), data.size()); } void diff --git a/src/lib/yajl/ResponseParser.hxx b/src/lib/yajl/ResponseParser.hxx index be08dd3d5..e6ac74466 100644 --- a/src/lib/yajl/ResponseParser.hxx +++ b/src/lib/yajl/ResponseParser.hxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2018 Max Kellermann + * Copyright 2008-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef YAJL_RESPONSE_PARSER_HXX -#define YAJL_RESPONSE_PARSER_HXX +#pragma once #include "Handle.hxx" #include "lib/curl/Parser.hxx" @@ -45,8 +44,6 @@ public: :handle(std::forward(args)...) {} /* virtual methods fro CurlResponseParser */ - void OnData(ConstBuffer data) final; + void OnData(std::span data) final; void OnEnd() override; }; - -#endif diff --git a/src/storage/plugins/CurlStorage.cxx b/src/storage/plugins/CurlStorage.cxx index 9ec3c2add..a518b99cf 100644 --- a/src/storage/plugins/CurlStorage.cxx +++ b/src/storage/plugins/CurlStorage.cxx @@ -37,6 +37,7 @@ #include "time/Parser.hxx" #include "util/ASCII.hxx" #include "util/RuntimeError.hxx" +#include "util/SpanCast.hxx" #include "util/StringCompare.hxx" #include "util/StringFormat.hxx" #include "util/StringView.hxx" @@ -307,9 +308,9 @@ private: throw std::runtime_error("Unexpected Content-Type from WebDAV server"); } - void OnData(ConstBuffer _data) final { - const auto data = ConstBuffer::FromVoid(_data); - Parse(data.data, data.size); + void OnData(std::span _src) final { + auto src = ToStringView(_src); + Parse(src.data(), src.size()); } void OnEnd() final { diff --git a/test/RunCurl.cxx b/test/RunCurl.cxx index 7ae233054..b03d0e571 100644 --- a/test/RunCurl.cxx +++ b/test/RunCurl.cxx @@ -48,9 +48,9 @@ public: i.first.c_str(), i.second.c_str()); } - void OnData(ConstBuffer data) override { + void OnData(std::span data) override { try { - if (fwrite(data.data, data.size, 1, stdout) != 1) + if (fwrite(data.data(), data.size(), 1, stdout) != 1) throw std::runtime_error("Failed to write"); } catch (...) { OnError(std::current_exception());