mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Detects connection establishment to AdhocServer by combining select and getpeername to increase accuracy.
This commit is contained in:
parent
ff8b5d53f4
commit
a10271dc1d
1 changed files with 15 additions and 4 deletions
|
@ -2221,15 +2221,26 @@ int initNetwork(SceNetAdhocctlAdhocId *adhoc_id){
|
||||||
|
|
||||||
if (iResult == SOCKET_ERROR && errorcode != EISCONN) {
|
if (iResult == SOCKET_ERROR && errorcode != EISCONN) {
|
||||||
u64 startTime = (u64)(time_now_d() * 1000000.0);
|
u64 startTime = (u64)(time_now_d() * 1000000.0);
|
||||||
while (IsSocketReady((int)metasocket, false, true) <= 0) {
|
bool done = false;
|
||||||
u64 now = (u64)(time_now_d() * 1000000.0);
|
while (!done) {
|
||||||
if (coreState == CORE_POWERDOWN)
|
if (coreState == CORE_POWERDOWN)
|
||||||
return iResult;
|
return iResult;
|
||||||
if (static_cast<s64>(now - startTime) > (getSockError((int)metasocket) == EINPROGRESS ? adhocDefaultTimeout*2LL: adhocDefaultTimeout))
|
|
||||||
|
done = (IsSocketReady((int)metasocket, false, true) > 0);
|
||||||
|
struct sockaddr_in sin;
|
||||||
|
socklen_t sinlen = sizeof(sin);
|
||||||
|
memset(&sin, 0, sinlen);
|
||||||
|
// Ensure that the connection really established or not, since "select" alone can't accurately detects it
|
||||||
|
done &= (getpeername((int)metasocket, (struct sockaddr*)&sin, &sinlen) != SOCKET_ERROR);
|
||||||
|
u64 now = (u64)(time_now_d() * 1000000.0);
|
||||||
|
if (static_cast<s64>(now - startTime) > adhocDefaultTimeout) {
|
||||||
|
if (connectInProgress(errorcode))
|
||||||
|
errorcode = ETIMEDOUT;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
sleep_ms(10);
|
sleep_ms(10);
|
||||||
}
|
}
|
||||||
if (IsSocketReady((int)metasocket, false, true) <= 0) {
|
if (!done) {
|
||||||
ERROR_LOG(SCENET, "Socket error (%i) when connecting to AdhocServer [%s/%s:%u]", errorcode, g_Config.proAdhocServer.c_str(), ip2str(g_adhocServerIP.in.sin_addr).c_str(), ntohs(g_adhocServerIP.in.sin_port));
|
ERROR_LOG(SCENET, "Socket error (%i) when connecting to AdhocServer [%s/%s:%u]", errorcode, g_Config.proAdhocServer.c_str(), ip2str(g_adhocServerIP.in.sin_addr).c_str(), ntohs(g_adhocServerIP.in.sin_port));
|
||||||
host->NotifyUserMessage(std::string(n->T("Failed to connect to Adhoc Server")) + " (" + std::string(n->T("Error")) + ": " + std::to_string(errorcode) + ")", 1.0f, 0x0000ff);
|
host->NotifyUserMessage(std::string(n->T("Failed to connect to Adhoc Server")) + " (" + std::string(n->T("Error")) + ": " + std::to_string(errorcode) + ")", 1.0f, 0x0000ff);
|
||||||
return iResult;
|
return iResult;
|
||||||
|
|
Loading…
Add table
Reference in a new issue