Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Simplify platform logic
  • Loading branch information
fjtrujy committed Mar 27, 2024
commit bb5a00cd414cf77ee5f924b956e9202b5618354d
8 changes: 2 additions & 6 deletions src/fsclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
5 changes: 2 additions & 3 deletions src/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
// NETWORK FUNCTIONS //
///////////////////////

#ifdef _WIN32
int network_startup(void);
#endif

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

Expand Down
10 changes: 2 additions & 8 deletions src/ps2client.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
#include <unistd.h>
#include "utility.h"
#include "ps2link.h"
#ifdef _WIN32
#include "network.h"
#endif

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

Expand Down Expand Up @@ -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; }
Expand Down
14 changes: 7 additions & 7 deletions src/ps2link.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#else
#include <windows.h>
#define sleep(x) Sleep(x * 1000)
#define pause() while (1) { Sleep(600000); }
#endif

#include "network.h"
Expand Down Expand Up @@ -59,11 +60,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;
Expand All @@ -78,8 +75,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); };
Expand All @@ -90,7 +87,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; }

Expand Down