Skip to content

Commit 0937296

Browse files
authored
Merge pull request #19 from fjtrujy/some_fixes
Some improvements
2 parents f8b69fd + e4e4f3d commit 0937296

7 files changed

Lines changed: 33 additions & 33 deletions

File tree

.github/workflows/compilation.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name: CI
33
on:
44
push:
55
pull_request:
6+
workflow_dispatch: {}
67

78
jobs:
89
build:
@@ -12,15 +13,26 @@ jobs:
1213
os: [
1314
[macos-latest, arm64],
1415
[macos-15-intel, x86_64],
15-
[ubuntu-latest, x86_64]
16+
[ubuntu-latest, x86_64],
17+
[windows-latest, x86_64],
1618
]
1719

1820
steps:
1921
- uses: actions/checkout@v4
2022

23+
- name: Install MSYS2 packages
24+
if: matrix.os[0] == 'windows-latest'
25+
uses: msys2/setup-msys2@v2
26+
with:
27+
msystem: MINGW32
28+
install: |
29+
base-devel mingw-w64-i686-gcc
30+
update: true
31+
2132
- name: Compile native versions
2233
run: |
23-
make --debug
34+
make -j $(getconf _NPROCESSORS_ONLN) clean
35+
make -j $(getconf _NPROCESSORS_ONLN) all
2436
2537
- name: Get short SHA
2638
id: slug
@@ -44,7 +56,8 @@ jobs:
4456

4557
- name: Compile windows version with cross-compilator
4658
run: |
47-
make -f Makefile.mingw32 --trace
59+
make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) clean
60+
make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) all
4861
4962
- name: Get short SHA
5063
id: slug

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
CFLAGS += -O2
1313
endif
1414

15-
ifneq "MINGW" "$(findstring MINGW,$(MSYSTEM))"
16-
LIBS = -lpthread
17-
else
15+
ifeq ($(OS),Windows_NT)
1816
LIBS = -lwsock32
17+
else
18+
LIBS = -lpthread
1919
endif
2020

2121
ifeq "x$(PREFIX)" "x"
2222
PREFIX = $(PS2DEV)
2323
endif
2424

25-
ifeq "MINGW" "$(findstring MINGW,$(MSYSTEM))"
25+
ifeq ($(OS),Windows_NT)
2626
all:
2727
$(MAKE) -f Makefile.mingw32 all
2828

src/fsclient.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,8 @@
5656
// Check to make sure a command was actually supplied.
5757
if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; }
5858

59-
#ifdef _WIN32
60-
61-
// Startup network, under windows.
62-
if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; }
63-
64-
#endif
59+
// Startup network
60+
if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; }
6561

6662
// Connect to the ps2netfs server.
6763
if (ps2netfs_connect(hostname) < 0) { printf("Error: Could not connect to the ps2netfs server. (%s)\n", hostname); return -1; }

src/network.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313
// NETWORK FUNCTIONS //
1414
///////////////////////
1515

16-
#ifdef _WIN32
1716
int network_startup(void) {
17+
#ifdef _WIN32
1818
WSADATA wsaData;
1919

2020
// Start up winsock.
2121
if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { return -1; }
2222

23+
#endif
2324
// End function.
2425
return 0;
25-
2626
}
27-
#endif
2827

2928
int network_connect(char *hostname, int port, int type) { int sock = -1;
3029
struct sockaddr_in sockaddr;

src/network.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
// NETWORK FUNCTIONS //
1313
///////////////////////
1414

15-
#ifdef _WIN32
1615
int network_startup(void);
17-
#endif
1816

1917
int network_connect(char *hostname, int port, int type);
2018

src/ps2client.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
#include <unistd.h>
66
#include "utility.h"
77
#include "ps2link.h"
8-
#ifdef _WIN32
98
#include "network.h"
10-
#endif
119

1210
char hostname[256] = { "192.168.0.10" };
1311

@@ -65,12 +63,8 @@
6563
// Check to make sure a command was actually supplied.
6664
if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; }
6765

68-
#ifdef _WIN32
69-
70-
// Startup network, under windows.
71-
if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; }
72-
73-
#endif
66+
// Startup network.
67+
if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; }
7468

7569
// Connect to the ps2link server.
7670
if (ps2link_connect(hostname) < 0) { printf("Error: Could not connect to the ps2link server. (%s)\n", hostname); return -1; }

src/ps2link.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#else
1515
#include <windows.h>
1616
#define sleep(x) Sleep(x * 1000)
17+
#define pause() while (1) { Sleep(600000); }
1718
#endif
1819

1920
#include "network.h"
@@ -68,11 +69,7 @@
6869
command_socket = network_connect(hostname, 0x4712, SOCK_DGRAM);
6970

7071
// Delay for a moment to let ps2link finish setup.
71-
#ifdef _WIN32
72-
Sleep(1);
73-
#else
7472
sleep(1);
75-
#endif
7673

7774
// End function.
7875
return 0;
@@ -87,8 +84,8 @@
8784
// If no timeout was given, timeout immediately.
8885
if (timeout == 0) { return 0; }
8986

90-
// If timeout was never, loop forever.
91-
if (timeout < 0) { for (;;) { sleep(600); } }
87+
// If timeout was never, wait forever.
88+
if (timeout < 0) { pause(); }
9289

9390
// Increment the timeout counter until timeout is reached.
9491
while (ps2link_counter++ < timeout) { sleep(1); };
@@ -99,7 +96,10 @@
9996
}
10097

10198
int ps2link_disconnect(void) {
102-
99+
// Kill created threads.
100+
pthread_cancel(request_thread_id);
101+
pthread_cancel(console_thread_id);
102+
103103
// Disconnect from the command port.
104104
if (network_disconnect(command_socket) < 0) { return -1; }
105105

0 commit comments

Comments
 (0)