Skip to content

Commit 0e58918

Browse files
committed
gamecube api changes
1 parent 6748f76 commit 0e58918

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

source/ftp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ static bool process_accept_events(s32 server) {
700700
s32 peer;
701701
struct sockaddr_in client_address;
702702
socklen_t addrlen = sizeof(client_address);
703-
while ((peer = net_accept(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) {
703+
while ((peer = net_accept_nonblocking(server, (struct sockaddr *)&client_address, &addrlen)) != -EAGAIN) {
704704
if (peer < 0) {
705705
printf("Error accepting connection: [%i] %s\n", -peer, strerror(-peer));
706706
return false;
@@ -759,7 +759,7 @@ static void process_data_events(client_t *client) {
759759
if (client->passive_socket >= 0) {
760760
struct sockaddr_in data_peer_address;
761761
socklen_t addrlen = sizeof(data_peer_address);
762-
result = net_accept(client->passive_socket, (struct sockaddr *)&data_peer_address ,&addrlen);
762+
result = net_accept_nonblocking(client->passive_socket, (struct sockaddr *)&data_peer_address ,&addrlen);
763763
if (result >= 0) {
764764
client->data_socket = result;
765765
client->data_connection_connected = true;

source/ftpii.c

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ static void initialise_video() {
6161
}
6262

6363
static void initialise_ftpii() {
64-
initialise_video();
6564
initialise_video();
6665
PAD_Init();
6766
initialise_reset_buttons();

source/net.c

+21-4
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ misrepresented as being the original software.
3838
static u32 NET_BUFFER_SIZE = MAX_NET_BUFFER_SIZE;
3939

4040
void initialise_network() {
41+
struct in_addr s_addr = {0};
42+
struct in_addr netmask = {0};
43+
struct in_addr gateway = {0};
44+
4145
printf("Waiting for network to initialise...\n");
4246
s32 result = -1;
4347
while (!check_reset_synchronous() && result < 0) {
44-
while (!check_reset_synchronous() && (result = net_init()) == -EAGAIN);
48+
result = if_configex(&s_addr, &netmask, &gateway, TRUE);
4549
if (result < 0) printf("net_init() failed: [%i] %s, retrying...\n", result, strerror(-result));
4650
}
4751
if (result >= 0) {
@@ -59,9 +63,8 @@ void initialise_network() {
5963
}
6064

6165
s32 set_blocking(s32 s, bool blocking) {
62-
s32 flags;
63-
flags = net_fcntl(s, F_GETFL, 0);
64-
if (flags >= 0) flags = net_fcntl(s, F_SETFL, blocking ? (flags&~4) : (flags|4));
66+
s32 flags = blocking;
67+
net_ioctl(s, FIONBIO, &flags);
6568
return flags;
6669
}
6770

@@ -167,3 +170,17 @@ s32 recv_to_file(s32 s, FILE *f) {
167170
if (bytes_written < bytes_read) return -1;
168171
}
169172
}
173+
174+
s32 net_accept_nonblocking(s32 s, struct sockaddr *addr, socklen_t *addrlen) {
175+
struct timeval tv = {0};
176+
fd_set readset;
177+
FD_ZERO(&readset);
178+
FD_SET(s, &readset);
179+
net_select(FD_SETSIZE, &readset, NULL, NULL, &tv);
180+
181+
if (FD_ISSET(s, &readset)) {
182+
return net_accept(s, addr, addrlen);
183+
} else {
184+
return -EAGAIN;
185+
}
186+
}

source/net.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ s32 send_from_file(s32 s, FILE *f);
4040

4141
s32 recv_to_file(s32 s, FILE *f);
4242

43+
s32 net_accept_nonblocking(s32 s, struct sockaddr *addr, socklen_t *addrlen);
44+
4345
#endif /* _NET_H_ */

0 commit comments

Comments
 (0)