mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
htcs: fixes, echo server is now fully functional
This commit is contained in:
parent
72de4d85f3
commit
0ec54ed492
8 changed files with 33 additions and 19 deletions
|
@ -70,11 +70,11 @@ namespace ams::sf::cmif {
|
||||||
|
|
||||||
/* Boolean operators. */
|
/* Boolean operators. */
|
||||||
explicit constexpr operator bool() const {
|
explicit constexpr operator bool() const {
|
||||||
return this->dispatch_meta != nullptr;
|
return this->srv != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator!() const {
|
constexpr bool operator!() const {
|
||||||
return this->dispatch_meta == nullptr;
|
return this->srv == nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getters. */
|
/* Getters. */
|
||||||
|
|
|
@ -221,7 +221,7 @@ namespace ams::htc::server::rpc {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> requires IsRpcTask<T>
|
template<typename T> requires IsRpcTask<T>
|
||||||
Result VerifyTaskIdWitHandle(u32 task_id, s32 handle) {
|
Result VerifyTaskIdWithHandle(u32 task_id, s32 handle) {
|
||||||
/* Lock ourselves. */
|
/* Lock ourselves. */
|
||||||
std::scoped_lock lk(m_mutex);
|
std::scoped_lock lk(m_mutex);
|
||||||
|
|
||||||
|
|
|
@ -119,7 +119,7 @@ namespace ams::htclow::mux {
|
||||||
|
|
||||||
void TaskManager::NotifyReceiveData(impl::ChannelInternalType channel, size_t size) {
|
void TaskManager::NotifyReceiveData(impl::ChannelInternalType channel, size_t size) {
|
||||||
for (auto i = 0; i < MaxTaskCount; ++i) {
|
for (auto i = 0; i < MaxTaskCount; ++i) {
|
||||||
if (m_valid[i] && m_tasks[i].channel == channel && m_tasks[i].size <= size) {
|
if (m_valid[i] && m_tasks[i].channel == channel && m_tasks[i].type == TaskType_Receive && m_tasks[i].size <= size) {
|
||||||
this->CompleteTask(i, EventTrigger_ReceiveData);
|
this->CompleteTask(i, EventTrigger_ReceiveData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,13 @@
|
||||||
*/
|
*/
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
#include "htcs_session.hpp"
|
#include "htcs_session.hpp"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
#include <switch/services/htcs.h>
|
#include <switch/services/htcs.h>
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
namespace ams::htcs::client {
|
namespace ams::htcs::client {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -32,6 +37,10 @@ namespace ams::htcs::client {
|
||||||
}
|
}
|
||||||
} g_static_allocator_initializer;
|
} g_static_allocator_initializer;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
class RemoteSocket {
|
class RemoteSocket {
|
||||||
private:
|
private:
|
||||||
::HtcsSocket m_s;
|
::HtcsSocket m_s;
|
||||||
|
@ -112,6 +121,8 @@ namespace ams::htcs::client {
|
||||||
::HtcsSocket libnx_socket;
|
::HtcsSocket libnx_socket;
|
||||||
R_TRY(::htcsCreateSocket(out_err.GetPointer(), std::addressof(libnx_socket), enable_disconnection_emulation));
|
R_TRY(::htcsCreateSocket(out_err.GetPointer(), std::addressof(libnx_socket), enable_disconnection_emulation));
|
||||||
|
|
||||||
|
R_SUCCEED_IF(*out_err != 0);
|
||||||
|
|
||||||
*out = ObjectFactory::CreateSharedEmplaced<tma::ISocket, RemoteSocket>(libnx_socket);
|
*out = ObjectFactory::CreateSharedEmplaced<tma::ISocket, RemoteSocket>(libnx_socket);
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
@ -160,7 +171,6 @@ namespace ams::htcs::client {
|
||||||
return ::htcsSocketFcntl(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), command, value);
|
return ::htcsSocketFcntl(std::addressof(m_s), out_err.GetPointer(), out_res.GetPointer(), command, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Result RemoteSocket::AcceptStart(sf::Out<u32> out_task_id, sf::OutCopyHandle out_event) {
|
Result RemoteSocket::AcceptStart(sf::Out<u32> out_task_id, sf::OutCopyHandle out_event) {
|
||||||
return ::htcsSocketAcceptStart(std::addressof(m_s), out_task_id.GetPointer(), out_event.GetHandlePointer());
|
return ::htcsSocketAcceptStart(std::addressof(m_s), out_task_id.GetPointer(), out_event.GetHandlePointer());
|
||||||
}
|
}
|
||||||
|
@ -170,6 +180,8 @@ namespace ams::htcs::client {
|
||||||
::HtcsSocket libnx_socket;
|
::HtcsSocket libnx_socket;
|
||||||
R_TRY(::htcsSocketAcceptResults(std::addressof(m_s), out_err.GetPointer(), std::addressof(libnx_socket), reinterpret_cast<::SockAddrHtcs *>(out_address.GetPointer()), task_id));
|
R_TRY(::htcsSocketAcceptResults(std::addressof(m_s), out_err.GetPointer(), std::addressof(libnx_socket), reinterpret_cast<::SockAddrHtcs *>(out_address.GetPointer()), task_id));
|
||||||
|
|
||||||
|
R_SUCCEED_IF(*out_err != 0);
|
||||||
|
|
||||||
*out = ObjectFactory::CreateSharedEmplaced<tma::ISocket, RemoteSocket>(libnx_socket);
|
*out = ObjectFactory::CreateSharedEmplaced<tma::ISocket, RemoteSocket>(libnx_socket);
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,7 +207,6 @@ namespace ams::htcs::client {
|
||||||
error_code = 0;
|
error_code = 0;
|
||||||
|
|
||||||
/* Create the socket. */
|
/* Create the socket. */
|
||||||
sf::SharedPointer<tma::ISocket> socket(nullptr);
|
|
||||||
return this->CreateSocket(sf::SharedPointer<tma::ISocket>{nullptr}, error_code);
|
return this->CreateSocket(sf::SharedPointer<tma::ISocket>{nullptr}, error_code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +578,7 @@ namespace ams::htcs::client {
|
||||||
|
|
||||||
/* Add the socket to the list. */
|
/* Add the socket to the list. */
|
||||||
if (m_list_count != 0) {
|
if (m_list_count != 0) {
|
||||||
/* Ensure the list remains in sorder order. */
|
/* Ensure the list remains in sorted order. */
|
||||||
s32 index;
|
s32 index;
|
||||||
for (index = m_list_count - 1; index >= 0; --index) {
|
for (index = m_list_count - 1; index >= 0; --index) {
|
||||||
if (m_socket_list[index].m_id < id) {
|
if (m_socket_list[index].m_id < id) {
|
||||||
|
@ -687,7 +686,7 @@ namespace ams::htcs::client {
|
||||||
s32 error_code = 0;
|
s32 error_code = 0;
|
||||||
|
|
||||||
/* Get socket. */
|
/* Get socket. */
|
||||||
sf::SharedPointer<tma::ISocket> res = socket(id);
|
sf::SharedPointer<tma::ISocket> res = socket(error_code);
|
||||||
if (res != nullptr) {
|
if (res != nullptr) {
|
||||||
/* Assign the new socket. */
|
/* Assign the new socket. */
|
||||||
s32 index;
|
s32 index;
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_desc = desc;
|
*out_desc = desc;
|
||||||
} else {
|
} else {
|
||||||
*out_desc = -1;
|
*out_desc = -1;
|
||||||
|
@ -77,7 +77,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_res = 0;
|
*out_res = 0;
|
||||||
} else {
|
} else {
|
||||||
*out_res = -1;
|
*out_res = -1;
|
||||||
|
@ -96,7 +96,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_res = 0;
|
*out_res = 0;
|
||||||
} else {
|
} else {
|
||||||
*out_res = -1;
|
*out_res = -1;
|
||||||
|
@ -115,7 +115,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_res = 0;
|
*out_res = 0;
|
||||||
} else {
|
} else {
|
||||||
*out_res = -1;
|
*out_res = -1;
|
||||||
|
@ -135,7 +135,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_size = recv_size;
|
*out_size = recv_size;
|
||||||
} else {
|
} else {
|
||||||
*out_size = -1;
|
*out_size = -1;
|
||||||
|
@ -155,7 +155,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_size = send_size;
|
*out_size = send_size;
|
||||||
} else {
|
} else {
|
||||||
*out_size = -1;
|
*out_size = -1;
|
||||||
|
@ -174,7 +174,7 @@ namespace ams::htcs::impl {
|
||||||
/* Set output. */
|
/* Set output. */
|
||||||
if (R_SUCCEEDED(result)) {
|
if (R_SUCCEEDED(result)) {
|
||||||
*out_err = err;
|
*out_err = err;
|
||||||
if (out_err == 0) {
|
if (err == 0) {
|
||||||
*out_res = 0;
|
*out_res = 0;
|
||||||
} else {
|
} else {
|
||||||
*out_res = -1;
|
*out_res = -1;
|
||||||
|
|
|
@ -259,7 +259,7 @@ namespace ams::htcs::impl {
|
||||||
|
|
||||||
Result HtcsService::SendSmallContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
Result HtcsService::SendSmallContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
||||||
/* Verify the task. */
|
/* Verify the task. */
|
||||||
R_TRY(m_rpc_client->VerifyTaskIdWitHandle<rpc::SendSmallTask>(task_id, desc));
|
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::SendSmallTask>(task_id, desc));
|
||||||
|
|
||||||
/* Continue the task. */
|
/* Continue the task. */
|
||||||
R_TRY(m_rpc_client->SendContinue<rpc::SendSmallTask>(task_id, buffer, buffer_size));
|
R_TRY(m_rpc_client->SendContinue<rpc::SendSmallTask>(task_id, buffer, buffer_size));
|
||||||
|
@ -293,7 +293,7 @@ namespace ams::htcs::impl {
|
||||||
|
|
||||||
Result HtcsService::SendContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
Result HtcsService::SendContinue(s64 *out_size, const char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
||||||
/* Verify the task. */
|
/* Verify the task. */
|
||||||
R_TRY(m_rpc_client->VerifyTaskIdWitHandle<rpc::SendTask>(task_id, desc));
|
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::SendTask>(task_id, desc));
|
||||||
|
|
||||||
/* Wait for the task to notify. */
|
/* Wait for the task to notify. */
|
||||||
m_rpc_client->WaitNotification<rpc::SendTask>(task_id);
|
m_rpc_client->WaitNotification<rpc::SendTask>(task_id);
|
||||||
|
@ -307,12 +307,14 @@ namespace ams::htcs::impl {
|
||||||
R_TRY(m_data_channel_manager->Send(buffer, buffer_size, task_id));
|
R_TRY(m_data_channel_manager->Send(buffer, buffer_size, task_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set output. */
|
||||||
|
*out_size = buffer_size;
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result HtcsService::SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) {
|
Result HtcsService::SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) {
|
||||||
/* Verify the task. */
|
/* Verify the task. */
|
||||||
R_TRY(m_rpc_client->VerifyTaskIdWitHandle<rpc::SendTask>(task_id, desc));
|
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::SendTask>(task_id, desc));
|
||||||
|
|
||||||
/* Finish the task. */
|
/* Finish the task. */
|
||||||
htcs::SocketError err;
|
htcs::SocketError err;
|
||||||
|
@ -337,7 +339,7 @@ namespace ams::htcs::impl {
|
||||||
|
|
||||||
Result HtcsService::ReceiveResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
Result HtcsService::ReceiveResults(s32 *out_err, s64 *out_size, char *buffer, s64 buffer_size, u32 task_id, s32 desc) {
|
||||||
/* Verify the task. */
|
/* Verify the task. */
|
||||||
R_TRY(m_rpc_client->VerifyTaskIdWitHandle<rpc::ReceiveTask>(task_id, desc));
|
R_TRY(m_rpc_client->VerifyTaskIdWithHandle<rpc::ReceiveTask>(task_id, desc));
|
||||||
|
|
||||||
/* Get the result. */
|
/* Get the result. */
|
||||||
htcs::SocketError err;
|
htcs::SocketError err;
|
||||||
|
|
|
@ -209,6 +209,7 @@ namespace ams::sf::hipc {
|
||||||
this->CloseSessionImpl(session);
|
this->CloseSessionImpl(session);
|
||||||
return ResultSuccess();
|
return ResultSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (GetCmifCommandType(message)) {
|
switch (GetCmifCommandType(message)) {
|
||||||
case CmifCommandType_Close:
|
case CmifCommandType_Close:
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue