htcs: hook up CreateSocket/RpcClient Begin<>/End<>

This commit is contained in:
Michael Scire
2021-02-17 23:28:05 -08:00
committed by SciresM
parent abff428212
commit 536e3e99a8
9 changed files with 235 additions and 14 deletions

View File

@@ -220,7 +220,7 @@ namespace ams::htcs::impl {
} else {
if (htc::ResultCancelled::Includes(result)) {
*out_err = HTCS_ENETDOWN;
} else if (htc::ResultUnknown2033::Includes(result)) {
} else if (htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_err = HTCS_EINTR;
} else {
*out_err = ConvertResultToErrorCode(result);
@@ -247,7 +247,7 @@ namespace ams::htcs::impl {
*out_size = -1;
}
} else {
if (htc::ResultUnknown2033::Includes(result)) {
if (htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_err = HTCS_EINTR;
} else {
*out_err = ConvertResultToErrorCode(result);
@@ -279,7 +279,7 @@ namespace ams::htcs::impl {
*out_size = -1;
}
} else {
if (htc::ResultUnknown2033::Includes(result)) {
if (htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_err = HTCS_EINTR;
} else {
*out_err = ConvertResultToErrorCode(result);
@@ -320,7 +320,7 @@ namespace ams::htcs::impl {
*out_size = -1;
}
} else {
if (htc::ResultUnknown2033::Includes(result)) {
if (htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_err = HTCS_EINTR;
} else {
*out_err = ConvertResultToErrorCode(result);
@@ -348,7 +348,7 @@ namespace ams::htcs::impl {
*out_size = -1;
}
} else {
if (htc::ResultCancelled::Includes(result) || htc::ResultUnknown2033::Includes(result)) {
if (htc::ResultCancelled::Includes(result) || htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_err = 0;
} else {
*out_err = ConvertResultToErrorCode(result);

View File

@@ -107,7 +107,7 @@ namespace ams::htcs::impl {
/* Continue the send. */
s64 continue_size;
const Result result = m_service.SendSmallContinue(std::addressof(continue_size), buffer, size, task_id, desc);
if (R_SUCCEEDED(result) || htcs::ResultUnknown2023::Includes(result) || htc::ResultUnknown2033::Includes(result)) {
if (R_SUCCEEDED(result) || htcs::ResultUnknown2023::Includes(result) || htc::ResultTaskQueueNotAvailable::Includes(result)) {
*out_task_id = task_id;
*out_handle = handle;
} else {

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#include "htcs_service.hpp"
#include "rpc/htcs_rpc_tasks.hpp"
namespace ams::htcs::impl {
void HtcsService::WaitTask(u32 task_id) {
return m_rpc_client->Wait(task_id);
}
Result HtcsService::CreateSocket(s32 *out_err, s32 *out_desc, bool enable_disconnection_emulation) {
/* Set disconnection emulation enabled. */
m_driver->SetDisconnectionEmulationEnabled(enable_disconnection_emulation);
/* Begin the task. */
u32 task_id;
R_TRY(m_rpc_client->Begin<rpc::SocketTask>(std::addressof(task_id)));
/* Wait for the task to complete. */
this->WaitTask(task_id);
/* Finish the task. */
htcs::SocketError err;
s32 desc;
R_TRY(m_rpc_client->End<rpc::SocketTask>(task_id, std::addressof(err), std::addressof(desc)));
/* Set output. */
*out_err = err;
*out_desc = desc;
return ResultSuccess();
}
}

View File

@@ -62,6 +62,8 @@ namespace ams::htcs::impl {
Result SelectStart(u32 *out_task_id, Handle *out_handle, Span<const int> read_handles, Span<const int> write_handles, Span<const int> exception_handles, s64 tv_sec, s64 tv_usec);
Result SelectEnd(s32 *out_err, s32 *out_res, Span<int> read_handles, Span<int> write_handles, Span<int> exception_handles, u32 task_id);
private:
void WaitTask(u32 task_id);
};
}

View File

@@ -32,7 +32,7 @@ namespace ams::htcs::impl {
R_CATCH(htc::ResultUnknown2021) { return HTCS_EINTR; }
R_CATCH(htc::ResultInvalidTaskId) { return HTCS_EINTR; }
R_CATCH(htc::ResultCancelled) { return HTCS_EINTR; }
R_CATCH(htc::ResultUnknown2033) { return HTCS_ENETDOWN; }
R_CATCH(htc::ResultTaskQueueNotAvailable) { return HTCS_ENETDOWN; }
R_CATCH(htclow::ResultConnectionFailure) { return HTCS_ENETDOWN; }
R_CATCH(htclow::ResultChannelNotExist) { return HTCS_ENOTCONN; }
R_CATCH_ALL() { return HTCS_EUNKNOWN; }

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 2018-2020 Atmosphère-NX
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
#include "../../../htc/server/rpc/htc_rpc_tasks.hpp"
namespace ams::htcs::impl::rpc {
enum class HtcsTaskType {
Receive = 0,
Send = 1,
Shutdown = 2,
Close = 3,
Connect = 4,
Listen = 5,
Accept = 6,
Socket = 7,
Bind = 8,
Fcntl = 9,
ReceiveSmall = 10,
SendSmall = 11,
Select = 12,
};
constexpr inline const s16 ProtocolVersion = 4;
class HtcsTask : public htc::server::rpc::Task {
private:
HtcsTaskType m_task_type;
s16 m_version;
public:
HtcsTask(HtcsTaskType type) : m_task_type(type), m_version(ProtocolVersion) { /* ... */ }
HtcsTaskType GetTaskType() const { return m_task_type; }
s16 GetVersion() const { return m_version; }
};
class SocketTask : public HtcsTask {
private:
htcs::SocketError m_err;
s32 m_desc;
public:
SocketTask() : HtcsTask(HtcsTaskType::Socket) { /* ... */ }
Result SetArguments();
void Complete(htcs::SocketError err, s32 desc);
Result GetResult(htcs::SocketError *out_err, s32 *out_desc);
public:
virtual Result ProcessResponse(const char *data, size_t size) override;
virtual Result CreateRequest(size_t *out, char *data, size_t size, u32 task_id) override;
};
}