~ubuntu-branches/ubuntu/feisty/basilisk2/feisty

« back to all changes in this revision

Viewing changes to src/slirp/slirp.c

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2006-06-01 01:11:16 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060601011116-xjhegbgyfsxag5fl
Tags: 0.9.20060529-1
* New upstream CVS snapshot.
* Update local cdbs snippet copyright-check.mk:
  + Broaden scan to also look for "(c)" by default.
  + Make egrep options configurable.
  + Ignore auto-tools files.
* Bump up standards-version to 3.7.2 (no changes needed).
* Let dh_strip do the stripping (not the make install target).

Show diffs side-by-side

added added

removed removed

Lines of Context:
183
183
}
184
184
#endif
185
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
188
{
189
189
    struct socket *so, *so_next;
190
 
    struct timeval timeout;
191
190
    int nfds;
192
 
    int tmp_time;
 
191
    int timeout, tmp_time;
193
192
 
194
193
    /* fail safe */
195
194
    global_readfds = NULL;
300
299
        /*
301
300
         * Setup timeout to use minimum CPU usage, especially when idle
302
301
         */
303
 
        
304
 
        /* 
305
 
         * First, see the timeout needed by *timo
306
 
         */
307
 
        timeout.tv_sec = 0;
308
 
        timeout.tv_usec = -1;
 
302
 
 
303
        timeout = -1;
 
304
 
309
305
        /*
310
 
         * 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
311
307
         * slow timeout. If a fast timeout is needed, set timeout within
312
 
         * 200ms of when it was requested.
 
308
         * 2ms of when it was requested.
313
309
         */
 
310
#       define SLOW_TIMO 5
 
311
#       define FAST_TIMO 2
314
312
        if (do_slowtimo) {
315
 
                /* XXX + 10000 because some select()'s aren't that accurate */
316
 
                timeout.tv_usec = ((500 - (curtime - last_slowtimo)) * 1000) + 10000;
317
 
                if (timeout.tv_usec < 0)
318
 
                   timeout.tv_usec = 0;
319
 
                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;
321
318
                
322
319
                /* Can only fasttimo if we also slowtimo */
323
320
                if (time_fasttimo) {
324
 
                        tmp_time = (200 - (curtime - time_fasttimo)) * 1000;
 
321
                        tmp_time = (FAST_TIMO - (curtime - time_fasttimo)) * 1000;
325
322
                        if (tmp_time < 0)
326
 
                           tmp_time = 0;
 
323
                                tmp_time = 0;
327
324
                        
328
325
                        /* Choose the smallest of the 2 */
329
 
                        if (tmp_time < timeout.tv_usec)
330
 
                           timeout.tv_usec = (u_int)tmp_time;
 
326
                        if (tmp_time < timeout)
 
327
                           timeout = tmp_time;
331
328
                }
332
329
        }
333
 
        *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 * 1000))
 
337
                timeout = FAST_TIMO * 1000;
 
338
 
 
339
        return timeout;
334
340
}       
335
341
 
336
342
void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
349
355
         * See if anything has timed out 
350
356
         */
351
357
        if (link_up) {
352
 
                if (time_fasttimo && ((curtime - time_fasttimo) >= 199)) {
 
358
                if (time_fasttimo && ((curtime - time_fasttimo) >= FAST_TIMO)) {
353
359
                        tcp_fasttimo();
354
360
                        time_fasttimo = 0;
355
361
                }
356
 
                if (do_slowtimo && ((curtime - last_slowtimo) >= 499)) {
 
362
                if (do_slowtimo && ((curtime - last_slowtimo) >= SLOW_TIMO)) {
357
363
                        ip_slowtimo();
358
364
                        tcp_slowtimo();
359
365
                        last_slowtimo = curtime;
595
601
    if (pkt_len < ETH_HLEN)
596
602
        return;
597
603
    
598
 
    proto = ntohs(*(uint16_t *)(pkt + 12));
 
604
    proto = (pkt[12] << 8) | pkt[13];
599
605
    switch(proto) {
600
606
    case ETH_P_ARP:
601
607
        arp_input(pkt, pkt_len);
604
610
        m = m_get();
605
611
        if (!m)
606
612
            return;
607
 
        m->m_len = pkt_len;
608
 
        memcpy(m->m_data, pkt, pkt_len);
 
613
        /* Note: we add to align the IP header */
 
614
        m->m_len = pkt_len + 2;
 
615
        memcpy(m->m_data + 2, pkt, pkt_len);
609
616
 
610
 
        m->m_data += ETH_HLEN;
611
 
        m->m_len -= ETH_HLEN;
 
617
        m->m_data += 2 + ETH_HLEN;
 
618
        m->m_len -= 2 + ETH_HLEN;
612
619
 
613
620
        ip_input(m);
614
621
        break;