Skip to content

Commit

Permalink
Terminate RPCN connection cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
RipleyTom authored and Megamouse committed Jan 29, 2024
1 parent a7da245 commit af8d308
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
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();
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

0 comments on commit af8d308

Please sign in to comment.