Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable netlink on windows #265

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile.libretro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
31 changes: 24 additions & 7 deletions libgambatte/libretro/net_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
#include "gambatte_log.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <winbase.h>
#else
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <netdb.h>
#endif

#ifdef _WIN32
#define close closesocket
#define ioctl ioctlsocket
#endif

NetSerial::NetSerial()
: is_stopped_(true)
, is_server_(false)
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions libgambatte/libretro/net_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
#include <sys/select.h>
#endif

#if _WIN32
#include <winsock2.h>
#endif

#include <gambatte.h>
#include <time.h>

Expand Down Expand Up @@ -36,6 +40,11 @@ class NetSerial : public gambatte::SerialIO
int sockfd_;

clock_t lastConnectAttempt_;

#ifdef __WIN32
WSADATA wsaData;
int wsaStartupStatus;
#endif
};

#endif