Make getNetErrorCode more generic between Windows and POSIX systems. Might break Windows build.
This commit is contained in:
parent
6cc02747a0
commit
6026f245c8
|
@ -72,6 +72,7 @@ it failed)
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
typedef struct pollfd pollfd_t;
|
typedef struct pollfd pollfd_t;
|
||||||
#else
|
#else
|
||||||
|
@ -493,11 +494,11 @@ struct GC_sockaddr_in
|
||||||
s8 sin_zero[8];
|
s8 sin_zero[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
char* DecodeError(int ErrorCode)
|
char* DecodeError(int ErrorCode)
|
||||||
{
|
{
|
||||||
static char Message[1024];
|
static char Message[1024];
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
// If this program was multi-threaded, we'd want to use FORMAT_MESSAGE_ALLOCATE_BUFFER
|
// If this program was multi-threaded, we'd want to use FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||||
// instead of a static buffer here.
|
// instead of a static buffer here.
|
||||||
// (And of course, free the buffer when we were done with it)
|
// (And of course, free the buffer when we were done with it)
|
||||||
|
@ -505,49 +506,59 @@ char *DecodeError(int ErrorCode)
|
||||||
FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, ErrorCode,
|
FORMAT_MESSAGE_MAX_WIDTH_MASK, NULL, ErrorCode,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)Message, 1024, NULL);
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)Message, 1024, NULL);
|
||||||
return Message;
|
return Message;
|
||||||
}
|
#else
|
||||||
|
return strerror(ErrorCode);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static int getNetErrorCode(int ret, std::string caller, bool isRW)
|
static int getNetErrorCode(int ret, std::string caller, bool isRW)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
int errorCode = WSAGetLastError();
|
int errorCode = WSAGetLastError();
|
||||||
|
#else
|
||||||
|
int errorCode = errno;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
WARN_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d",
|
WARN_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d",
|
||||||
caller.c_str(), errorCode, DecodeError(errorCode), ret);
|
caller.c_str(), errorCode, DecodeError(errorCode), ret);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define ERRORCODE(name) WSA ## name
|
||||||
|
#define EITHER(win32, posix) win32
|
||||||
|
#else
|
||||||
|
#define ERRORCODE(name) name
|
||||||
|
#define EITHER(win32, posix) posix
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (errorCode)
|
switch (errorCode)
|
||||||
{
|
{
|
||||||
case 10040:
|
case ERRORCODE(EMSGSIZE):
|
||||||
WARN_LOG(WII_IPC_NET, "Find out why this happened, looks like PEEK failure?");
|
WARN_LOG(WII_IPC_NET, "Find out why this happened, looks like PEEK failure?");
|
||||||
return -1;
|
return -1;
|
||||||
case 10054:
|
case ERRORCODE(ECONNRESET):
|
||||||
return -15;
|
return -15;
|
||||||
case 10056:
|
case ERRORCODE(EISCONN):
|
||||||
return -30;
|
return -30;
|
||||||
case 10057:
|
case ERRORCODE(ENOTCONN):
|
||||||
return -6;
|
return -6;
|
||||||
case 10035:
|
case ERRORCODE(EWOULDBLOCK):
|
||||||
|
case ERRORCODE(EINPROGRESS):
|
||||||
if(isRW){
|
if(isRW){
|
||||||
return -6;
|
return -6;
|
||||||
}else{
|
}else{
|
||||||
return -26;
|
return -26;
|
||||||
}
|
}
|
||||||
case 6:
|
case EITHER(WSA_INVALID_HANDLE, EBADF):
|
||||||
return -26;
|
return -26;
|
||||||
default:
|
default:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (ret >= 0)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
WARN_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d",
|
#undef ERRORCODE
|
||||||
caller.c_str(), errno, "hmm", ret);
|
#undef EITHER
|
||||||
return ret;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int convertWiiSockOpt(int level, int optname)
|
static int convertWiiSockOpt(int level, int optname)
|
||||||
|
|
Loading…
Reference in New Issue