~vcs-imports/qemu/git

« back to all changes in this revision

Viewing changes to slirp/sbuf.c

  • Committer: bellard
  • Date: 2005-03-01 21:43:42 UTC
  • Revision ID: git-v1:1289f43ab16f9a012fb3698bcc5c92e61c10cd34
Windows keys support with keymaps


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1315 c046a42c-6fe2-441c-8c8c-71466251a162

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
 
 
12
10
/* Done as a macro in socket.h */
13
11
/* int
14
 
 * sbspace(struct sockbuff *sb)
 
12
 * sbspace(struct sockbuff *sb) 
15
13
 * {
16
14
 *      return SB_DATALEN - sb->sb_cc;
17
15
 * }
27
25
void
28
26
sbdrop(sb, num)
29
27
        struct sbuf *sb;
30
 
        int num;
 
28
        int num; 
31
29
{
32
 
        /*
 
30
        /* 
33
31
         * We can only drop how much we have
34
 
         * This should never succeed
 
32
         * This should never succeed 
35
33
         */
36
34
        if(num > sb->sb_cc)
37
35
                num = sb->sb_cc;
39
37
        sb->sb_rptr += num;
40
38
        if(sb->sb_rptr >= sb->sb_data + sb->sb_datalen)
41
39
                sb->sb_rptr -= sb->sb_datalen;
42
 
 
 
40
   
43
41
}
44
42
 
45
43
void
79
77
        struct mbuf *m;
80
78
{
81
79
        int ret = 0;
82
 
 
 
80
        
83
81
        DEBUG_CALL("sbappend");
84
82
        DEBUG_ARG("so = %lx", (long)so);
85
83
        DEBUG_ARG("m = %lx", (long)m);
86
84
        DEBUG_ARG("m->m_len = %d", m->m_len);
87
 
 
 
85
        
88
86
        /* Shouldn't happen, but...  e.g. foreign host closes connection */
89
87
        if (m->m_len <= 0) {
90
88
                m_free(m);
91
89
                return;
92
90
        }
93
 
 
 
91
        
94
92
        /*
95
93
         * If there is urgent data, call sosendoob
96
94
         * if not all was sent, sowrite will take care of the rest
102
100
                sosendoob(so);
103
101
                return;
104
102
        }
105
 
 
 
103
        
106
104
        /*
107
105
         * We only write if there's nothing in the buffer,
108
106
         * ottherwise it'll arrive out of order, and hence corrupt
109
107
         */
110
108
        if (!so->so_rcv.sb_cc)
111
109
           ret = send(so->s, m->m_data, m->m_len, 0);
112
 
 
 
110
        
113
111
        if (ret <= 0) {
114
 
                /*
 
112
                /* 
115
113
                 * Nothing was written
116
114
                 * It's possible that the socket has closed, but
117
115
                 * we don't need to check because if it has closed,
135
133
 * Copy the data from m into sb
136
134
 * The caller is responsible to make sure there's enough room
137
135
 */
138
 
static void
139
 
sbappendsb(struct sbuf *sb, struct mbuf *m)
 
136
void
 
137
sbappendsb(sb, m)
 
138
         struct sbuf *sb;
 
139
         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