Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminate RPCN connection cleanly #15121

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions rpcs3/Emu/NP/rpcn_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ namespace rpcn

rpcn_client::~rpcn_client()
{
terminate_connection();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why bool if it's unused?

std::lock_guard lock(inst_mutex);
terminate = true;
sem_rpcn.release();
Expand Down Expand Up @@ -414,7 +415,7 @@ namespace rpcn
command == CommandType::AddBlock || command == CommandType::RemoveBlock ||
command == CommandType::SendMessage || command == CommandType::SendToken ||
command == CommandType::SendResetToken || command == CommandType::ResetPassword ||
command == CommandType::GetNetworkTime || command == CommandType::SetPresence)
command == CommandType::GetNetworkTime || command == CommandType::SetPresence || command == CommandType::Terminate)
{
std::lock_guard lock(mutex_replies_sync);
replies_sync.insert(std::make_pair(packet_id, std::make_pair(command, std::move(data))));
Expand Down Expand Up @@ -574,23 +575,20 @@ namespace rpcn
if (res == 0)
{
// Remote closed connection
rpcn_log.error("recv failed: connection reset by server");
rpcn_log.notice("recv failed: connection reset by server");
return recvn_result::recvn_noconn;
}

rpcn_log.error("recvn failed with error: %d:%s(native: %d)", res, get_wolfssl_error(read_wssl, res), get_native_error());
return recvn_result::recvn_fatal;
}

res = 0;
}
else
{
// Reset timeout each time something is received
num_timeouts = 0;
n_recv += res;
}

n_recv += res;
}

return recvn_result::recvn_success;
Expand Down Expand Up @@ -1017,6 +1015,21 @@ namespace rpcn
return true;
}

bool rpcn_client::terminate_connection()
{
u64 req_id = rpcn_request_counter.fetch_add(1);

std::vector<u8> packet_data;
std::vector<u8> data;

if (!forge_send_reply(CommandType::Terminate, req_id, data, packet_data))
{
return false;
}

return true;
}

ErrorType rpcn_client::create_user(std::string_view npid, std::string_view password, std::string_view online_name, std::string_view avatar_url, std::string_view email)
{
std::vector<u8> data;
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/NP/rpcn_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ namespace rpcn
static std::shared_ptr<rpcn_client> get_instance(bool check_config = false);
rpcn_state wait_for_connection();
rpcn_state wait_for_authentified();
bool terminate_connection();

void get_friends_and_register_cb(friend_data& friend_infos, friend_cb_func cb_func, void* cb_param);
void remove_friend_cb(friend_cb_func, void* cb_param);
Expand Down