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
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_NFS_CONNECTION_HXX
|
#pragma once
|
||||||
#define MPD_NFS_CONNECTION_HXX
|
|
||||||
|
|
||||||
#include "Cancellable.hxx"
|
#include "Cancellable.hxx"
|
||||||
#include "event/SocketEvent.hxx"
|
#include "event/SocketEvent.hxx"
|
||||||
@ -124,7 +123,8 @@ class NfsConnection {
|
|||||||
public:
|
public:
|
||||||
[[gnu::nonnull]]
|
[[gnu::nonnull]]
|
||||||
NfsConnection(EventLoop &_loop,
|
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)),
|
:socket_event(_loop, BIND_THIS_METHOD(OnSocketReady)),
|
||||||
defer_new_lease(_loop, BIND_THIS_METHOD(RunDeferred)),
|
defer_new_lease(_loop, BIND_THIS_METHOD(RunDeferred)),
|
||||||
mount_timeout_event(_loop, BIND_THIS_METHOD(OnMountTimeout)),
|
mount_timeout_event(_loop, BIND_THIS_METHOD(OnMountTimeout)),
|
||||||
@ -141,13 +141,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
const char *GetServer() const noexcept {
|
std::string_view GetServer() const noexcept {
|
||||||
return server.c_str();
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
const char *GetExportName() const noexcept {
|
std::string_view GetExportName() const noexcept {
|
||||||
return export_name.c_str();
|
return export_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -225,5 +225,3 @@ private:
|
|||||||
/* DeferEvent callback */
|
/* DeferEvent callback */
|
||||||
void RunDeferred() noexcept;
|
void RunDeferred() noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -268,6 +268,6 @@ NfsFileReader::OnDeferredOpen() noexcept
|
|||||||
|
|
||||||
state = State::MOUNT;
|
state = State::MOUNT;
|
||||||
|
|
||||||
connection = &nfs_get_connection(server.c_str(), export_name.c_str());
|
connection = &nfs_get_connection(server, export_name);
|
||||||
connection->AddLease(*this);
|
connection->AddLease(*this);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,8 @@ nfs_get_event_loop() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
NfsConnection &
|
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);
|
assert(in_use > 0);
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
// Copyright The Music Player Daemon Project
|
// Copyright The Music Player Daemon Project
|
||||||
|
|
||||||
#ifndef MPD_NFS_GLUE_HXX
|
#pragma once
|
||||||
#define MPD_NFS_GLUE_HXX
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
class NfsConnection;
|
class NfsConnection;
|
||||||
@ -22,6 +23,5 @@ nfs_get_event_loop() noexcept;
|
|||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
NfsConnection &
|
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;
|
||||||
#endif
|
|
||||||
|
@ -20,8 +20,8 @@ class NfsManager::ManagedConnection final
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ManagedConnection(NfsManager &_manager, EventLoop &_loop,
|
ManagedConnection(NfsManager &_manager, EventLoop &_loop,
|
||||||
const char *_server,
|
std::string_view _server,
|
||||||
const char *_export_name) noexcept
|
std::string_view _export_name) noexcept
|
||||||
:NfsConnection(_loop, _server, _export_name),
|
:NfsConnection(_loop, _server, _export_name),
|
||||||
manager(_manager) {}
|
manager(_manager) {}
|
||||||
|
|
||||||
@ -55,15 +55,13 @@ NfsManager::~NfsManager() noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
NfsConnection &
|
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());
|
assert(GetEventLoop().IsInside());
|
||||||
|
|
||||||
for (auto &c : connections)
|
for (auto &c : connections)
|
||||||
if (StringIsEqual(server, c.GetServer()) &&
|
if (c.GetServer() == server &&
|
||||||
StringIsEqual(export_name, c.GetExportName()))
|
c.GetExportName() == export_name)
|
||||||
return c;
|
return c;
|
||||||
|
|
||||||
auto c = new ManagedConnection(*this, GetEventLoop(),
|
auto c = new ManagedConnection(*this, GetEventLoop(),
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "event/IdleEvent.hxx"
|
#include "event/IdleEvent.hxx"
|
||||||
#include "util/IntrusiveList.hxx"
|
#include "util/IntrusiveList.hxx"
|
||||||
|
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
class NfsConnection;
|
class NfsConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +42,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
NfsConnection &GetConnection(const char *server,
|
NfsConnection &GetConnection(std::string_view server,
|
||||||
const char *export_name) noexcept;
|
std::string_view export_name) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ScheduleDelete(ManagedConnection &c) noexcept;
|
void ScheduleDelete(ManagedConnection &c) noexcept;
|
||||||
|
@ -141,8 +141,7 @@ private:
|
|||||||
assert(state != State::READY);
|
assert(state != State::READY);
|
||||||
assert(GetEventLoop().IsInside());
|
assert(GetEventLoop().IsInside());
|
||||||
|
|
||||||
connection = &nfs_get_connection(server.c_str(),
|
connection = &nfs_get_connection(server, export_name);
|
||||||
export_name.c_str());
|
|
||||||
connection->AddLease(*this);
|
connection->AddLease(*this);
|
||||||
|
|
||||||
SetState(State::CONNECTING);
|
SetState(State::CONNECTING);
|
||||||
|
Loading…
Reference in New Issue
Block a user