VirtualBox

Ignore:
Timestamp:
Feb 15, 2007 3:34:02 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
18659
Message:

Eliminate unnecessary global vars in slirp

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r530 r926  
    3232struct ex_list *exec_list;
    3333
     34#ifndef VBOX
    3435/* XXX: suppress those select globals */
    3536fd_set *global_readfds, *global_writefds, *global_xfds;
     37#endif /* !VBOX */
    3638
    3739char slirp_hostname[33];
     
    5759        FixedInfo = GlobalAlloc(GPTR, BufLen);
    5860    }
    59        
     61
    6062    if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) {
    6163#ifndef VBOX
     
    322324{
    323325        gettimeofday(&tt, 0);
    324        
     326
    325327        curtime = (u_int)tt.tv_sec * (u_int)1000;
    326328        curtime += (u_int)tt.tv_usec / (u_int)1000;
    327        
     329
    328330        if ((tt.tv_usec % 1000) >= 500)
    329331           curtime++;
     
    339341    int tmp_time;
    340342
     343#ifndef VBOX
    341344    /* fail safe */
    342345    global_readfds = NULL;
    343346    global_writefds = NULL;
    344347    global_xfds = NULL;
     348#endif /* !VBOX */
    345349
    346350    nfds = *pnfds;
     
    356360                do_slowtimo = ((tcb.so_next != &tcb) ||
    357361                               ((struct ipasfrag *)&ipq != u32_to_ptr(ipq.next, struct ipasfrag *)));
    358                
     362
    359363                for (so = tcb.so_next; so != &tcb; so = so_next) {
    360364                        so_next = so->so_next;
    361                        
     365
    362366                        /*
    363367                         * See if we need a tcp_fasttimo
     
    365369                        if (time_fasttimo == 0 && so->so_tcpcb->t_flags & TF_DELACK)
    366370                           time_fasttimo = curtime; /* Flag when we want a fasttimo */
    367                        
     371
    368372                        /*
    369373                         * NOFDREF can include still connecting to local-host,
     
    372376                        if (so->so_state & SS_NOFDREF || so->s == -1)
    373377                           continue;
    374                        
     378
    375379                        /*
    376380                         * Set for reading sockets which are accepting
     
    381385                                continue;
    382386                        }
    383                        
     387
    384388                        /*
    385389                         * Set for writing sockets which are connecting
     
    390394                                continue;
    391395                        }
    392                        
     396
    393397                        /*
    394398                         * Set for writing if we are connected, can send more, and
     
    399403                                UPD_NFDS(so->s);
    400404                        }
    401                        
     405
    402406                        /*
    403407                         * Set for reading (and urgent data) if we are connected, can
     
    410414                        }
    411415                }
    412                
     416
    413417                /*
    414418                 * UDP sockets
     
    416420                for (so = udb.so_next; so != &udb; so = so_next) {
    417421                        so_next = so->so_next;
    418                        
     422
    419423                        /*
    420424                         * See if it's timed out
     
    427431                                        do_slowtimo = 1; /* Let socket expire */
    428432                        }
    429                        
     433
    430434                        /*
    431435                         * When UDP packets are received from over the
     
    444448                }
    445449        }
    446        
     450
    447451        /*
    448452         * Setup timeout to use minimum CPU usage, especially when idle
    449453         */
    450        
     454
    451455        /*
    452456         * First, see the timeout needed by *timo
     
    466470                else if (timeout.tv_usec > 510000)
    467471                   timeout.tv_usec = 510000;
    468                
     472
    469473                /* Can only fasttimo if we also slowtimo */
    470474                if (time_fasttimo) {
     
    472476                        if (tmp_time < 0)
    473477                           tmp_time = 0;
    474                        
     478
    475479                        /* Choose the smallest of the 2 */
    476480                        if (tmp_time < timeout.tv_usec)
     
    479483        }
    480484        *pnfds = nfds;
    481 }       
     485}
    482486
    483487void slirp_select_poll(fd_set *readfds, fd_set *writefds, fd_set *xfds)
     
    486490    int ret;
    487491
     492#ifndef VBOX
    488493    global_readfds = readfds;
    489494    global_writefds = writefds;
    490495    global_xfds = xfds;
     496#endif /* !VBOX */
    491497
    492498        /* Update time */
    493499        updtime();
    494        
     500
    495501        /*
    496502         * See if anything has timed out
     
    507513                }
    508514        }
    509        
     515
    510516        /*
    511517         * Check sockets
     
    517523                for (so = tcb.so_next; so != &tcb; so = so_next) {
    518524                        so_next = so->so_next;
    519                        
     525
    520526                        /*
    521527                         * FD_ISSET is meaningless on these sockets
     
    524530                        if (so->so_state & SS_NOFDREF || so->s == -1)
    525531                           continue;
    526                        
     532
    527533                        /*
    528534                         * Check for URG data
     
    544550                                } /* else */
    545551                                ret = soread(so);
    546                                
     552
    547553                                /* Output it if we read something */
    548554                                if (ret > 0)
    549555                                   tcp_output(sototcpcb(so));
    550556                        }
    551                        
     557
    552558                        /*
    553559                         * Check sockets for writing
     
    560566                            /* Connected */
    561567                            so->so_state &= ~SS_ISFCONNECTING;
    562                        
     568
    563569                            ret = send(so->s, &ret, 0, 0);
    564570                            if (ret < 0) {
     
    567573                                  errno == EINPROGRESS || errno == ENOTCONN)
    568574                                continue;
    569                        
     575
    570576                              /* else failed */
    571577                              so->so_state = SS_NOFDREF;
    572578                            }
    573579                            /* else so->so_state &= ~SS_ISFCONNECTING; */
    574                        
     580
    575581                            /*
    576582                             * Continue tcp_input
     
    587593                           */
    588594                        }
    589                        
     595
    590596                        /*
    591597                         * Probe a still-connecting, non-blocking socket
     
    595601                        if (so->so_state & SS_ISFCONNECTING) {
    596602                          ret = recv(so->s, (char *)&ret, 0,0);
    597                        
     603
    598604                          if (ret < 0) {
    599605                            /* XXX */
     
    601607                                errno == EINPROGRESS || errno == ENOTCONN)
    602608                              continue; /* Still connecting, continue */
    603                        
     609
    604610                            /* else failed */
    605611                            so->so_state = SS_NOFDREF;
    606                        
     612
    607613                            /* tcp_input will take care of it */
    608614                          } else {
     
    617623                            } else
    618624                              so->so_state &= ~SS_ISFCONNECTING;
    619                        
     625
    620626                          }
    621627                          tcp_input((struct mbuf *)NULL, sizeof(struct ip),so);
     
    623629#endif
    624630                }
    625                
     631
    626632                /*
    627633                 * Now UDP sockets.
     
    631637                for (so = udb.so_next; so != &udb; so = so_next) {
    632638                        so_next = so->so_next;
    633                        
     639
    634640                        if (so->s != -1 && FD_ISSET(so->s, readfds)) {
    635641                            sorecvfrom(so);
     
    637643                }
    638644        }
    639        
     645
    640646        /*
    641647         * See if we can start outputting
     
    644650           if_start();
    645651
     652#ifndef VBOX
    646653        /* clear global file descriptor sets.
    647654         * these reside on the stack in vl.c
     
    652659         global_writefds = NULL;
    653660         global_xfds = NULL;
     661#endif /* !VBOX */
    654662}
    655663
  • trunk/src/VBox/Devices/Network/slirp/socket.c

    r1 r926  
    11/*
    22 * Copyright (c) 1995 Danny Gasparovski.
    3  * 
    4  * Please read the file COPYRIGHT for the 
     3 *
     4 * Please read the file COPYRIGHT for the
    55 * terms and conditions of the copyright.
    66 */
     
    3030{
    3131        struct socket *so;
    32        
     32
    3333        for (so = head->so_next; so != head; so = so->so_next) {
    34                 if (so->so_lport == lport && 
     34                if (so->so_lport == lport &&
    3535                    so->so_laddr.s_addr == laddr.s_addr &&
    3636                    so->so_faddr.s_addr == faddr.s_addr &&
     
    3838                   break;
    3939        }
    40        
     40
    4141        if (so == head)
    4242           return (struct socket *)NULL;
    4343        return so;
    44        
     44
    4545}
    4646
     
    5454{
    5555  struct socket *so;
    56        
     56
    5757  so = (struct socket *)malloc(sizeof(struct socket));
    5858  if(so) {
     
    7979  else if (so == udp_last_so)
    8080    udp_last_so = &udb;
    81        
     81
    8282  m_free(so->so_m);
    83        
    84   if(so->so_next && so->so_prev) 
     83
     84  if(so->so_next && so->so_prev)
    8585    remque(so);  /* crashes if so is not in a queue */
    8686
     
    102102        struct iovec iov[2];
    103103        int mss = so->so_tcpcb->t_maxseg;
    104        
     104
    105105        DEBUG_CALL("soread");
    106106        DEBUG_ARG("so = %lx", (long )so);
    107        
    108         /* 
     107
     108        /*
    109109         * No need to check if there's enough room to read.
    110110         * soread wouldn't have been called if there weren't
    111111         */
    112        
     112
    113113        len = sb->sb_datalen - sb->sb_cc;
    114        
     114
    115115        iov[0].iov_base = sb->sb_wptr;
    116116        if (sb->sb_wptr < sb->sb_rptr) {
     
    151151                }
    152152        }
    153        
     153
    154154#ifdef HAVE_READV
    155155        nn = readv(so->s, (struct iovec *)iov, n);
     
    157157#else
    158158        nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
    159 #endif 
     159#endif
    160160        if (nn <= 0) {
    161161                if (nn < 0 && (errno == EINTR || errno == EAGAIN))
     
    168168                }
    169169        }
    170        
     170
    171171#ifndef HAVE_READV
    172172        /*
     
    185185                nn += ret;
    186186        }
    187        
     187
    188188        DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
    189189#endif
    190        
     190
    191191        /* Update fields */
    192192        sb->sb_cc += nn;
     
    196196        return nn;
    197197}
    198        
     198
    199199/*
    200200 * Get urgent data
    201  * 
     201 *
    202202 * When the socket is created, we set it SO_OOBINLINE,
    203203 * so when OOB data arrives, we soread() it and everything
     
    212212        DEBUG_CALL("sorecvoob");
    213213        DEBUG_ARG("so = %lx", (long)so);
    214        
     214
    215215        /*
    216216         * We take a guess at how much urgent data has arrived.
     
    218218         * read() should get all the urgent data.  This guess will
    219219         * be wrong however if more data arrives just after the
    220          * urgent data, or the read() doesn't return all the 
     220         * urgent data, or the read() doesn't return all the
    221221         * urgent data.
    222222         */
     
    238238        struct sbuf *sb = &so->so_rcv;
    239239        char buff[2048]; /* XXX Shouldn't be sending more oob data than this */
    240        
     240
    241241        int n, len;
    242        
     242
    243243        DEBUG_CALL("sosendoob");
    244244        DEBUG_ARG("so = %lx", (long)so);
    245245        DEBUG_ARG("sb->sb_cc = %d", sb->sb_cc);
    246        
     246
    247247        if (so->so_urgc > 2048)
    248248           so->so_urgc = 2048; /* XXXX */
    249        
     249
    250250        if (sb->sb_rptr < sb->sb_wptr) {
    251251                /* We can send it directly */
    252252                n = send(so->s, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */
    253253                so->so_urgc -= n;
    254                
     254
    255255                DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
    256256        } else {
    257                 /* 
     257                /*
    258258                 * Since there's no sendv or sendtov like writev,
    259259                 * we must copy all data to a linear buffer then
     
    275275                if (n != len)
    276276                   DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
    277 #endif         
     277#endif
    278278                DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
    279279        }
    280        
     280
    281281        sb->sb_cc -= n;
    282282        sb->sb_rptr += n;
    283283        if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen))
    284284                sb->sb_rptr -= sb->sb_datalen;
    285        
     285
    286286        return n;
    287287}
    288288
    289289/*
    290  * Write data from so_rcv to so's socket, 
     290 * Write data from so_rcv to so's socket,
    291291 * updating all sbuf field as necessary
    292292 */
     
    299299        int len = sb->sb_cc;
    300300        struct iovec iov[2];
    301        
     301
    302302        DEBUG_CALL("sowrite");
    303303        DEBUG_ARG("so = %lx", (long)so);
    304        
     304
    305305        if (so->so_urgc) {
    306306                sosendoob(so);
     
    313313         * sowrite wouldn't have been called otherwise
    314314         */
    315        
     315
    316316        len = sb->sb_cc;
    317        
     317
    318318        iov[0].iov_base = sb->sb_rptr;
    319319        if (sb->sb_rptr < sb->sb_wptr) {
     
    338338#ifdef HAVE_READV
    339339        nn = writev(so->s, (const struct iovec *)iov, n);
    340        
     340
    341341        DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
    342342#else
     
    346346        if (nn < 0 && (errno == EAGAIN || errno == EINTR))
    347347                return 0;
    348        
     348
    349349        if (nn <= 0) {
    350350                DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
     
    354354                return -1;
    355355        }
    356        
     356
    357357#ifndef HAVE_READV
    358358        if (n == 2 && nn == iov[0].iov_len) {
     
    364364        DEBUG_MISC((dfd, "  ... wrote nn = %d bytes\n", nn));
    365365#endif
    366        
     366
    367367        /* Update sbuf */
    368368        sb->sb_cc -= nn;
     
    370370        if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen))
    371371                sb->sb_rptr -= sb->sb_datalen;
    372        
     372
    373373        /*
    374374         * If in DRAIN mode, and there's no more data, set
     
    377377        if ((so->so_state & SS_FWDRAIN) && sb->sb_cc == 0)
    378378                sofcantsendmore(so);
    379        
     379
    380380        return nn;
    381381}
     
    394394        socklen_t addrlen = sizeof(struct sockaddr_in);
    395395#endif /* VBOX */
    396        
     396
    397397        DEBUG_CALL("sorecvfrom");
    398398        DEBUG_ARG("so = %lx", (long)so);
    399        
     399
    400400        if (so->so_type == IPPROTO_ICMP) {   /* This is a "ping" reply */
    401401          char buff[256];
    402402          int len;
    403                
    404           len = recvfrom(so->s, buff, 256, 0, 
     403
     404          len = recvfrom(so->s, buff, 256, 0,
    405405                         (struct sockaddr *)&addr, &addrlen);
    406406          /* XXX Check if reply is "correct"? */
    407          
     407
    408408          if(len == -1 || len == 0) {
    409409            u_char code=ICMP_UNREACH_PORT;
     
    411411            if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
    412412            else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
    413            
     413
    414414            DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
    415415                        errno,strerror(errno)));
     
    427427          if (!(m = m_get())) return;
    428428          m->m_data += if_maxlinkhdr;
    429                
    430           /* 
     429
     430          /*
    431431           * XXX Shouldn't FIONREAD packets destined for port 53,
    432432           * but I don't know the max packet size for DNS lookups
     
    435435          /* if (so->so_fport != htons(53)) { */
    436436          ioctlsocket(so->s, FIONREAD, &n);
    437          
     437
    438438          if (n > len) {
    439439            n = (m->m_data - m->m_dat) + m->m_len + n + 1;
     
    442442          }
    443443          /* } */
    444                
     444
    445445          m->m_len = recvfrom(so->s, m->m_data, len, 0,
    446446                              (struct sockaddr *)&addr, &addrlen);
    447           DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n", 
     447          DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
    448448                      m->m_len, errno,strerror(errno)));
    449449          if(m->m_len<0) {
     
    452452            if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
    453453            else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET;
    454            
     454
    455455            DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));
    456456            icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
     
    475475             *          }
    476476             */
    477            
    478             /* 
     477
     478            /*
    479479             * If this packet was destined for CTL_ADDR,
    480480             * make it look like that's where it came from, done by udp_output
     
    499499        DEBUG_ARG("so = %lx", (long)so);
    500500        DEBUG_ARG("m = %lx", (long)m);
    501        
     501
    502502        addr.sin_family = AF_INET;
    503503        if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) {
     
    517517
    518518        DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n", ntohs(addr.sin_port), inet_ntoa(addr.sin_addr)));
    519        
     519
    520520        /* Don't care what port we get */
    521521        ret = sendto(so->s, m->m_data, m->m_len, 0,
     
    523523        if (ret < 0)
    524524                return -1;
    525        
     525
    526526        /*
    527527         * Kill the socket if there's no reply in 4 minutes,
     
    558558        DEBUG_ARG("lport = %d", lport);
    559559        DEBUG_ARG("flags = %x", flags);
    560        
     560
    561561        if ((so = socreate()) == NULL) {
    562562          /* free(so);      Not sofree() ??? free(NULL) == NOP */
    563563          return NULL;
    564564        }
    565        
     565
    566566        /* Don't tcp_attach... we don't need so_snd nor so_rcv */
    567567        if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) {
     
    570570        }
    571571        insque(so,&tcb);
    572        
    573         /* 
     572
     573        /*
    574574         * SS_FACCEPTONCE sockets must time out.
    575575         */
    576576        if (flags & SS_FACCEPTONCE)
    577577           so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;
    578        
     578
    579579        so->so_state = (SS_FACCEPTCONN|flags);
    580580        so->so_lport = lport; /* Kept in network format */
    581581        so->so_laddr.s_addr = laddr; /* Ditto */
    582        
     582
    583583        addr.sin_family = AF_INET;
    584584        addr.sin_addr.s_addr = INADDR_ANY;
    585585        addr.sin_port = port;
    586        
     586
    587587        if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) ||
    588588            (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||
     
    591591#ifndef VBOX
    592592                int tmperrno = errno; /* Don't clobber the real reason we failed */
    593                
     593
    594594                close(s);
    595595                sofree(so);
     
    618618        }
    619619        setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
    620        
     620
    621621        getsockname(s,(struct sockaddr *)&addr,&addrlen);
    622622        so->so_fport = addr.sin_port;
     
    630630}
    631631
    632 /* 
     632/*
    633633 * Data is available in so_rcv
    634634 * Just write() the data to the socket
     
    642642/*      FD_CLR(so->s,&writefds); */
    643643}
    644        
     644
    645645/*
    646646 * Data has been freed in so_snd
     
    684684        if ((so->so_state & SS_NOFDREF) == 0) {
    685685                shutdown(so->s,0);
     686#ifndef VBOX
    686687                if(global_writefds) {
    687688                  FD_CLR(so->s,global_writefds);
    688689                }
     690#endif /* !VBOX */
    689691        }
    690692        so->so_state &= ~(SS_ISFCONNECTING);
     
    701703        if ((so->so_state & SS_NOFDREF) == 0) {
    702704            shutdown(so->s,1);           /* send FIN to fhost */
     705#ifndef VBOX
    703706            if (global_readfds) {
    704707                FD_CLR(so->s,global_readfds);
     
    707710                FD_CLR(so->s,global_xfds);
    708711            }
     712#endif /* !VBOX */
    709713        }
    710714        so->so_state &= ~(SS_ISFCONNECTING);
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette