Skip to content

Commit

Permalink
gamecube api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
leo60228 committed Jan 15, 2024
1 parent 6748f76 commit 0e58918
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ static bool process_accept_events(s32 server) {
s32 peer;
struct sockaddr_in client_address;
socklen_t addrlen = sizeof(client_address);
while ((peer = net_accept(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) {
while ((peer = net_accept_nonblocking(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) {
if (peer < 0) {
printf("Error accepting connection: [%i] %s\n", -peer, strerror(-peer));
return false;
Expand Down Expand Up @@ -759,7 +759,7 @@ static void process_data_events(client_t *client) {
if (client->passive_socket >= 0) {
struct sockaddr_in data_peer_address;
socklen_t addrlen = sizeof(data_peer_address);
result = net_accept(client->passive_socket, (struct sockaddr *)&data_peer_address ,&addrlen);
result = net_accept_nonblocking(client->passive_socket, (struct sockaddr *)&data_peer_address ,&addrlen);
if (result >= 0) {
client->data_socket = result;
client->data_connection_connected = true;
Expand Down
1 change: 0 additions & 1 deletion source/ftpii.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ static void initialise_video() {
}

static void initialise_ftpii() {
initialise_video();
initialise_video();
PAD_Init();
initialise_reset_buttons();
Expand Down
25 changes: 21 additions & 4 deletions source/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ misrepresented as being the original software.
static u32 NET_BUFFER_SIZE = MAX_NET_BUFFER_SIZE;

void initialise_network() {
struct in_addr s_addr = {0};
struct in_addr netmask = {0};
struct in_addr gateway = {0};

printf("Waiting for network to initialise...\n");
s32 result = -1;
while (!check_reset_synchronous() && result < 0) {
while (!check_reset_synchronous() && (result = net_init()) == -EAGAIN);
result = if_configex(&s_addr, &netmask, &gateway, TRUE);
if (result < 0) printf("net_init() failed: [%i] %s, retrying...\n", result, strerror(-result));
}
if (result >= 0) {
Expand All @@ -59,9 +63,8 @@ void initialise_network() {
}

s32 set_blocking(s32 s, bool blocking) {
s32 flags;
flags = net_fcntl(s, F_GETFL, 0);
if (flags >= 0) flags = net_fcntl(s, F_SETFL, blocking ? (flags&~4) : (flags|4));
s32 flags = blocking;
net_ioctl(s, FIONBIO, &flags);
return flags;
}

Expand Down Expand Up @@ -167,3 +170,17 @@ s32 recv_to_file(s32 s, FILE *f) {
if (bytes_written < bytes_read) return -1;
}
}

s32 net_accept_nonblocking(s32 s, struct sockaddr *addr, socklen_t *addrlen) {
struct timeval tv = {0};
fd_set readset;
FD_ZERO(&readset);
FD_SET(s, &readset);
net_select(FD_SETSIZE, &readset, NULL, NULL, &tv);

if (FD_ISSET(s, &readset)) {
return net_accept(s, addr, addrlen);
} else {
return -EAGAIN;
}
}
2 changes: 2 additions & 0 deletions source/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ s32 send_from_file(s32 s, FILE *f);

s32 recv_to_file(s32 s, FILE *f);

s32 net_accept_nonblocking(s32 s, struct sockaddr *addr, socklen_t *addrlen);

#endif /* _NET_H_ */

0 comments on commit 0e58918

Please sign in to comment.