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

Comparing BasiliskII/src/slirp/slirp.c (file contents):
Revision 1.4 by gbeauche, 2006-03-25T07:57:38Z vs.
Revision 1.5 by gbeauche, 2006-04-02T21:06:50Z

# Line 183 | Line 183 | static void updtime(void)
183   }
184   #endif
185  
186 < void slirp_select_fill(int *pnfds,
187 <                       fd_set *readfds, fd_set *writefds, fd_set *xfds)
186 > int slirp_select_fill(int *pnfds,
187 >                                          fd_set *readfds, fd_set *writefds, fd_set *xfds)
188   {
189      struct socket *so, *so_next;
190    struct timeval timeout;
190      int nfds;
191 <    int tmp_time;
191 >    int timeout, tmp_time;
192  
193      /* fail safe */
194      global_readfds = NULL;
# Line 300 | Line 299 | void slirp_select_fill(int *pnfds,
299          /*
300           * Setup timeout to use minimum CPU usage, especially when idle
301           */
302 <        
303 <        /*
304 <         * First, see the timeout needed by *timo
306 <         */
307 <        timeout.tv_sec = 0;
308 <        timeout.tv_usec = -1;
302 >
303 >        timeout = -1;
304 >
305          /*
306 <         * If a slowtimo is needed, set timeout to 500ms from the last
306 >         * If a slowtimo is needed, set timeout to 5ms from the last
307           * slow timeout. If a fast timeout is needed, set timeout within
308 <         * 200ms of when it was requested.
308 >         * 2ms of when it was requested.
309           */
310 + #       define SLOW_TIMO 5
311 + #       define FAST_TIMO 2
312          if (do_slowtimo) {
313 <                /* XXX + 10000 because some select()'s aren't that accurate */
314 <                timeout.tv_usec = ((500 - (curtime - last_slowtimo)) * 1000) + 10000;
315 <                if (timeout.tv_usec < 0)
316 <                   timeout.tv_usec = 0;
317 <                else if (timeout.tv_usec > 510000)
320 <                   timeout.tv_usec = 510000;
313 >                timeout = (SLOW_TIMO - (curtime - last_slowtimo)) * 1000;
314 >                if (timeout < 0)
315 >                   timeout = 0;
316 >                else if (timeout > (SLOW_TIMO * 1000))
317 >                   timeout = SLOW_TIMO * 1000;
318                  
319                  /* Can only fasttimo if we also slowtimo */
320                  if (time_fasttimo) {
321 <                        tmp_time = (200 - (curtime - time_fasttimo)) * 1000;
321 >                        tmp_time = (FAST_TIMO - (curtime - time_fasttimo)) * 1000;
322                          if (tmp_time < 0)
323 <                           tmp_time = 0;
323 >                                tmp_time = 0;
324                          
325                          /* Choose the smallest of the 2 */
326 <                        if (tmp_time < timeout.tv_usec)
327 <                           timeout.tv_usec = (u_int)tmp_time;
326 >                        if (tmp_time < timeout)
327 >                           timeout = tmp_time;
328                  }
329          }
330 <        *pnfds = nfds;
330 >        *pnfds = nfds;
331 >
332 >        /*
333 >         * Adjust the timeout to make the minimum timeout
334 >         * 2ms (XXX?) to lessen the CPU load
335 >         */
336 >        if (timeout < FAST_TIMO)
337 >                timeout = FAST_TIMO;
338 >
339 >        return timeout;
340   }      
341  
342   void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
# Line 349 | Line 355 | void slirp_select_poll(fd_set *readfds,
355           * See if anything has timed out
356           */
357          if (link_up) {
358 <                if (time_fasttimo && ((curtime - time_fasttimo) >= 2)) {
358 >                if (time_fasttimo && ((curtime - time_fasttimo) >= FAST_TIMO)) {
359                          tcp_fasttimo();
360                          time_fasttimo = 0;
361                  }
362 <                if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
362 >                if (do_slowtimo && ((curtime - last_slowtimo) >= SLOW_TIMO)) {
363                          ip_slowtimo();
364                          tcp_slowtimo();
365                          last_slowtimo = curtime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines