diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 2b7c3d9..a3130ef 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -3,6 +3,7 @@ name: CI on: push: pull_request: + workflow_dispatch: {} jobs: build: @@ -12,15 +13,26 @@ jobs: os: [ [macos-latest, arm64], [macos-15-intel, x86_64], - [ubuntu-latest, x86_64] + [ubuntu-latest, x86_64], + [windows-latest, x86_64], ] steps: - uses: actions/checkout@v4 + - name: Install MSYS2 packages + if: matrix.os[0] == 'windows-latest' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW32 + install: | + base-devel mingw-w64-i686-gcc + update: true + - name: Compile native versions run: | - make --debug + make -j $(getconf _NPROCESSORS_ONLN) clean + make -j $(getconf _NPROCESSORS_ONLN) all - name: Get short SHA id: slug @@ -44,7 +56,8 @@ jobs: - name: Compile windows version with cross-compilator run: | - make -f Makefile.mingw32 --trace + make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) clean + make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) all - name: Get short SHA id: slug diff --git a/Makefile b/Makefile index a4c0731..e726c3d 100644 --- a/Makefile +++ b/Makefile @@ -12,17 +12,17 @@ CFLAGS += -O2 endif - ifneq "MINGW" "$(findstring MINGW,$(MSYSTEM))" - LIBS = -lpthread - else + ifeq ($(OS),Windows_NT) LIBS = -lwsock32 + else + LIBS = -lpthread endif ifeq "x$(PREFIX)" "x" PREFIX = $(PS2DEV) endif - ifeq "MINGW" "$(findstring MINGW,$(MSYSTEM))" + ifeq ($(OS),Windows_NT) all: $(MAKE) -f Makefile.mingw32 all diff --git a/src/fsclient.c b/src/fsclient.c index d39c4a7..de58c2f 100644 --- a/src/fsclient.c +++ b/src/fsclient.c @@ -56,12 +56,8 @@ // Check to make sure a command was actually supplied. if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; } -#ifdef _WIN32 - - // Startup network, under windows. - if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; } - -#endif + // Startup network + if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; } // Connect to the ps2netfs server. if (ps2netfs_connect(hostname) < 0) { printf("Error: Could not connect to the ps2netfs server. (%s)\n", hostname); return -1; } diff --git a/src/network.c b/src/network.c index d0d877c..cdbf06d 100644 --- a/src/network.c +++ b/src/network.c @@ -13,18 +13,17 @@ // NETWORK FUNCTIONS // /////////////////////// -#ifdef _WIN32 int network_startup(void) { +#ifdef _WIN32 WSADATA wsaData; // Start up winsock. if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { return -1; } +#endif // End function. return 0; - } -#endif int network_connect(char *hostname, int port, int type) { int sock = -1; struct sockaddr_in sockaddr; diff --git a/src/network.h b/src/network.h index a592757..a1fe603 100644 --- a/src/network.h +++ b/src/network.h @@ -12,9 +12,7 @@ // NETWORK FUNCTIONS // /////////////////////// -#ifdef _WIN32 int network_startup(void); -#endif int network_connect(char *hostname, int port, int type); diff --git a/src/ps2client.c b/src/ps2client.c index 7631795..be54bda 100644 --- a/src/ps2client.c +++ b/src/ps2client.c @@ -5,9 +5,7 @@ #include #include "utility.h" #include "ps2link.h" -#ifdef _WIN32 #include "network.h" -#endif char hostname[256] = { "192.168.0.10" }; @@ -65,12 +63,8 @@ // Check to make sure a command was actually supplied. if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; } -#ifdef _WIN32 - - // Startup network, under windows. - if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; } - -#endif + // Startup network. + if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; } // Connect to the ps2link server. if (ps2link_connect(hostname) < 0) { printf("Error: Could not connect to the ps2link server. (%s)\n", hostname); return -1; } diff --git a/src/ps2link.c b/src/ps2link.c index 2e96a31..6a926bf 100644 --- a/src/ps2link.c +++ b/src/ps2link.c @@ -14,6 +14,7 @@ #else #include #define sleep(x) Sleep(x * 1000) + #define pause() while (1) { Sleep(600000); } #endif #include "network.h" @@ -68,11 +69,7 @@ command_socket = network_connect(hostname, 0x4712, SOCK_DGRAM); // Delay for a moment to let ps2link finish setup. -#ifdef _WIN32 - Sleep(1); -#else sleep(1); -#endif // End function. return 0; @@ -87,8 +84,8 @@ // If no timeout was given, timeout immediately. if (timeout == 0) { return 0; } - // If timeout was never, loop forever. - if (timeout < 0) { for (;;) { sleep(600); } } + // If timeout was never, wait forever. + if (timeout < 0) { pause(); } // Increment the timeout counter until timeout is reached. while (ps2link_counter++ < timeout) { sleep(1); }; @@ -99,7 +96,10 @@ } int ps2link_disconnect(void) { - + // Kill created threads. + pthread_cancel(request_thread_id); + pthread_cancel(console_thread_id); + // Disconnect from the command port. if (network_disconnect(command_socket) < 0) { return -1; }