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