event/BufferedSocket: pass std::span to OnSocketInput()
This commit is contained in:
parent
5de8edced6
commit
c94c08c6b4
@ -258,7 +258,7 @@ private:
|
|||||||
CommandResult ProcessLine(char *line) noexcept;
|
CommandResult ProcessLine(char *line) noexcept;
|
||||||
|
|
||||||
/* virtual methods from class BufferedSocket */
|
/* 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 OnSocketError(std::exception_ptr ep) noexcept override;
|
||||||
void OnSocketClosed() noexcept override;
|
void OnSocketClosed() noexcept override;
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
BufferedSocket::InputResult
|
BufferedSocket::InputResult
|
||||||
Client::OnSocketInput(void *data, size_t length) noexcept
|
Client::OnSocketInput(std::span<std::byte> src) noexcept
|
||||||
{
|
{
|
||||||
if (background_command)
|
if (background_command)
|
||||||
return InputResult::PAUSE;
|
return InputResult::PAUSE;
|
||||||
|
|
||||||
char *p = (char *)data;
|
char *p = (char *)src.data();
|
||||||
char *newline = (char *)std::memchr(p, '\n', length);
|
char *newline = (char *)std::memchr(p, '\n', src.size());
|
||||||
if (newline == nullptr)
|
if (newline == nullptr)
|
||||||
return InputResult::MORE;
|
return InputResult::MORE;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ BufferedSocket::ResumeInput() noexcept
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto result = OnSocketInput(buffer.data(), buffer.size());
|
const auto result = OnSocketInput(buffer);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case InputResult::MORE:
|
case InputResult::MORE:
|
||||||
if (input.IsFull()) {
|
if (input.IsFull()) {
|
||||||
|
@ -109,11 +109,11 @@ protected:
|
|||||||
/**
|
/**
|
||||||
* Data has been received on the socket.
|
* 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
|
* buffer may be modified by the method while it processes the
|
||||||
* data
|
* 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 OnSocketError(std::exception_ptr ep) noexcept = 0;
|
||||||
virtual void OnSocketClosed() noexcept = 0;
|
virtual void OnSocketClosed() noexcept = 0;
|
||||||
|
@ -385,7 +385,7 @@ HttpdClient::OnSocketReady(unsigned flags) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
BufferedSocket::InputResult
|
BufferedSocket::InputResult
|
||||||
HttpdClient::OnSocketInput(void *data, size_t length) noexcept
|
HttpdClient::OnSocketInput(std::span<std::byte> src) noexcept
|
||||||
{
|
{
|
||||||
if (state == State::RESPONSE) {
|
if (state == State::RESPONSE) {
|
||||||
LogWarning(httpd_output_domain,
|
LogWarning(httpd_output_domain,
|
||||||
@ -394,8 +394,8 @@ HttpdClient::OnSocketInput(void *data, size_t length) noexcept
|
|||||||
return InputResult::CLOSED;
|
return InputResult::CLOSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *line = (char *)data;
|
char *line = (char *)src.data();
|
||||||
char *newline = (char *)std::memchr(line, '\n', length);
|
char *newline = (char *)std::memchr(line, '\n', src.size());
|
||||||
if (newline == nullptr)
|
if (newline == nullptr)
|
||||||
return InputResult::MORE;
|
return InputResult::MORE;
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ protected:
|
|||||||
/* virtual methods from class BufferedSocket */
|
/* virtual methods from class BufferedSocket */
|
||||||
void OnSocketReady(unsigned flags) noexcept override;
|
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 OnSocketError(std::exception_ptr ep) noexcept override;
|
||||||
void OnSocketClosed() noexcept override;
|
void OnSocketClosed() noexcept override;
|
||||||
};
|
};
|
||||||
|
@ -245,12 +245,12 @@ SnapcastClient::SendStreamTags(std::span<const std::byte> payload) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
BufferedSocket::InputResult
|
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) ||
|
if (src.size() < sizeof(base) ||
|
||||||
length < sizeof(base) + base.size)
|
src.size() < sizeof(base) + base.size)
|
||||||
return InputResult::MORE;
|
return InputResult::MORE;
|
||||||
|
|
||||||
base.received = ToSnapcastTimestamp(GetEventLoop().SteadyNow());
|
base.received = ToSnapcastTimestamp(GetEventLoop().SteadyNow());
|
||||||
|
@ -79,7 +79,7 @@ private:
|
|||||||
|
|
||||||
/* virtual methods from class BufferedSocket */
|
/* virtual methods from class BufferedSocket */
|
||||||
void OnSocketReady(unsigned flags) noexcept override;
|
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 OnSocketError(std::exception_ptr ep) noexcept override;
|
||||||
void OnSocketClosed() noexcept override;
|
void OnSocketClosed() noexcept override;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user