event/FullyBufferedSocket: pass std::span to DirectWrite()
This commit is contained in:
parent
fe69ad0861
commit
21590e60e6
@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
FullyBufferedSocket::ssize_t
|
inline FullyBufferedSocket::ssize_t
|
||||||
FullyBufferedSocket::DirectWrite(const void *data, size_t length) noexcept
|
FullyBufferedSocket::DirectWrite(std::span<const std::byte> src) noexcept
|
||||||
{
|
{
|
||||||
const auto nbytes = GetSocket().Write((const char *)data, length);
|
const auto nbytes = GetSocket().Write((const char *)src.data(), src.size());
|
||||||
if (nbytes < 0) [[unlikely]] {
|
if (nbytes < 0) [[unlikely]] {
|
||||||
const auto code = GetSocketError();
|
const auto code = GetSocketError();
|
||||||
if (IsSocketErrorSendWouldBlock(code))
|
if (IsSocketErrorSendWouldBlock(code))
|
||||||
@ -41,7 +41,7 @@ FullyBufferedSocket::Flush() noexcept
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nbytes = DirectWrite(data.data(), data.size());
|
auto nbytes = DirectWrite(data);
|
||||||
if (nbytes <= 0) [[unlikely]]
|
if (nbytes <= 0) [[unlikely]]
|
||||||
return nbytes == 0;
|
return nbytes == 0;
|
||||||
|
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
// 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_FULLY_BUFFERED_SOCKET_HXX
|
#pragma once
|
||||||
#define MPD_FULLY_BUFFERED_SOCKET_HXX
|
|
||||||
|
|
||||||
#include "BufferedSocket.hxx"
|
#include "BufferedSocket.hxx"
|
||||||
#include "IdleEvent.hxx"
|
#include "IdleEvent.hxx"
|
||||||
#include "util/PeakBuffer.hxx"
|
#include "util/PeakBuffer.hxx"
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A #BufferedSocket specialization that adds an output buffer.
|
* A #BufferedSocket specialization that adds an output buffer.
|
||||||
*/
|
*/
|
||||||
@ -42,7 +43,7 @@ private:
|
|||||||
* socket isn't ready for writing, -1 on error (the socket has
|
* socket isn't ready for writing, -1 on error (the socket has
|
||||||
* been closed and probably destructed)
|
* been closed and probably destructed)
|
||||||
*/
|
*/
|
||||||
ssize_t DirectWrite(const void *data, size_t length) noexcept;
|
ssize_t DirectWrite(std::span<const std::byte> src) noexcept;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
@ -62,5 +63,3 @@ protected:
|
|||||||
/* virtual methods from class BufferedSocket */
|
/* virtual methods from class BufferedSocket */
|
||||||
void OnSocketReady(unsigned flags) noexcept override;
|
void OnSocketReady(unsigned flags) noexcept override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user