20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
|
|
23 |
+ |
/* |
24 |
+ |
* NOTES concerning MacOS X issues: |
25 |
+ |
* - poll() does not exist in 10.2.8, but is available in 10.4.4 |
26 |
+ |
* - select(), and very likely poll(), are not cancellation points. So |
27 |
+ |
* the ethernet thread doesn't stop on exit. An explicit check is |
28 |
+ |
* performed to workaround this problem. |
29 |
+ |
*/ |
30 |
+ |
#if (defined __APPLE__ && defined __MACH__) || ! defined HAVE_POLL |
31 |
+ |
#define USE_POLL 0 |
32 |
+ |
#else |
33 |
+ |
#define USE_POLL 1 |
34 |
+ |
#endif |
35 |
+ |
|
36 |
+ |
// Define to let the slirp library determine the right timeout for select() |
37 |
+ |
#define USE_SLIRP_TIMEOUT 1 |
38 |
+ |
|
39 |
|
#ifdef HAVE_SYS_POLL_H |
40 |
|
#include <sys/poll.h> |
41 |
|
#endif |
225 |
|
|
226 |
|
bool ether_init(void) |
227 |
|
{ |
228 |
< |
int nonblock = 1; |
228 |
> |
int val, nonblock = 1; |
229 |
|
char str[256]; |
230 |
|
|
231 |
|
// Do nothing if no Ethernet device specified |
336 |
|
#endif |
337 |
|
|
338 |
|
// Set nonblocking I/O |
339 |
< |
ioctl(fd, FIONBIO, &nonblock); |
339 |
> |
#ifdef USE_FIONBIO |
340 |
> |
if (ioctl(fd, FIONBIO, &nonblock) < 0) { |
341 |
> |
sprintf(str, GetString(STR_BLOCKING_NET_SOCKET_WARN), strerror(errno)); |
342 |
> |
WarningAlert(str); |
343 |
> |
goto open_error; |
344 |
> |
} |
345 |
> |
#else |
346 |
> |
val = fcntl(fd, F_GETFL, 0); |
347 |
> |
if (val < 0 || fcntl(fd, F_SETFL, val | O_NONBLOCK) < 0) { |
348 |
> |
sprintf(str, GetString(STR_BLOCKING_NET_SOCKET_WARN), strerror(errno)); |
349 |
> |
WarningAlert(str); |
350 |
> |
goto open_error; |
351 |
> |
} |
352 |
> |
#endif |
353 |
|
|
354 |
|
// Get Ethernet address |
355 |
|
if (net_if_type == NET_IF_ETHERTAP) { |
804 |
|
FD_ZERO(&rfds); |
805 |
|
FD_ZERO(&wfds); |
806 |
|
FD_ZERO(&xfds); |
807 |
< |
slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
807 |
> |
int timeout = slirp_select_fill(&nfds, &rfds, &wfds, &xfds); |
808 |
> |
#if ! USE_SLIRP_TIMEOUT |
809 |
> |
timeout = 10000; |
810 |
> |
#endif |
811 |
|
tv.tv_sec = 0; |
812 |
< |
tv.tv_usec = 10000; |
812 |
> |
tv.tv_usec = timeout; |
813 |
|
if (select(nfds + 1, &rfds, &wfds, &xfds, &tv) >= 0) |
814 |
|
slirp_select_poll(&rfds, &wfds, &xfds); |
815 |
|
|
842 |
|
for (;;) { |
843 |
|
|
844 |
|
// Wait for packets to arrive |
845 |
< |
#if HAVE_POLL |
845 |
> |
#if USE_POLL |
846 |
|
struct pollfd pf = {fd, POLLIN, 0}; |
847 |
|
int res = poll(&pf, 1, -1); |
848 |
|
#else |
871 |
|
// Wait for interrupt acknowledge by EtherInterrupt() |
872 |
|
sem_wait(&int_ack); |
873 |
|
} else |
874 |
< |
usleep(20000); |
874 |
> |
Delay_usec(20000); |
875 |
|
} |
876 |
|
return NULL; |
877 |
|
} |