mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 12:21:18 +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. */
|
||||
explicit constexpr operator bool() const {
|
||||
return this->dispatch_meta != nullptr;
|
||||
return this->srv != nullptr;
|
||||
}
|
||||
|
||||
constexpr bool operator!() const {
|
||||
return this->dispatch_meta == nullptr;
|
||||
return this->srv == nullptr;
|
||||
}
|
||||
|
||||
/* Getters. */
|
||||
|
|
|
@ -221,7 +221,7 @@ namespace ams::htc::server::rpc {
|
|||
}
|
||||
|
||||
template<typename T> requires IsRpcTask<T>
|
||||
Result VerifyTaskIdWitHandle(u32 task_id, s32 handle) {
|
||||
Result VerifyTaskIdWithHandle(u32 task_id, s32 handle) {
|
||||
/* Lock ourselves. */
|
||||
std::scoped_lock lk(m_mutex);
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ namespace ams::htclow::mux {
|
|||
|
||||
void TaskManager::NotifyReceiveData(impl::ChannelInternalType channel, size_t size) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,13 @@
|
|||
*/
|
||||
#include <stratosphere.hpp>
|
||||
#include "htcs_session.hpp"
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include <switch/services/htcs.h>
|
||||
|
||||
}
|
||||
|
||||
namespace ams::htcs::client {
|
||||
|
||||
namespace {
|
||||
|
@ -32,6 +37,10 @@ namespace ams::htcs::client {
|
|||
}
|
||||
} g_static_allocator_initializer;
|
||||
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
class RemoteSocket {
|
||||
private:
|
||||
::HtcsSocket m_s;
|
||||
|
@ -112,6 +121,8 @@ namespace ams::htcs::client {
|
|||
::HtcsSocket libnx_socket;
|
||||
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);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
@ -160,7 +171,6 @@ namespace ams::htcs::client {
|
|||
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) {
|
||||
return ::htcsSocketAcceptStart(std::addressof(m_s), out_task_id.GetPointer(), out_event.GetHandlePointer());
|
||||
}
|
||||
|
@ -170,6 +180,8 @@ namespace ams::htcs::client {
|
|||
::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_SUCCEED_IF(*out_err != 0);
|
||||
|
||||
*out = ObjectFactory::CreateSharedEmplaced<tma::ISocket, RemoteSocket>(libnx_socket);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
|
|
@ -207,7 +207,6 @@ namespace ams::htcs::client {
|
|||
error_code = 0;
|
||||
|
||||
/* Create the socket. */
|
||||
sf::SharedPointer<tma::ISocket> socket(nullptr);
|
||||
return this->CreateSocket(sf::SharedPointer<tma::ISocket>{nullptr}, error_code);
|
||||
}
|
||||
|
||||
|
@ -579,7 +578,7 @@ namespace ams::htcs::client {
|
|||
|
||||
/* Add the socket to the list. */
|
||||
if (m_list_count != 0) {
|
||||
/* Ensure the list remains in sorder order. */
|
||||
/* Ensure the list remains in sorted order. */
|
||||
s32 index;
|
||||
for (index = m_list_count - 1; index >= 0; --index) {
|
||||
if (m_socket_list[index].m_id < id) {
|
||||
|
@ -687,7 +686,7 @@ namespace ams::htcs::client {
|
|||
s32 error_code = 0;
|
||||
|
||||
/* Get socket. */
|
||||
sf::SharedPointer<tma::ISocket> res = socket(id);
|
||||
sf::SharedPointer<tma::ISocket> res = socket(error_code);
|
||||
if (res != nullptr) {
|
||||
/* Assign the new socket. */
|
||||
s32 index;
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_desc = desc;
|
||||
} else {
|
||||
*out_desc = -1;
|
||||
|
@ -77,7 +77,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_res = 0;
|
||||
} else {
|
||||
*out_res = -1;
|
||||
|
@ -96,7 +96,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_res = 0;
|
||||
} else {
|
||||
*out_res = -1;
|
||||
|
@ -115,7 +115,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_res = 0;
|
||||
} else {
|
||||
*out_res = -1;
|
||||
|
@ -135,7 +135,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_size = recv_size;
|
||||
} else {
|
||||
*out_size = -1;
|
||||
|
@ -155,7 +155,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_size = send_size;
|
||||
} else {
|
||||
*out_size = -1;
|
||||
|
@ -174,7 +174,7 @@ namespace ams::htcs::impl {
|
|||
/* Set output. */
|
||||
if (R_SUCCEEDED(result)) {
|
||||
*out_err = err;
|
||||
if (out_err == 0) {
|
||||
if (err == 0) {
|
||||
*out_res = 0;
|
||||
} else {
|
||||
*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) {
|
||||
/* 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. */
|
||||
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) {
|
||||
/* 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. */
|
||||
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));
|
||||
}
|
||||
|
||||
/* Set output. */
|
||||
*out_size = buffer_size;
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result HtcsService::SendResults(s32 *out_err, s64 *out_size, u32 task_id, s32 desc) {
|
||||
/* 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. */
|
||||
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) {
|
||||
/* 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. */
|
||||
htcs::SocketError err;
|
||||
|
|
|
@ -209,6 +209,7 @@ namespace ams::sf::hipc {
|
|||
this->CloseSessionImpl(session);
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
switch (GetCmifCommandType(message)) {
|
||||
case CmifCommandType_Close:
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue