event/BufferedSocket: pass std::span to DirectRead()

This commit is contained in:
Max Kellermann 2023-09-27 10:28:26 +02:00
parent 9daf8f6de5
commit fe69ad0861
2 changed files with 7 additions and 9 deletions

View File

@ -6,10 +6,10 @@
#include <stdexcept>
BufferedSocket::ssize_t
BufferedSocket::DirectRead(void *data, size_t length) noexcept
inline BufferedSocket::ssize_t
BufferedSocket::DirectRead(std::span<std::byte> dest) noexcept
{
const auto nbytes = GetSocket().Read((char *)data, length);
const auto nbytes = GetSocket().Read((char *)dest.data(), dest.size());
if (nbytes > 0) [[likely]]
return nbytes;
@ -37,7 +37,7 @@ BufferedSocket::ReadToBuffer() noexcept
const auto buffer = input.Write();
assert(!buffer.empty());
const auto nbytes = DirectRead(buffer.data(), buffer.size());
const auto nbytes = DirectRead(buffer);
if (nbytes > 0)
input.Append(nbytes);

View File

@ -1,8 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#ifndef MPD_BUFFERED_SOCKET_HXX
#define MPD_BUFFERED_SOCKET_HXX
#pragma once
#include "SocketEvent.hxx"
#include "util/StaticFifoBuffer.hxx"
@ -10,6 +9,7 @@
#include <cassert>
#include <cstddef>
#include <exception>
#include <span>
#include <type_traits>
class EventLoop;
@ -53,7 +53,7 @@ private:
* socket isn't ready for reading, -1 on error (the socket has
* been closed and probably destructed)
*/
ssize_t DirectRead(void *data, size_t length) noexcept;
ssize_t DirectRead(std::span<std::byte> dest) noexcept;
/**
* Receive data from the socket to the input buffer.
@ -120,5 +120,3 @@ protected:
virtual void OnSocketReady(unsigned flags) noexcept;
};
#endif