diff --git a/Makefile.libretro b/Makefile.libretro index 98ee91b2..9f02a0a1 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -448,7 +448,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) WinPartition = desktop MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP LDFLAGS += -MANIFEST -LTCG:incremental -NXCOMPAT -DYNAMICBASE -DEBUG -OPT:REF -INCREMENTAL:NO -SUBSYSTEM:WINDOWS -MANIFESTUAC:"level='asInvoker' uiAccess='false'" -OPT:ICF -ERRORREPORT:PROMPT -NOLOGO -TLBID:1 - LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib + LIBS += kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib ws2_32.lib else ifneq (,$(findstring uwp,$(PlatformSuffix))) WinPartition = uwp MSVC2017CompileFlags = -DWINAPI_FAMILY=WINAPI_FAMILY_APP -D_WINDLL -D_UNICODE -DUNICODE -D__WRL_NO_DEFAULT_LIB__ -EHsc @@ -528,6 +528,7 @@ else ifneq (,$(findstring windows_msvc2017,$(platform))) TARGET := $(TARGET_NAME)_libretro.dll PSS_STYLE :=2 LDFLAGS += -DLL + HAVE_NETWORK=1 # Windows MSVC 2010 x64 else ifeq ($(platform), windows_msvc2010_x64) diff --git a/libgambatte/libretro/net_serial.cpp b/libgambatte/libretro/net_serial.cpp index b19605b3..da4e3d10 100644 --- a/libgambatte/libretro/net_serial.cpp +++ b/libgambatte/libretro/net_serial.cpp @@ -3,19 +3,25 @@ #include "gambatte_log.h" #include #include -#include -#include -#include #ifdef _WIN32 #include #include +#include #else +#include +#include +#include #include #include #include #include #endif +#ifdef _WIN32 +#define close closesocket +#define ioctl ioctlsocket +#endif + NetSerial::NetSerial() : is_stopped_(true) , is_server_(false) @@ -25,11 +31,19 @@ NetSerial::NetSerial() , sockfd_(-1) , lastConnectAttempt_(0) { +#ifdef _WIN32 + //wsaStartupStatus = WSAStartup(MAKEWORD(2, 2), &wsaData); + WSADATA data = {}; + WSAStartup(MAKEWORD(2, 2), &data); +#endif } NetSerial::~NetSerial() { stop(); +#ifdef _WIN32 + WSACleanup(); +#endif } bool NetSerial::start(bool is_server, int port, const std::string& hostname) @@ -101,7 +115,14 @@ bool NetSerial::startServerSocket() int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) { +#ifdef _WIN32 + LPSTR lpErrorMessage; + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR) &lpErrorMessage, 0, NULL); + gambatte_log(RETRO_LOG_ERROR, "Error opening socket: %s\n", lpErrorMessage); + LocalFree(lpErrorMessage); +#else gambatte_log(RETRO_LOG_ERROR, "Error opening socket: %s\n", strerror(errno)); +#endif return false; } @@ -246,11 +267,7 @@ bool NetSerial::check(unsigned char out, unsigned char& in, bool& fastCgb) return false; } } -#ifdef _WIN32 - if (ioctlsocket(sockfd_, FIONREAD, &bytes_avail) < 0) -#else if (ioctl(sockfd_, FIONREAD, &bytes_avail) < 0) -#endif { gambatte_log(RETRO_LOG_ERROR, "IOCTL Failed: %s\n", strerror(errno)); return false; diff --git a/libgambatte/libretro/net_serial.h b/libgambatte/libretro/net_serial.h index fb0edeb7..07e43551 100644 --- a/libgambatte/libretro/net_serial.h +++ b/libgambatte/libretro/net_serial.h @@ -6,6 +6,10 @@ #include #endif +#if _WIN32 +#include +#endif + #include #include @@ -36,6 +40,11 @@ class NetSerial : public gambatte::SerialIO int sockfd_; clock_t lastConnectAttempt_; + +#ifdef __WIN32 + WSADATA wsaData; + int wsaStartupStatus; +#endif }; #endif