Added a framework for partially handling Session disconnections.

Further implementation will happen in a future commit.

Fixes a regression.
This commit is contained in:
Subv 2016-12-08 15:01:10 -05:00
parent f9bcf89510
commit 386112da32
8 changed files with 67 additions and 9 deletions

View file

@ -174,6 +174,7 @@ void File::HandleSyncRequestImpl(Kernel::SharedPtr<Kernel::ServerSession> server
case FileCommand::OpenLinkFile: {
LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str());
auto sessions = Kernel::ServerSession::CreateSessionPair(GetName(), shared_from_this());
ClientConnected(std::get<Kernel::SharedPtr<Kernel::ServerSession>>(sessions));
cmd_buff[3] = Kernel::g_handle_table.Create(std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions)).ValueOr(INVALID_HANDLE);
break;
}

View file

@ -73,6 +73,7 @@ static void OpenFile(Service::Interface* self) {
if (file_res.Succeeded()) {
std::shared_ptr<File> file = *file_res;
auto sessions = ServerSession::CreateSessionPair(file->GetName(), file);
file->ClientConnected(std::get<Kernel::SharedPtr<Kernel::ServerSession>>(sessions));
cmd_buff[3] = Kernel::g_handle_table.Create(std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions)).MoveFrom();
} else {
cmd_buff[3] = 0;
@ -135,6 +136,7 @@ static void OpenFileDirectly(Service::Interface* self) {
if (file_res.Succeeded()) {
std::shared_ptr<File> file = *file_res;
auto sessions = ServerSession::CreateSessionPair(file->GetName(), file);
file->ClientConnected(std::get<Kernel::SharedPtr<Kernel::ServerSession>>(sessions));
cmd_buff[3] = Kernel::g_handle_table.Create(std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions)).MoveFrom();
} else {
cmd_buff[3] = 0;
@ -398,6 +400,7 @@ static void OpenDirectory(Service::Interface* self) {
if (dir_res.Succeeded()) {
std::shared_ptr<Directory> directory = *dir_res;
auto sessions = ServerSession::CreateSessionPair(directory->GetName(), directory);
directory->ClientConnected(std::get<Kernel::SharedPtr<Kernel::ServerSession>>(sessions));
cmd_buff[3] = Kernel::g_handle_table.Create(std::get<Kernel::SharedPtr<Kernel::ClientSession>>(sessions)).MoveFrom();
} else {
LOG_ERROR(Service_FS, "failed to get a handle for directory type=%d size=%d data=%s",

View file

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/range/algorithm_ext/erase.hpp>
#include "common/logging/log.h"
#include "common/string_util.h"
@ -79,6 +81,14 @@ ResultCode SessionRequestHandler::HandleSyncRequest(Kernel::SharedPtr<Kernel::Se
return RESULT_SUCCESS;
}
void SessionRequestHandler::ClientConnected(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
connected_sessions.push_back(server_session);
}
void SessionRequestHandler::ClientDisconnected(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
boost::range::remove_erase(connected_sessions, server_session);
}
ResultCode SessionRequestHandler::TranslateRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) {
// TODO(Subv): Implement this function once multiple concurrent processes are supported.
return RESULT_SUCCESS;

View file

@ -38,6 +38,20 @@ public:
*/
ResultCode HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session);
/**
* Signals that a client has just connected to this HLE handler and keeps the
* associated ServerSession alive for the duration of the connection.
* @param server_session Owning pointer to the ServerSession associated with the connection.
*/
void ClientConnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
/**
* Signals that a client has just disconnected from this HLE handler and releases the
* associated ServerSession.
* @param server_session ServerSession associated with the connection.
*/
void ClientDisconnected(Kernel::SharedPtr<Kernel::ServerSession> server_session);
protected:
/**
* Handles a sync request from the emulated application and writes the response to the command buffer.
@ -55,6 +69,10 @@ private:
* but once that is implemented we'll need to properly translate all descriptors in the command buffer.
*/
ResultCode TranslateRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session);
/// List of sessions that are connected to this handler.
/// A ServerSession whose server endpoint is an HLE implementation is kept alive by this list for the duration of the connection.
std::vector<Kernel::SharedPtr<Kernel::ServerSession>> connected_sessions;
};
/**