Skip to content

Commit bb5a00c

Browse files
committed
Simplify platform logic
1 parent 092f338 commit bb5a00c

File tree

5 files changed

+13
-26
lines changed

5 files changed

+13
-26
lines changed

src/fsclient.c

+2-6
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

+2-3
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

-2
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

+2-8
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

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#else
1414
#include <windows.h>
1515
#define sleep(x) Sleep(x * 1000)
16+
#define pause() while (1) { Sleep(600000); }
1617
#endif
1718

1819
#include "network.h"
@@ -59,11 +60,7 @@
5960
command_socket = network_connect(hostname, 0x4712, SOCK_DGRAM);
6061

6162
// Delay for a moment to let ps2link finish setup.
62-
#ifdef _WIN32
63-
Sleep(1);
64-
#else
6563
sleep(1);
66-
#endif
6764

6865
// End function.
6966
return 0;
@@ -78,8 +75,8 @@
7875
// If no timeout was given, timeout immediately.
7976
if (timeout == 0) { return 0; }
8077

81-
// If timeout was never, loop forever.
82-
if (timeout < 0) { for (;;) { sleep(600); } }
78+
// If timeout was never, wait forever.
79+
if (timeout < 0) { pause(); }
8380

8481
// Increment the timeout counter until timeout is reached.
8582
while (ps2link_counter++ < timeout) { sleep(1); };
@@ -90,7 +87,10 @@
9087
}
9188

9289
int ps2link_disconnect(void) {
93-
90+
// Kill created threads.
91+
pthread_cancel(request_thread_id);
92+
pthread_cancel(console_thread_id);
93+
9494
// Disconnect from the command port.
9595
if (network_disconnect(command_socket) < 0) { return -1; }
9696

0 commit comments

Comments
 (0)