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

This commit is contained in:
Max Kellermann 2024-04-03 20:40:43 +02:00
parent 5de8edced6
commit c94c08c6b4
8 changed files with 16 additions and 16 deletions

View File

@ -258,7 +258,7 @@ private:
CommandResult ProcessLine(char *line) noexcept;
/* virtual methods from class BufferedSocket */
InputResult OnSocketInput(void *data, size_t length) noexcept override;
InputResult OnSocketInput(std::span<std::byte> src) noexcept override;
void OnSocketError(std::exception_ptr ep) noexcept override;
void OnSocketClosed() noexcept override;

View File

@ -10,13 +10,13 @@
#include <cstring>
BufferedSocket::InputResult
Client::OnSocketInput(void *data, size_t length) noexcept
Client::OnSocketInput(std::span<std::byte> src) noexcept
{
if (background_command)
return InputResult::PAUSE;
char *p = (char *)data;
char *newline = (char *)std::memchr(p, '\n', length);
char *p = (char *)src.data();
char *newline = (char *)std::memchr(p, '\n', src.size());
if (newline == nullptr)
return InputResult::MORE;

View File

@ -56,7 +56,7 @@ BufferedSocket::ResumeInput() noexcept
return true;
}
const auto result = OnSocketInput(buffer.data(), buffer.size());
const auto result = OnSocketInput(buffer);
switch (result) {
case InputResult::MORE:
if (input.IsFull()) {

View File

@ -109,11 +109,11 @@ protected:
/**
* Data has been received on the socket.
*
* @param data a pointer to the beginning of the buffer; the
* @param src the buffer containing the data; the
* buffer may be modified by the method while it processes the
* data
*/
virtual InputResult OnSocketInput(void *data, size_t length) noexcept = 0;
virtual InputResult OnSocketInput(std::span<std::byte> src) noexcept = 0;
virtual void OnSocketError(std::exception_ptr ep) noexcept = 0;
virtual void OnSocketClosed() noexcept = 0;

View File

@ -385,7 +385,7 @@ HttpdClient::OnSocketReady(unsigned flags) noexcept
}
BufferedSocket::InputResult
HttpdClient::OnSocketInput(void *data, size_t length) noexcept
HttpdClient::OnSocketInput(std::span<std::byte> src) noexcept
{
if (state == State::RESPONSE) {
LogWarning(httpd_output_domain,
@ -394,8 +394,8 @@ HttpdClient::OnSocketInput(void *data, size_t length) noexcept
return InputResult::CLOSED;
}
char *line = (char *)data;
char *newline = (char *)std::memchr(line, '\n', length);
char *line = (char *)src.data();
char *newline = (char *)std::memchr(line, '\n', src.size());
if (newline == nullptr)
return InputResult::MORE;

View File

@ -181,7 +181,7 @@ protected:
/* virtual methods from class BufferedSocket */
void OnSocketReady(unsigned flags) noexcept override;
InputResult OnSocketInput(void *data, size_t length) noexcept override;
InputResult OnSocketInput(std::span<std::byte> src) noexcept override;
void OnSocketError(std::exception_ptr ep) noexcept override;
void OnSocketClosed() noexcept override;
};

View File

@ -245,12 +245,12 @@ SnapcastClient::SendStreamTags(std::span<const std::byte> payload) noexcept
}
BufferedSocket::InputResult
SnapcastClient::OnSocketInput(void *data, size_t length) noexcept
SnapcastClient::OnSocketInput(std::span<std::byte> src) noexcept
{
auto &base = *(SnapcastBase *)data;
auto &base = *(SnapcastBase *)src.data();
if (length < sizeof(base) ||
length < sizeof(base) + base.size)
if (src.size() < sizeof(base) ||
src.size() < sizeof(base) + base.size)
return InputResult::MORE;
base.received = ToSnapcastTimestamp(GetEventLoop().SteadyNow());

View File

@ -79,7 +79,7 @@ private:
/* virtual methods from class BufferedSocket */
void OnSocketReady(unsigned flags) noexcept override;
InputResult OnSocketInput(void *data, size_t length) noexcept override;
InputResult OnSocketInput(std::span<std::byte> src) noexcept override;
void OnSocketError(std::exception_ptr ep) noexcept override;
void OnSocketClosed() noexcept override;
};