diff --git a/src/client/Client.hxx b/src/client/Client.hxx index 7213b10b0..64e466ec8 100644 --- a/src/client/Client.hxx +++ b/src/client/Client.hxx @@ -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 src) noexcept override; void OnSocketError(std::exception_ptr ep) noexcept override; void OnSocketClosed() noexcept override; diff --git a/src/client/Read.cxx b/src/client/Read.cxx index ee079f7c2..ac4c86bc8 100644 --- a/src/client/Read.cxx +++ b/src/client/Read.cxx @@ -10,13 +10,13 @@ #include BufferedSocket::InputResult -Client::OnSocketInput(void *data, size_t length) noexcept +Client::OnSocketInput(std::span 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; diff --git a/src/event/BufferedSocket.cxx b/src/event/BufferedSocket.cxx index b9f68ad50..a1c1fb191 100644 --- a/src/event/BufferedSocket.cxx +++ b/src/event/BufferedSocket.cxx @@ -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()) { diff --git a/src/event/BufferedSocket.hxx b/src/event/BufferedSocket.hxx index b1953f942..156fd1e02 100644 --- a/src/event/BufferedSocket.hxx +++ b/src/event/BufferedSocket.hxx @@ -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 src) noexcept = 0; virtual void OnSocketError(std::exception_ptr ep) noexcept = 0; virtual void OnSocketClosed() noexcept = 0; diff --git a/src/output/plugins/httpd/HttpdClient.cxx b/src/output/plugins/httpd/HttpdClient.cxx index 0bfa27ee4..21b60e091 100644 --- a/src/output/plugins/httpd/HttpdClient.cxx +++ b/src/output/plugins/httpd/HttpdClient.cxx @@ -385,7 +385,7 @@ HttpdClient::OnSocketReady(unsigned flags) noexcept } BufferedSocket::InputResult -HttpdClient::OnSocketInput(void *data, size_t length) noexcept +HttpdClient::OnSocketInput(std::span 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; diff --git a/src/output/plugins/httpd/HttpdClient.hxx b/src/output/plugins/httpd/HttpdClient.hxx index 814498a9d..527342dd5 100644 --- a/src/output/plugins/httpd/HttpdClient.hxx +++ b/src/output/plugins/httpd/HttpdClient.hxx @@ -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 src) noexcept override; void OnSocketError(std::exception_ptr ep) noexcept override; void OnSocketClosed() noexcept override; }; diff --git a/src/output/plugins/snapcast/Client.cxx b/src/output/plugins/snapcast/Client.cxx index a3ed85659..cc3d62a5d 100644 --- a/src/output/plugins/snapcast/Client.cxx +++ b/src/output/plugins/snapcast/Client.cxx @@ -245,12 +245,12 @@ SnapcastClient::SendStreamTags(std::span payload) noexcept } BufferedSocket::InputResult -SnapcastClient::OnSocketInput(void *data, size_t length) noexcept +SnapcastClient::OnSocketInput(std::span 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()); diff --git a/src/output/plugins/snapcast/Client.hxx b/src/output/plugins/snapcast/Client.hxx index 880b26a6d..1b08ac36c 100644 --- a/src/output/plugins/snapcast/Client.hxx +++ b/src/output/plugins/snapcast/Client.hxx @@ -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 src) noexcept override; void OnSocketError(std::exception_ptr ep) noexcept override; void OnSocketClosed() noexcept override; };