Skip to content

Commit

Permalink
Merge pull request #18205 from unknownbrackets/http-error
Browse files Browse the repository at this point in the history
http: Fix errors on connect
  • Loading branch information
hrydgard committed Sep 23, 2023
2 parents 7dc18a9 + 4a2cd1b commit a829578
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions Common/Net/HTTPClient.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit a829578

Please sign in to comment.