lib/nfs/Connection: pass `server` and `export_name` as std::string_view
This commit is contained in:
parent
028693c380
commit
2b0275a1c8
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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 <string_view>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include "event/IdleEvent.hxx"
|
||||
#include "util/IntrusiveList.hxx"
|
||||
|
||||
#include <string_view>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue