summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2012-02-18 17:50:49 +0100
committerPierre Bourdon <delroth@gmail.com>2012-02-18 17:51:06 +0100
commit6026f245c8341eecf168caa0a0313d42ffdb0619 (patch)
tree028d487891d53984b6a41781e6c4f60f5482e779 /Source
parent6cc02747a085a2f9aa9e21e764bed3ff5daf0eb1 (diff)
Make getNetErrorCode more generic between Windows and POSIX systems. Might break Windows build.
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp45
1 files changed, 28 insertions, 17 deletions
diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp
index 4abfb2732c..33e44065b3 100644
--- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp
+++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_net.cpp
@@ -72,6 +72,7 @@ it failed)
#include <net/if.h>
#include <errno.h>
#include <poll.h>
+#include <string.h>
typedef struct pollfd pollfd_t;
#else
@@ -493,11 +494,11 @@ struct GC_sockaddr_in
s8 sin_zero[8];
};
-#ifdef _WIN32
-char *DecodeError(int ErrorCode)
+char* DecodeError(int ErrorCode)
{
static char Message[1024];
+#ifdef _WIN32
// If this program was multi-threaded, we'd want to use FORMAT_MESSAGE_ALLOCATE_BUFFER
// instead of a static buffer here.
// (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,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)Message, 1024, NULL);
return Message;
-}
+#else
+ return strerror(ErrorCode);
#endif
+}
static int getNetErrorCode(int ret, std::string caller, bool isRW)
{
#ifdef _WIN32
int errorCode = WSAGetLastError();
- if (ret>= 0)
+#else
+ int errorCode = errno;
+#endif
+
+ if (ret >= 0)
return ret;
WARN_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d",
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)
{
- case 10040:
+ case ERRORCODE(EMSGSIZE):
WARN_LOG(WII_IPC_NET, "Find out why this happened, looks like PEEK failure?");
return -1;
- case 10054:
+ case ERRORCODE(ECONNRESET):
return -15;
- case 10056:
+ case ERRORCODE(EISCONN):
return -30;
- case 10057:
+ case ERRORCODE(ENOTCONN):
return -6;
- case 10035:
+ case ERRORCODE(EWOULDBLOCK):
+ case ERRORCODE(EINPROGRESS):
if(isRW){
return -6;
}else{
return -26;
}
- case 6:
+ case EITHER(WSA_INVALID_HANDLE, EBADF):
return -26;
default:
return -1;
}
-#else
- if (ret >= 0)
- return ret;
- WARN_LOG(WII_IPC_NET, "%s failed with error %d: %s, ret= %d",
- caller.c_str(), errno, "hmm", ret);
- return ret;
-#endif
+#undef ERRORCODE
+#undef EITHER
}
static int convertWiiSockOpt(int level, int optname)