event/FullyBufferedSocket: pass std::span to DirectWrite()
This commit is contained in:
parent
fe69ad0861
commit
21590e60e6
@ -8,10 +8,10 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
FullyBufferedSocket::ssize_t
|
||||
FullyBufferedSocket::DirectWrite(const void *data, size_t length) noexcept
|
||||
inline FullyBufferedSocket::ssize_t
|
||||
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]] {
|
||||
const auto code = GetSocketError();
|
||||
if (IsSocketErrorSendWouldBlock(code))
|
||||
@ -41,7 +41,7 @@ FullyBufferedSocket::Flush() noexcept
|
||||
return true;
|
||||
}
|
||||
|
||||
auto nbytes = DirectWrite(data.data(), data.size());
|
||||
auto nbytes = DirectWrite(data);
|
||||
if (nbytes <= 0) [[unlikely]]
|
||||
return nbytes == 0;
|
||||
|
||||
|
@ -1,13 +1,14 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_FULLY_BUFFERED_SOCKET_HXX
|
||||
#define MPD_FULLY_BUFFERED_SOCKET_HXX
|
||||
#pragma once
|
||||
|
||||
#include "BufferedSocket.hxx"
|
||||
#include "IdleEvent.hxx"
|
||||
#include "util/PeakBuffer.hxx"
|
||||
|
||||
#include <span>
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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:
|
||||
/**
|
||||
@ -62,5 +63,3 @@ protected:
|
||||
/* virtual methods from class BufferedSocket */
|
||||
void OnSocketReady(unsigned flags) noexcept override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user