forked from ShuriZma/suyu
1
0
Fork 0

kernel/server_session: Return a std::pair from CreateSessionPair()

Keeps the return type consistent with the function name. While we're at
it, we can also reduce the amount of boilerplate involved with handling
these by using structured bindings.
This commit is contained in:
Lioncash 2019-04-06 01:41:43 -04:00
parent 04d265562f
commit 7a7ffa602d
4 changed files with 8 additions and 11 deletions

View File

@ -139,10 +139,8 @@ public:
context->AddDomainObject(std::move(iface)); context->AddDomainObject(std::move(iface));
} else { } else {
auto& kernel = Core::System::GetInstance().Kernel(); auto& kernel = Core::System::GetInstance().Kernel();
auto sessions = auto [server, client] =
Kernel::ServerSession::CreateSessionPair(kernel, iface->GetServiceName()); Kernel::ServerSession::CreateSessionPair(kernel, iface->GetServiceName());
auto server = std::get<Kernel::SharedPtr<Kernel::ServerSession>>(sessions);
auto client = std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions);
iface->ClientConnected(server); iface->ClientConnected(server);
context->AddMoveObject(std::move(client)); context->AddMoveObject(std::move(client));
} }

View File

@ -2,8 +2,6 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <tuple>
#include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h" #include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/errors.h" #include "core/hle/kernel/errors.h"
@ -31,18 +29,18 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() {
active_sessions++; active_sessions++;
// Create a new session pair, let the created sessions inherit the parent port's HLE handler. // Create a new session pair, let the created sessions inherit the parent port's HLE handler.
auto sessions = ServerSession::CreateSessionPair(kernel, server_port->GetName(), this); auto [server, client] = ServerSession::CreateSessionPair(kernel, server_port->GetName(), this);
if (server_port->HasHLEHandler()) { if (server_port->HasHLEHandler()) {
server_port->GetHLEHandler()->ClientConnected(std::get<SharedPtr<ServerSession>>(sessions)); server_port->GetHLEHandler()->ClientConnected(server);
} else { } else {
server_port->AppendPendingSession(std::get<SharedPtr<ServerSession>>(sessions)); server_port->AppendPendingSession(server);
} }
// Wake the threads waiting on the ServerPort // Wake the threads waiting on the ServerPort
server_port->WakeupAllWaitingThreads(); server_port->WakeupAllWaitingThreads();
return MakeResult(std::get<SharedPtr<ClientSession>>(sessions)); return MakeResult(client);
} }
void ClientPort::ConnectionClosed() { void ClientPort::ConnectionClosed() {

View File

@ -204,6 +204,6 @@ ServerSession::SessionPair ServerSession::CreateSessionPair(KernelCore& kernel,
client_session->parent = parent; client_session->parent = parent;
server_session->parent = parent; server_session->parent = parent;
return std::make_tuple(std::move(server_session), std::move(client_session)); return std::make_pair(std::move(server_session), std::move(client_session));
} }
} // namespace Kernel } // namespace Kernel

View File

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "core/hle/kernel/object.h" #include "core/hle/kernel/object.h"
@ -58,7 +59,7 @@ public:
return parent.get(); return parent.get();
} }
using SessionPair = std::tuple<SharedPtr<ServerSession>, SharedPtr<ClientSession>>; using SessionPair = std::pair<SharedPtr<ServerSession>, SharedPtr<ClientSession>>;
/** /**
* Creates a pair of ServerSession and an associated ClientSession. * Creates a pair of ServerSession and an associated ClientSession.