~ubuntu-branches/ubuntu/trusty/virtualbox-ose/trusty

« back to all changes in this revision

Viewing changes to src/VBox/Devices/Network/slirp/sbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2009-12-18 16:44:29 UTC
  • mfrom: (0.3.3 upstream) (0.4.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091218164429-jd34ccexpv5na11a
Tags: 3.1.2-dfsg-1ubuntu1
* Merge from Debian unstable (LP: #498219), remaining changes:
  - Disable update action
    - debian/patches/u01-disable-update-action.dpatch
  - VirtualBox should go in Accessories, not in System tools (LP: #288590)
    - debian/virtualbox-ose-qt.files/virtualbox-ose.desktop
  - Add Apport hook
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Add Launchpad integration
    - debian/control
    - debian/lpi-bug.xpm
    - debian/patches/u02-lp-integration.dpatch
* Fixes the following bugs:
  - Kernel module fails to build with Linux >= 2.6.32 (LP: #474625)
  - X.Org drivers need to be rebuilt against X-Server 1.7 (LP: #495935)
  - The *-source packages try to build the kernel modules even though the
    kernel headers aren't available (LP: #473334)
* Replace *-source packages with transitional packages for *-dkms.
* Adapt u01-disable-update-action.dpatch and u02-lp-integration.dpatch for
  new upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
sbappend(PNATState pData, struct socket *so, struct mbuf *m)
77
77
{
78
78
    int ret = 0;
 
79
#ifdef VBOX_WITH_SLIRP_BSD_MBUF
 
80
    int mlen = 0;
 
81
    uint8_t *buf = NULL;
 
82
#endif
79
83
 
80
84
    STAM_PROFILE_START(&pData->StatIOSBAppend_pf, a);
81
85
    DEBUG_CALL("sbappend");
83
87
    DEBUG_ARG("m = %lx", (long)m);
84
88
    DEBUG_ARG("m->m_len = %d", m ? m->m_len : 0);
85
89
 
86
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppend);
87
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppend_zm);
88
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppend_wa);
89
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppend_wf);
90
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppend_wp);
91
 
 
92
90
    STAM_COUNTER_INC(&pData->StatIOSBAppend);
93
91
    /* Shouldn't happen, but...  e.g. foreign host closes connection */
 
92
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
94
93
    if (m->m_len <= 0)
 
94
#else
 
95
    mlen = m_length(m, NULL);
 
96
    if (mlen <= 0)
 
97
#endif
95
98
    {
96
99
        STAM_COUNTER_INC(&pData->StatIOSBAppend_zm);
97
100
        goto done;
114
117
     * We only write if there's nothing in the buffer,
115
118
     * ottherwise it'll arrive out of order, and hence corrupt
116
119
     */
117
 
    if (!so->so_rcv.sb_cc)
 
120
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
 
121
    if(!so->so_rcv.sb_cc)
118
122
        ret = send(so->s, m->m_data, m->m_len, 0);
 
123
#else
 
124
    buf = RTMemAlloc(mlen);
 
125
    if (buf == NULL)
 
126
    {
 
127
        ret = 0;
 
128
        goto no_sent;
 
129
    }
 
130
    m_copydata(m, 0, mlen, buf);
 
131
    if(!so->so_rcv.sb_cc)
 
132
        ret = send(so->s, buf, mlen, 0);
 
133
    RTMemFree(buf);
 
134
no_sent:
 
135
#endif
119
136
 
120
137
    if (ret <= 0)
121
138
    {
130
147
        STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wf, a);
131
148
        goto done;
132
149
    }
 
150
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
133
151
    else if (ret != m->m_len)
 
152
#else
 
153
    else if (ret != mlen)
 
154
#endif
134
155
    {
135
156
        STAM_COUNTER_INC(&pData->StatIOSBAppend_wp);
136
157
        /*
137
158
         * Something was written, but not everything..
138
159
         * sbappendsb the rest
139
160
         */
 
161
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
140
162
        m->m_len -= ret;
141
163
        m->m_data += ret;
 
164
#else
 
165
        m_adj(m, ret);
 
166
#endif
142
167
        sbappendsb(pData, &so->so_rcv, m);
143
168
        STAM_PROFILE_STOP(&pData->StatIOSBAppend_pf_wp, a);
144
169
        goto done;
159
184
{
160
185
    int len, n,  nn;
161
186
 
 
187
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
162
188
    len = m->m_len;
163
 
 
164
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppendSB);
165
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppendSB_w_l_r);
166
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppendSB_w_ge_r);
167
 
    STAM_COUNTER_RESET(&pData->StatIOSBAppendSB_w_alter);
 
189
#else
 
190
    len = m_length(m, NULL);
 
191
#endif
168
192
 
169
193
    STAM_COUNTER_INC(&pData->StatIOSBAppendSB);
170
194
    if (sb->sb_wptr < sb->sb_rptr)
173
197
        n = sb->sb_rptr - sb->sb_wptr;
174
198
        if (n > len)
175
199
            n = len;
 
200
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
176
201
        memcpy(sb->sb_wptr, m->m_data, n);
 
202
#else
 
203
        m_copydata(m, 0, n, sb->sb_wptr);
 
204
#endif
177
205
    }
178
206
    else
179
207
    {
182
210
        n = sb->sb_data + sb->sb_datalen - sb->sb_wptr;
183
211
        if (n > len)
184
212
            n = len;
 
213
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
185
214
        memcpy(sb->sb_wptr, m->m_data, n);
 
215
#else
 
216
        m_copydata(m, 0, n, sb->sb_wptr);
 
217
#endif
186
218
        len -= n;
187
219
        if (len)
188
220
        {
190
222
            nn = sb->sb_rptr - sb->sb_data;
191
223
            if (nn > len)
192
224
                nn = len;
 
225
#ifndef VBOX_WITH_SLIRP_BSD_MBUF
193
226
            memcpy(sb->sb_data, m->m_data+n, nn);
 
227
#else
 
228
            m_copydata(m, n, nn, sb->sb_wptr);
 
229
#endif
194
230
            n += nn;
195
231
        }
196
232
    }