From fe69ad086134526d9a74247a8e42076cabb9029e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 27 Sep 2023 10:28:26 +0200 Subject: [PATCH] event/BufferedSocket: pass std::span to DirectRead() --- src/event/BufferedSocket.cxx | 8 ++++---- src/event/BufferedSocket.hxx | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/event/BufferedSocket.cxx b/src/event/BufferedSocket.cxx index 052c984b1..8a9a6e047 100644 --- a/src/event/BufferedSocket.cxx +++ b/src/event/BufferedSocket.cxx @@ -6,10 +6,10 @@ #include -BufferedSocket::ssize_t -BufferedSocket::DirectRead(void *data, size_t length) noexcept +inline BufferedSocket::ssize_t +BufferedSocket::DirectRead(std::span 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); diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx index 4ae913067..b1953f942 100644 --- a/src/event/BufferedSocket.hxx +++ b/src/event/BufferedSocket.hxx @@ -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 #include #include +#include #include 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 dest) noexcept; /** * Receive data from the socket to the input buffer. @@ -120,5 +120,3 @@ protected: virtual void OnSocketReady(unsigned flags) noexcept; }; - -#endif