mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
http: Fix errors on connect.
This commit is contained in:
parent
7dc18a94af
commit
4a2cd1bb7b
1 changed files with 17 additions and 5 deletions
|
@ -30,6 +30,7 @@
|
|||
#include "Common/Net/URL.h"
|
||||
|
||||
#include "Common/File/FileDescriptor.h"
|
||||
#include "Common/SysError.h"
|
||||
#include "Common/Thread/ThreadUtil.h"
|
||||
#include "Common/Data/Encoding/Compression.h"
|
||||
#include "Common/Net/NetBuffer.h"
|
||||
|
@ -97,7 +98,7 @@ static void FormatAddr(char *addrbuf, size_t bufsize, const addrinfo *info) {
|
|||
switch (info->ai_family) {
|
||||
case AF_INET:
|
||||
case AF_INET6:
|
||||
inet_ntop(info->ai_family, info->ai_addr, addrbuf, bufsize);
|
||||
inet_ntop(info->ai_family, &((sockaddr_in *)info->ai_addr)->sin_addr, addrbuf, bufsize);
|
||||
break;
|
||||
default:
|
||||
snprintf(addrbuf, bufsize, "(Unknown AF %d)", info->ai_family);
|
||||
|
@ -131,11 +132,22 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
|
|||
// Start trying to connect (async with timeout.)
|
||||
errno = 0;
|
||||
if (connect(sock, possible->ai_addr, (int)possible->ai_addrlen) < 0) {
|
||||
if (errno != 0 && errno != EINPROGRESS) {
|
||||
char addrStr[128];
|
||||
#if PPSSPP_PLATFORM(WINDOWS)
|
||||
int errorCode = WSAGetLastError();
|
||||
std::string errorString = GetStringErrorMsg(errorCode);
|
||||
bool unreachable = errorCode == WSAENETUNREACH;
|
||||
bool inProgress = errorCode == WSAEINPROGRESS || errorCode == WSAEWOULDBLOCK;
|
||||
#else
|
||||
int errorCode = errno;
|
||||
std::string errorString = strerror(errno);
|
||||
bool unreachable = errorCode == ENETUNREACH;
|
||||
bool inProgress = errorCode == EINPROGRESS || errorCode == EWOULDBLOCK;
|
||||
#endif
|
||||
if (!inProgress) {
|
||||
char addrStr[128]{};
|
||||
FormatAddr(addrStr, sizeof(addrStr), possible);
|
||||
if (errno != ENETUNREACH) {
|
||||
ERROR_LOG(HTTP, "connect(%d) call to %s failed (%d: %s)", sock, addrStr, errno, strerror(errno));
|
||||
if (!unreachable) {
|
||||
ERROR_LOG(HTTP, "connect(%d) call to %s failed (%d: %s)", sock, addrStr, errorCode, errorString.c_str());
|
||||
} else {
|
||||
INFO_LOG(HTTP, "connect(%d): Ignoring unreachable resolved address %s", sock, addrStr);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue