diff --git a/src/network/core/os_abstraction.cpp b/src/network/core/os_abstraction.cpp index 238f368f6e..923fedba6e 100644 --- a/src/network/core/os_abstraction.cpp +++ b/src/network/core/os_abstraction.cpp @@ -29,7 +29,7 @@ * @param error The error code. * @param message The error message. Leave empty to determine this automatically based on the error number. */ -NetworkError::NetworkError(int error, const std::string &message) : error(error), message(message) +NetworkError::NetworkError(int error, std::string_view message) : error(error), message(message) { } @@ -78,7 +78,7 @@ bool NetworkError::IsConnectInProgress() const * Get the string representation of the error message. * @return The string representation that will get overwritten by next calls. */ -const std::string &NetworkError::AsString() const +std::string_view NetworkError::AsString() const { if (this->message.empty()) { #if defined(_WIN32) diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 86c37db105..f4d090bbd6 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -23,13 +23,13 @@ private: int error; ///< The underlying error number from errno or WSAGetLastError. mutable std::string message; ///< The string representation of the error (set on first call to #AsString). public: - NetworkError(int error, const std::string &message = {}); + NetworkError(int error, std::string_view message = {}); bool HasError() const; bool WouldBlock() const; bool IsConnectionReset() const; bool IsConnectInProgress() const; - const std::string &AsString() const; + std::string_view AsString() const; static NetworkError GetLast(); };