~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to slirp/sbuf.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2008-08-25 04:38:35 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20080825043835-8e3tftavy8bujdch
Tags: 0.9.1-6
[ Aurelien Jarno ]
* debian/control: 
  - Update list of supported targets (Closes: bug#488339).
* debian/qemu-make-debian-root:
  - Use mktemp instead of $$ to create temporary directories (Closes: 
    bug#496394).
* debian/links:
  - Add missing links to manpages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 1995 Danny Gasparovski.
3
 
 * 
4
 
 * Please read the file COPYRIGHT for the 
 
3
 *
 
4
 * Please read the file COPYRIGHT for the
5
5
 * terms and conditions of the copyright.
6
6
 */
7
7
 
8
8
#include <slirp.h>
9
9
 
 
10
static void sbappendsb(struct sbuf *sb, struct mbuf *m);
 
11
 
10
12
/* Done as a macro in socket.h */
11
13
/* int
12
 
 * sbspace(struct sockbuff *sb) 
 
14
 * sbspace(struct sockbuff *sb)
13
15
 * {
14
16
 *      return SB_DATALEN - sb->sb_cc;
15
17
 * }
25
27
void
26
28
sbdrop(sb, num)
27
29
        struct sbuf *sb;
28
 
        int num; 
 
30
        int num;
29
31
{
30
 
        /* 
 
32
        /*
31
33
         * We can only drop how much we have
32
 
         * This should never succeed 
 
34
         * This should never succeed
33
35
         */
34
36
        if(num > sb->sb_cc)
35
37
                num = sb->sb_cc;
37
39
        sb->sb_rptr += num;
38
40
        if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen)
39
41
                sb->sb_rptr -= sb->sb_datalen;
40
 
   
 
42
 
41
43
}
42
44
 
43
45
void
77
79
        struct mbuf *m;
78
80
{
79
81
        int ret = 0;
80
 
        
 
82
 
81
83
        DEBUG_CALL("sbappend");
82
84
        DEBUG_ARG("so = %lx", (long)so);
83
85
        DEBUG_ARG("m = %lx", (long)m);
84
86
        DEBUG_ARG("m->m_len = %d", m->m_len);
85
 
        
 
87
 
86
88
        /* Shouldn't happen, but...  e.g. foreign host closes connection */
87
89
        if (m->m_len <= 0) {
88
90
                m_free(m);
89
91
                return;
90
92
        }
91
 
        
 
93
 
92
94
        /*
93
95
         * If there is urgent data, call sosendoob
94
96
         * if not all was sent, sowrite will take care of the rest
100
102
                sosendoob(so);
101
103
                return;
102
104
        }
103
 
        
 
105
 
104
106
        /*
105
107
         * We only write if there's nothing in the buffer,
106
108
         * ottherwise it'll arrive out of order, and hence corrupt
107
109
         */
108
110
        if (!so->so_rcv.sb_cc)
109
 
           ret = write(so->s, m->m_data, m->m_len);
110
 
        
 
111
           ret = send(so->s, m->m_data, m->m_len, 0);
 
112
 
111
113
        if (ret <= 0) {
112
 
                /* 
 
114
                /*
113
115
                 * Nothing was written
114
116
                 * It's possible that the socket has closed, but
115
117
                 * we don't need to check because if it has closed,
133
135
 * Copy the data from m into sb
134
136
 * The caller is responsible to make sure there's enough room
135
137
 */
136
 
void
137
 
sbappendsb(sb, m)
138
 
         struct sbuf *sb;
139
 
         struct mbuf *m;
 
138
static void
 
139
sbappendsb(struct sbuf *sb, struct mbuf *m)
140
140
{
141
141
        int len, n,  nn;
142
 
        
 
142
 
143
143
        len = m->m_len;
144
144
 
145
145
        if (sb->sb_wptr < sb->sb_rptr) {
180
180
        char *to;
181
181
{
182
182
        char *from;
183
 
        
 
183
 
184
184
        from = sb->sb_rptr + off;
185
185
        if (from >= sb->sb_data + sb->sb_datalen)
186
186
                from -= sb->sb_datalen;
198
198
                   memcpy(to+off,sb->sb_data,len);
199
199
        }
200
200
}
201
 
                
 
201