ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Unix/ether_unix.cpp
(Generate patch)

Comparing BasiliskII/src/Unix/ether_unix.cpp (file contents):
Revision 1.23 by gbeauche, 2005-07-03T08:21:32Z vs.
Revision 1.29 by gbeauche, 2006-04-02T21:06:50Z

# Line 20 | Line 20
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
# Line 209 | Line 225 | static bool execute_network_script(const
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
# Line 320 | Line 336 | bool ether_init(void)
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) {
# Line 775 | Line 804 | void *slirp_receive_func(void *arg)
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  
# Line 810 | Line 842 | static void *receive_func(void *arg)
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
# Line 839 | Line 871 | static void *receive_func(void *arg)
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines