1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:07:34 +00:00

LibProtocol: Remove use of ByteBuffer::wrap() in protocol API

This commit is contained in:
Andreas Kling 2020-12-19 13:09:02 +01:00
parent 77515fead2
commit 685d5f4e25
6 changed files with 10 additions and 10 deletions

View file

@ -61,7 +61,7 @@ DownloadWidget::DownloadWidget(const URL& url)
m_download->on_progress = [this](Optional<u32> total_size, u32 downloaded_size) {
did_progress(total_size.value(), downloaded_size);
};
m_download->on_finish = [this](bool success, auto& payload, auto payload_storage, auto& response_headers, auto) {
m_download->on_finish = [this](bool success, auto payload, auto payload_storage, auto& response_headers, auto) {
did_finish(success, payload, payload_storage, response_headers);
};
@ -156,7 +156,7 @@ void DownloadWidget::did_progress(Optional<u32> total_size, u32 downloaded_size)
}
}
void DownloadWidget::did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)
void DownloadWidget::did_finish(bool success, ReadonlyBytes payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers)
{
(void)payload;
(void)payload_storage;

View file

@ -44,7 +44,7 @@ private:
explicit DownloadWidget(const URL&);
void did_progress(Optional<u32> total_size, u32 downloaded_size);
void did_finish(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers);
void did_finish(bool success, ReadonlyBytes payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers);
URL m_url;
String m_destination_path;

View file

@ -46,11 +46,11 @@ void Download::did_finish(Badge<Client>, bool success, Optional<u32> status_code
if (!on_finish)
return;
ByteBuffer payload;
ReadonlyBytes payload;
RefPtr<SharedBuffer> shared_buffer;
if (success && shbuf_id != -1) {
shared_buffer = SharedBuffer::create_from_shbuf_id(shbuf_id);
payload = ByteBuffer::wrap(shared_buffer->data<void>(), total_size);
payload = { shared_buffer->data<void>(), total_size };
}
// FIXME: It's a bit silly that we copy the response headers here just so we can move them into a HashMap with different traits.

View file

@ -53,7 +53,7 @@ public:
int id() const { return m_download_id; }
bool stop();
Function<void(bool success, const ByteBuffer& payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> on_finish;
Function<void(bool success, ReadonlyBytes payload, RefPtr<SharedBuffer> payload_storage, const HashMap<String, String, CaseInsensitiveStringTraits>& response_headers, Optional<u32> status_code)> on_finish;
Function<void(Optional<u32> total_size, u32 downloaded_size)> on_progress;
Function<CertificateAndKey()> on_certificate_requested;

View file

@ -170,7 +170,7 @@ void ResourceLoader::load(const LoadRequest& request, Function<void(const ByteBu
error_callback("Failed to initiate load");
return;
}
download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, const ByteBuffer& payload, auto, auto& response_headers, auto status_code) {
download->on_finish = [this, success_callback = move(success_callback), error_callback = move(error_callback)](bool success, ReadonlyBytes payload, auto, auto& response_headers, auto status_code) {
--m_pending_loads;
if (on_load_counter_change)
on_load_counter_change();

View file

@ -116,12 +116,12 @@ private:
bool m_might_be_wrong { false };
};
static void do_write(const ByteBuffer& payload)
static void do_write(ReadonlyBytes payload)
{
size_t length_remaining = payload.size();
size_t length_written = 0;
while (length_remaining > 0) {
auto nwritten = fwrite(payload.offset_pointer(length_written), sizeof(char), length_remaining, stdout);
auto nwritten = fwrite(payload.data() + length_written, sizeof(char), length_remaining, stdout);
if (nwritten > 0) {
length_remaining -= nwritten;
length_written += nwritten;
@ -192,7 +192,7 @@ int main(int argc, char** argv)
previous_downloaded_size = downloaded_size;
prev_time = current_time;
};
download->on_finish = [&](bool success, auto& payload, auto, auto& response_headers, auto) {
download->on_finish = [&](bool success, auto payload, auto, auto& response_headers, auto) {
fprintf(stderr, "\033]9;-1;\033\\");
fprintf(stderr, "\n");
if (success && save_at_provided_name) {