diff options
| author | 2016-12-08 15:01:10 -0500 | |
|---|---|---|
| committer | 2016-12-08 15:01:10 -0500 | |
| commit | 386112da3265d111595329508b860800e5cf14e8 (patch) | |
| tree | 7cb27e289abd255ff7f371eff0f9d1ddd07b5d11 /src/core/hle/kernel | |
| parent | Use std::move where appropriate. (diff) | |
| download | yuzu-386112da3265d111595329508b860800e5cf14e8.tar.gz yuzu-386112da3265d111595329508b860800e5cf14e8.tar.xz yuzu-386112da3265d111595329508b860800e5cf14e8.zip | |
Added a framework for partially handling Session disconnections.
Further implementation will happen in a future commit.
Fixes a regression.
Diffstat (limited to 'src/core/hle/kernel')
| -rw-r--r-- | src/core/hle/kernel/client_port.cpp | 8 | ||||
| -rw-r--r-- | src/core/hle/kernel/client_session.cpp | 15 | ||||
| -rw-r--r-- | src/core/hle/kernel/client_session.h | 11 | ||||
| -rw-r--r-- | src/core/hle/kernel/server_session.cpp | 10 |
4 files changed, 35 insertions, 9 deletions
diff --git a/src/core/hle/kernel/client_port.cpp b/src/core/hle/kernel/client_port.cpp index 20179e546..bd8ef055d 100644 --- a/src/core/hle/kernel/client_port.cpp +++ b/src/core/hle/kernel/client_port.cpp | |||
| @@ -19,9 +19,10 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { | |||
| 19 | // AcceptSession before returning from this call. | 19 | // AcceptSession before returning from this call. |
| 20 | 20 | ||
| 21 | if (active_sessions >= max_sessions) { | 21 | if (active_sessions >= max_sessions) { |
| 22 | return ResultCode(ErrorDescription::MaxConnectionsReached, | 22 | // TODO(Subv): Return an error code in this situation after session disconnection is implemented. |
| 23 | /*return ResultCode(ErrorDescription::MaxConnectionsReached, | ||
| 23 | ErrorModule::OS, ErrorSummary::WouldBlock, | 24 | ErrorModule::OS, ErrorSummary::WouldBlock, |
| 24 | ErrorLevel::Temporary); | 25 | ErrorLevel::Temporary);*/ |
| 25 | } | 26 | } |
| 26 | active_sessions++; | 27 | active_sessions++; |
| 27 | 28 | ||
| @@ -30,6 +31,9 @@ ResultVal<SharedPtr<ClientSession>> ClientPort::Connect() { | |||
| 30 | auto client_session = std::get<SharedPtr<ClientSession>>(sessions); | 31 | auto client_session = std::get<SharedPtr<ClientSession>>(sessions); |
| 31 | auto server_session = std::get<SharedPtr<ServerSession>>(sessions); | 32 | auto server_session = std::get<SharedPtr<ServerSession>>(sessions); |
| 32 | 33 | ||
| 34 | if (server_port->hle_handler) | ||
| 35 | server_port->hle_handler->ClientConnected(server_session); | ||
| 36 | |||
| 33 | server_port->pending_sessions.push_back(std::move(server_session)); | 37 | server_port->pending_sessions.push_back(std::move(server_session)); |
| 34 | 38 | ||
| 35 | // Wake the threads waiting on the ServerPort | 39 | // Wake the threads waiting on the ServerPort |
diff --git a/src/core/hle/kernel/client_session.cpp b/src/core/hle/kernel/client_session.cpp index 30ef10764..17302baca 100644 --- a/src/core/hle/kernel/client_session.cpp +++ b/src/core/hle/kernel/client_session.cpp | |||
| @@ -10,13 +10,22 @@ | |||
| 10 | namespace Kernel { | 10 | namespace Kernel { |
| 11 | 11 | ||
| 12 | ClientSession::ClientSession() = default; | 12 | ClientSession::ClientSession() = default; |
| 13 | ClientSession::~ClientSession() = default; | 13 | ClientSession::~ClientSession() { |
| 14 | // This destructor will be called automatically when the last ClientSession handle is closed by the emulated application. | ||
| 14 | 15 | ||
| 15 | ResultVal<SharedPtr<ClientSession>> ClientSession::Create(SharedPtr<ServerSession> server_session, std::string name) { | 16 | if (server_session->hle_handler) |
| 17 | server_session->hle_handler->ClientDisconnected(server_session); | ||
| 18 | |||
| 19 | // TODO(Subv): If the session is still open, set the connection status to 2 (Closed by client), | ||
| 20 | // wake up all the ServerSession's waiting threads and set the WaitSynchronization result to 0xC920181A. | ||
| 21 | } | ||
| 22 | |||
| 23 | ResultVal<SharedPtr<ClientSession>> ClientSession::Create(ServerSession* server_session, std::string name) { | ||
| 16 | SharedPtr<ClientSession> client_session(new ClientSession); | 24 | SharedPtr<ClientSession> client_session(new ClientSession); |
| 17 | 25 | ||
| 18 | client_session->name = std::move(name); | 26 | client_session->name = std::move(name); |
| 19 | client_session->server_session = std::move(server_session); | 27 | client_session->server_session = server_session; |
| 28 | client_session->session_status = SessionStatus::Open; | ||
| 20 | return MakeResult<SharedPtr<ClientSession>>(std::move(client_session)); | 29 | return MakeResult<SharedPtr<ClientSession>>(std::move(client_session)); |
| 21 | } | 30 | } |
| 22 | 31 | ||
diff --git a/src/core/hle/kernel/client_session.h b/src/core/hle/kernel/client_session.h index 45f479901..fedbd0625 100644 --- a/src/core/hle/kernel/client_session.h +++ b/src/core/hle/kernel/client_session.h | |||
| @@ -15,6 +15,12 @@ namespace Kernel { | |||
| 15 | 15 | ||
| 16 | class ServerSession; | 16 | class ServerSession; |
| 17 | 17 | ||
| 18 | enum class SessionStatus { | ||
| 19 | Open = 1, | ||
| 20 | ClosedByClient = 2, | ||
| 21 | ClosedBYServer = 3, | ||
| 22 | }; | ||
| 23 | |||
| 18 | class ClientSession final : public Object { | 24 | class ClientSession final : public Object { |
| 19 | public: | 25 | public: |
| 20 | friend class ServerSession; | 26 | friend class ServerSession; |
| @@ -39,7 +45,8 @@ public: | |||
| 39 | ResultCode SendSyncRequest(); | 45 | ResultCode SendSyncRequest(); |
| 40 | 46 | ||
| 41 | std::string name; ///< Name of client port (optional) | 47 | std::string name; ///< Name of client port (optional) |
| 42 | SharedPtr<ServerSession> server_session; ///< The server session associated with this client session. | 48 | ServerSession* server_session; ///< The server session associated with this client session. |
| 49 | SessionStatus session_status; ///< The session's current status. | ||
| 43 | 50 | ||
| 44 | private: | 51 | private: |
| 45 | ClientSession(); | 52 | ClientSession(); |
| @@ -51,7 +58,7 @@ private: | |||
| 51 | * @param name Optional name of client session | 58 | * @param name Optional name of client session |
| 52 | * @return The created client session | 59 | * @return The created client session |
| 53 | */ | 60 | */ |
| 54 | static ResultVal<SharedPtr<ClientSession>> Create(SharedPtr<ServerSession> server_session, std::string name = "Unknown"); | 61 | static ResultVal<SharedPtr<ClientSession>> Create(ServerSession* server_session, std::string name = "Unknown"); |
| 55 | }; | 62 | }; |
| 56 | 63 | ||
| 57 | } // namespace | 64 | } // namespace |
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp index f8bccadfd..3fac6b934 100644 --- a/src/core/hle/kernel/server_session.cpp +++ b/src/core/hle/kernel/server_session.cpp | |||
| @@ -11,7 +11,11 @@ | |||
| 11 | namespace Kernel { | 11 | namespace Kernel { |
| 12 | 12 | ||
| 13 | ServerSession::ServerSession() = default; | 13 | ServerSession::ServerSession() = default; |
| 14 | ServerSession::~ServerSession() = default; | 14 | ServerSession::~ServerSession() { |
| 15 | // This destructor will be called automatically when the last ServerSession handle is closed by the emulated application. | ||
| 16 | // TODO(Subv): Reduce the ClientPort's connection count, | ||
| 17 | // if the session is still open, set the connection status to 3 (Closed by server), | ||
| 18 | } | ||
| 15 | 19 | ||
| 16 | ResultVal<SharedPtr<ServerSession>> ServerSession::Create(std::string name, std::shared_ptr<Service::SessionRequestHandler> hle_handler) { | 20 | ResultVal<SharedPtr<ServerSession>> ServerSession::Create(std::string name, std::shared_ptr<Service::SessionRequestHandler> hle_handler) { |
| 17 | SharedPtr<ServerSession> server_session(new ServerSession); | 21 | SharedPtr<ServerSession> server_session(new ServerSession); |
| @@ -49,7 +53,9 @@ ResultCode ServerSession::HandleSyncRequest() { | |||
| 49 | ServerSession::SessionPair ServerSession::CreateSessionPair(const std::string& name, | 53 | ServerSession::SessionPair ServerSession::CreateSessionPair(const std::string& name, |
| 50 | std::shared_ptr<Service::SessionRequestHandler> hle_handler) { | 54 | std::shared_ptr<Service::SessionRequestHandler> hle_handler) { |
| 51 | auto server_session = ServerSession::Create(name + "_Server", std::move(hle_handler)).MoveFrom(); | 55 | auto server_session = ServerSession::Create(name + "_Server", std::move(hle_handler)).MoveFrom(); |
| 52 | auto client_session = ClientSession::Create(server_session, name + "_Client").MoveFrom(); | 56 | // We keep a non-owning pointer to the ServerSession in the ClientSession because we don't want to prevent the |
| 57 | // ServerSession's destructor from being called when the emulated application closes the last ServerSession handle. | ||
| 58 | auto client_session = ClientSession::Create(server_session.get(), name + "_Client").MoveFrom(); | ||
| 53 | 59 | ||
| 54 | return std::make_tuple(std::move(server_session), std::move(client_session)); | 60 | return std::make_tuple(std::move(server_session), std::move(client_session)); |
| 55 | } | 61 | } |