@@ -38,10 +38,14 @@ misrepresented as being the original software.
38
38
static u32 NET_BUFFER_SIZE = MAX_NET_BUFFER_SIZE ;
39
39
40
40
void initialise_network () {
41
+ struct in_addr s_addr = {0 };
42
+ struct in_addr netmask = {0 };
43
+ struct in_addr gateway = {0 };
44
+
41
45
printf ("Waiting for network to initialise...\n" );
42
46
s32 result = -1 ;
43
47
while (!check_reset_synchronous () && result < 0 ) {
44
- while (! check_reset_synchronous () && ( result = net_init ()) == - EAGAIN );
48
+ result = if_configex ( & s_addr , & netmask , & gateway , TRUE );
45
49
if (result < 0 ) printf ("net_init() failed: [%i] %s, retrying...\n" , result , strerror (- result ));
46
50
}
47
51
if (result >= 0 ) {
@@ -59,9 +63,8 @@ void initialise_network() {
59
63
}
60
64
61
65
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 );
65
68
return flags ;
66
69
}
67
70
@@ -167,3 +170,17 @@ s32 recv_to_file(s32 s, FILE *f) {
167
170
if (bytes_written < bytes_read ) return -1 ;
168
171
}
169
172
}
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
+ }
0 commit comments