lib/curl: use std::span

This commit is contained in:
Max Kellermann
2022-06-27 17:27:37 +02:00
committed by Max Kellermann
parent 062df65b1e
commit 1da09f5b1b
12 changed files with 32 additions and 33 deletions

View File

@@ -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;

View File

@@ -41,7 +41,7 @@ DelegateCurlResponseHandler::OnHeaders(unsigned status, Curl::Headers &&headers)
}
void
DelegateCurlResponseHandler::OnData(ConstBuffer<void> data)
DelegateCurlResponseHandler::OnData(std::span<const std::byte> data)
{
parser->OnData(data);
}

View File

@@ -64,6 +64,6 @@ protected:
public:
void OnHeaders(unsigned status, Curl::Headers &&headers) final;
void OnData(ConstBuffer<void> data) final;
void OnData(std::span<const std::byte> data) final;
void OnEnd() final;
};

View File

@@ -30,9 +30,10 @@
#pragma once
#include "Headers.hxx"
#include "util/ConstBuffer.hxx"
#include <cstddef>
#include <exception>
#include <span>
/**
* Asynchronous response handler for a #CurlRequest.
@@ -58,7 +59,7 @@ public:
*
* May throw #Pause (but nothing else).
*/
virtual void OnData(ConstBuffer<void> data) = 0;
virtual void OnData(std::span<const std::byte> data) = 0;
/**
* The response has ended. The method is allowed to delete the

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2018 Max Kellermann <max.kellermann@gmail.com>
* Copyright 2008-2022 Max Kellermann <max.kellermann@gmail.com>
*
* 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 <span>
template<typename T> struct ConstBuffer;
class CurlResponseParser {
public:
virtual ~CurlResponseParser() = default;
virtual void OnData(ConstBuffer<void> data) = 0;
virtual void OnData(std::span<const std::byte> data) = 0;
virtual void OnEnd() = 0;
};
#endif