event/BufferedSocket: pass std::span to DirectRead()
This commit is contained in:
parent
9daf8f6de5
commit
fe69ad0861
@ -6,10 +6,10 @@
|
|||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
BufferedSocket::ssize_t
|
inline BufferedSocket::ssize_t
|
||||||
BufferedSocket::DirectRead(void *data, size_t length) noexcept
|
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]]
|
if (nbytes > 0) [[likely]]
|
||||||
return nbytes;
|
return nbytes;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ BufferedSocket::ReadToBuffer() noexcept
|
|||||||
const auto buffer = input.Write();
|
const auto buffer = input.Write();
|
||||||
assert(!buffer.empty());
|
assert(!buffer.empty());
|
||||||
|
|
||||||
const auto nbytes = DirectRead(buffer.data(), buffer.size());
|
const auto nbytes = DirectRead(buffer);
|
||||||
if (nbytes > 0)
|
if (nbytes > 0)
|
||||||
input.Append(nbytes);
|
input.Append(nbytes);
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_BUFFERED_SOCKET_HXX
|
#pragma once
|
||||||
#define MPD_BUFFERED_SOCKET_HXX
|
|
||||||
|
|
||||||
#include "SocketEvent.hxx"
|
#include "SocketEvent.hxx"
|
||||||
#include "util/StaticFifoBuffer.hxx"
|
#include "util/StaticFifoBuffer.hxx"
|
||||||
@ -10,6 +9,7 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
#include <span>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
@ -53,7 +53,7 @@ private:
|
|||||||
* socket isn't ready for reading, -1 on error (the socket has
|
* socket isn't ready for reading, -1 on error (the socket has
|
||||||
* been closed and probably destructed)
|
* 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.
|
* Receive data from the socket to the input buffer.
|
||||||
@ -120,5 +120,3 @@ protected:
|
|||||||
|
|
||||||
virtual void OnSocketReady(unsigned flags) noexcept;
|
virtual void OnSocketReady(unsigned flags) noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user