Skip to content

Commit

Permalink
Avoid using getaddrinfo during initialization as it could blocked the…
Browse files Browse the repository at this point in the history
… thread if there is no network
  • Loading branch information
anr2me committed Aug 19, 2020
1 parent 0752e7d commit 0298f59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
20 changes: 3 additions & 17 deletions Core/HLE/sceNet.cpp
Expand Up @@ -113,30 +113,16 @@ void AfterApctlMipsCall::SetData(int HandlerID, int OldState, int NewState, int
argsAddr = ArgsAddr;
}

static int InitLocalhostIP() {
void InitLocalhostIP() {
// The entire 127.*.*.* is reserved for loopback.
uint32_t localIP = 0x7F000001 + PPSSPP_ID - 1;

g_localhostIP.in.sin_family = AF_INET;
g_localhostIP.in.sin_addr.s_addr = htonl(localIP);
g_localhostIP.in.sin_port = 0;

// If lookup fails, we'll assume it's not local.
isLocalServer = false;

addrinfo *resultAddr = nullptr;
std::string error;
if (net::DNSResolve(g_Config.proAdhocServer, "", &resultAddr, error, net::DNSType::IPV4)) {
for (addrinfo *ptr = resultAddr; ptr != nullptr; ptr = ptr->ai_next) {
auto addr4 = ((sockaddr_in *)ptr->ai_addr)->sin_addr.s_addr;
isLocalServer = (ntohl(addr4) & 0x7F000000) == 0x7F000000;
}

net::DNSResolveFree(resultAddr);
resultAddr = nullptr;
}

return 0;
std::string serverStr = StripSpaces(g_Config.proAdhocServer);
isLocalServer = (!strcasecmp(serverStr.c_str(), "localhost") || serverStr.find("127.") == 0);
}

void __NetApctlInit() {
Expand Down
2 changes: 1 addition & 1 deletion UI/GameSettingsScreen.cpp
Expand Up @@ -1930,7 +1930,7 @@ bool HostnameSelectScreen::CanComplete(DialogResult result) {

void HostnameSelectScreen::OnCompleted(DialogResult result) {
if (result == DR_OK)
*value_ = addrView_->GetText();
*value_ = StripSpaces(addrView_->GetText());
}

SettingInfoMessage::SettingInfoMessage(int align, UI::AnchorLayoutParams *lp)
Expand Down

0 comments on commit 0298f59

Please sign in to comment.