diff --git a/src/lib/nfs/Connection.hxx b/src/lib/nfs/Connection.hxx index ad2756fe8..814209890 100644 --- a/src/lib/nfs/Connection.hxx +++ b/src/lib/nfs/Connection.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_NFS_CONNECTION_HXX -#define MPD_NFS_CONNECTION_HXX +#pragma once #include "Cancellable.hxx" #include "event/SocketEvent.hxx" @@ -124,7 +123,8 @@ class NfsConnection { public: [[gnu::nonnull]] NfsConnection(EventLoop &_loop, - const char *_server, const char *_export_name) noexcept + std::string_view _server, + std::string_view _export_name) noexcept :socket_event(_loop, BIND_THIS_METHOD(OnSocketReady)), defer_new_lease(_loop, BIND_THIS_METHOD(RunDeferred)), mount_timeout_event(_loop, BIND_THIS_METHOD(OnMountTimeout)), @@ -141,13 +141,13 @@ public: } [[gnu::pure]] - const char *GetServer() const noexcept { - return server.c_str(); + std::string_view GetServer() const noexcept { + return server; } [[gnu::pure]] - const char *GetExportName() const noexcept { - return export_name.c_str(); + std::string_view GetExportName() const noexcept { + return export_name; } /** @@ -225,5 +225,3 @@ private: /* DeferEvent callback */ void RunDeferred() noexcept; }; - -#endif diff --git a/src/lib/nfs/FileReader.cxx b/src/lib/nfs/FileReader.cxx index 4ef943d50..39bcf9315 100644 --- a/src/lib/nfs/FileReader.cxx +++ b/src/lib/nfs/FileReader.cxx @@ -268,6 +268,6 @@ NfsFileReader::OnDeferredOpen() noexcept state = State::MOUNT; - connection = &nfs_get_connection(server.c_str(), export_name.c_str()); + connection = &nfs_get_connection(server, export_name); connection->AddLease(*this); } diff --git a/src/lib/nfs/Glue.cxx b/src/lib/nfs/Glue.cxx index 6d518020e..013e0abcc 100644 --- a/src/lib/nfs/Glue.cxx +++ b/src/lib/nfs/Glue.cxx @@ -40,7 +40,8 @@ nfs_get_event_loop() noexcept } NfsConnection & -nfs_get_connection(const char *server, const char *export_name) noexcept +nfs_get_connection(std::string_view server, + std::string_view export_name) noexcept { assert(in_use > 0); diff --git a/src/lib/nfs/Glue.hxx b/src/lib/nfs/Glue.hxx index 6b66fda6a..7e5150ea4 100644 --- a/src/lib/nfs/Glue.hxx +++ b/src/lib/nfs/Glue.hxx @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_NFS_GLUE_HXX -#define MPD_NFS_GLUE_HXX +#pragma once + +#include class EventLoop; class NfsConnection; @@ -22,6 +23,5 @@ nfs_get_event_loop() noexcept; [[gnu::pure]] NfsConnection & -nfs_get_connection(const char *server, const char *export_name) noexcept; - -#endif +nfs_get_connection(std::string_view server, + std::string_view export_name) noexcept; diff --git a/src/lib/nfs/Manager.cxx b/src/lib/nfs/Manager.cxx index 7005d7a6d..6cab13390 100644 --- a/src/lib/nfs/Manager.cxx +++ b/src/lib/nfs/Manager.cxx @@ -20,8 +20,8 @@ class NfsManager::ManagedConnection final public: ManagedConnection(NfsManager &_manager, EventLoop &_loop, - const char *_server, - const char *_export_name) noexcept + std::string_view _server, + std::string_view _export_name) noexcept :NfsConnection(_loop, _server, _export_name), manager(_manager) {} @@ -55,15 +55,13 @@ NfsManager::~NfsManager() noexcept } NfsConnection & -NfsManager::GetConnection(const char *server, const char *export_name) noexcept +NfsManager::GetConnection(std::string_view server, std::string_view export_name) noexcept { - assert(server != nullptr); - assert(export_name != nullptr); assert(GetEventLoop().IsInside()); for (auto &c : connections) - if (StringIsEqual(server, c.GetServer()) && - StringIsEqual(export_name, c.GetExportName())) + if (c.GetServer() == server && + c.GetExportName() == export_name) return c; auto c = new ManagedConnection(*this, GetEventLoop(), diff --git a/src/lib/nfs/Manager.hxx b/src/lib/nfs/Manager.hxx index 32c531b4c..21cdcfa02 100644 --- a/src/lib/nfs/Manager.hxx +++ b/src/lib/nfs/Manager.hxx @@ -6,6 +6,8 @@ #include "event/IdleEvent.hxx" #include "util/IntrusiveList.hxx" +#include + class NfsConnection; /** @@ -40,8 +42,8 @@ public: } [[gnu::pure]] - NfsConnection &GetConnection(const char *server, - const char *export_name) noexcept; + NfsConnection &GetConnection(std::string_view server, + std::string_view export_name) noexcept; private: void ScheduleDelete(ManagedConnection &c) noexcept; diff --git a/src/storage/plugins/NfsStorage.cxx b/src/storage/plugins/NfsStorage.cxx index 265b7e2d6..2ce618ff1 100644 --- a/src/storage/plugins/NfsStorage.cxx +++ b/src/storage/plugins/NfsStorage.cxx @@ -141,8 +141,7 @@ private: assert(state != State::READY); assert(GetEventLoop().IsInside()); - connection = &nfs_get_connection(server.c_str(), - export_name.c_str()); + connection = &nfs_get_connection(server, export_name); connection->AddLease(*this); SetState(State::CONNECTING);