root / slirp / socket.c @ c5d6edc3
History | View | Annotate | Download (16.6 kB)
1 | f0cbd3ec | bellard | /*
|
---|---|---|---|
2 | f0cbd3ec | bellard | * Copyright (c) 1995 Danny Gasparovski.
|
3 | f0cbd3ec | bellard | *
|
4 | f0cbd3ec | bellard | * Please read the file COPYRIGHT for the
|
5 | f0cbd3ec | bellard | * terms and conditions of the copyright.
|
6 | f0cbd3ec | bellard | */
|
7 | f0cbd3ec | bellard | |
8 | f0cbd3ec | bellard | #define WANT_SYS_IOCTL_H
|
9 | f0cbd3ec | bellard | #include <slirp.h> |
10 | f0cbd3ec | bellard | #include "ip_icmp.h" |
11 | f0cbd3ec | bellard | #include "main.h" |
12 | ec530c81 | bellard | #ifdef __sun__
|
13 | ec530c81 | bellard | #include <sys/filio.h> |
14 | ec530c81 | bellard | #endif
|
15 | f0cbd3ec | bellard | |
16 | f0cbd3ec | bellard | void
|
17 | f0cbd3ec | bellard | so_init() |
18 | f0cbd3ec | bellard | { |
19 | f0cbd3ec | bellard | /* Nothing yet */
|
20 | f0cbd3ec | bellard | } |
21 | f0cbd3ec | bellard | |
22 | f0cbd3ec | bellard | |
23 | f0cbd3ec | bellard | struct socket *
|
24 | f0cbd3ec | bellard | solookup(head, laddr, lport, faddr, fport) |
25 | f0cbd3ec | bellard | struct socket *head;
|
26 | f0cbd3ec | bellard | struct in_addr laddr;
|
27 | f0cbd3ec | bellard | u_int lport; |
28 | f0cbd3ec | bellard | struct in_addr faddr;
|
29 | f0cbd3ec | bellard | u_int fport; |
30 | f0cbd3ec | bellard | { |
31 | f0cbd3ec | bellard | struct socket *so;
|
32 | f0cbd3ec | bellard | |
33 | f0cbd3ec | bellard | for (so = head->so_next; so != head; so = so->so_next) {
|
34 | f0cbd3ec | bellard | if (so->so_lport == lport &&
|
35 | f0cbd3ec | bellard | so->so_laddr.s_addr == laddr.s_addr && |
36 | f0cbd3ec | bellard | so->so_faddr.s_addr == faddr.s_addr && |
37 | f0cbd3ec | bellard | so->so_fport == fport) |
38 | f0cbd3ec | bellard | break;
|
39 | f0cbd3ec | bellard | } |
40 | f0cbd3ec | bellard | |
41 | f0cbd3ec | bellard | if (so == head)
|
42 | f0cbd3ec | bellard | return (struct socket *)NULL; |
43 | f0cbd3ec | bellard | return so;
|
44 | f0cbd3ec | bellard | |
45 | f0cbd3ec | bellard | } |
46 | f0cbd3ec | bellard | |
47 | f0cbd3ec | bellard | /*
|
48 | f0cbd3ec | bellard | * Create a new socket, initialise the fields
|
49 | f0cbd3ec | bellard | * It is the responsibility of the caller to
|
50 | f0cbd3ec | bellard | * insque() it into the correct linked-list
|
51 | f0cbd3ec | bellard | */
|
52 | f0cbd3ec | bellard | struct socket *
|
53 | f0cbd3ec | bellard | socreate() |
54 | f0cbd3ec | bellard | { |
55 | f0cbd3ec | bellard | struct socket *so;
|
56 | f0cbd3ec | bellard | |
57 | f0cbd3ec | bellard | so = (struct socket *)malloc(sizeof(struct socket)); |
58 | f0cbd3ec | bellard | if(so) {
|
59 | f0cbd3ec | bellard | memset(so, 0, sizeof(struct socket)); |
60 | f0cbd3ec | bellard | so->so_state = SS_NOFDREF; |
61 | f0cbd3ec | bellard | so->s = -1;
|
62 | f0cbd3ec | bellard | } |
63 | f0cbd3ec | bellard | return(so);
|
64 | f0cbd3ec | bellard | } |
65 | f0cbd3ec | bellard | |
66 | f0cbd3ec | bellard | /*
|
67 | f0cbd3ec | bellard | * remque and free a socket, clobber cache
|
68 | f0cbd3ec | bellard | */
|
69 | f0cbd3ec | bellard | void
|
70 | f0cbd3ec | bellard | sofree(so) |
71 | f0cbd3ec | bellard | struct socket *so;
|
72 | f0cbd3ec | bellard | { |
73 | f0cbd3ec | bellard | if (so->so_emu==EMU_RSH && so->extra) {
|
74 | f0cbd3ec | bellard | sofree(so->extra); |
75 | f0cbd3ec | bellard | so->extra=NULL;
|
76 | f0cbd3ec | bellard | } |
77 | f0cbd3ec | bellard | if (so == tcp_last_so)
|
78 | f0cbd3ec | bellard | tcp_last_so = &tcb; |
79 | f0cbd3ec | bellard | else if (so == udp_last_so) |
80 | f0cbd3ec | bellard | udp_last_so = &udb; |
81 | f0cbd3ec | bellard | |
82 | f0cbd3ec | bellard | m_free(so->so_m); |
83 | f0cbd3ec | bellard | |
84 | f0cbd3ec | bellard | if(so->so_next && so->so_prev)
|
85 | f0cbd3ec | bellard | remque(so); /* crashes if so is not in a queue */
|
86 | f0cbd3ec | bellard | |
87 | f0cbd3ec | bellard | free(so); |
88 | f0cbd3ec | bellard | } |
89 | f0cbd3ec | bellard | |
90 | f0cbd3ec | bellard | /*
|
91 | f0cbd3ec | bellard | * Read from so's socket into sb_snd, updating all relevant sbuf fields
|
92 | f0cbd3ec | bellard | * NOTE: This will only be called if it is select()ed for reading, so
|
93 | f0cbd3ec | bellard | * a read() of 0 (or less) means it's disconnected
|
94 | f0cbd3ec | bellard | */
|
95 | f0cbd3ec | bellard | int
|
96 | f0cbd3ec | bellard | soread(so) |
97 | f0cbd3ec | bellard | struct socket *so;
|
98 | f0cbd3ec | bellard | { |
99 | f0cbd3ec | bellard | int n, nn, lss, total;
|
100 | f0cbd3ec | bellard | struct sbuf *sb = &so->so_snd;
|
101 | f0cbd3ec | bellard | int len = sb->sb_datalen - sb->sb_cc;
|
102 | f0cbd3ec | bellard | struct iovec iov[2]; |
103 | f0cbd3ec | bellard | int mss = so->so_tcpcb->t_maxseg;
|
104 | f0cbd3ec | bellard | |
105 | f0cbd3ec | bellard | DEBUG_CALL("soread");
|
106 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long )so); |
107 | f0cbd3ec | bellard | |
108 | f0cbd3ec | bellard | /*
|
109 | f0cbd3ec | bellard | * No need to check if there's enough room to read.
|
110 | f0cbd3ec | bellard | * soread wouldn't have been called if there weren't
|
111 | f0cbd3ec | bellard | */
|
112 | f0cbd3ec | bellard | |
113 | f0cbd3ec | bellard | len = sb->sb_datalen - sb->sb_cc; |
114 | f0cbd3ec | bellard | |
115 | f0cbd3ec | bellard | iov[0].iov_base = sb->sb_wptr;
|
116 | f0cbd3ec | bellard | if (sb->sb_wptr < sb->sb_rptr) {
|
117 | f0cbd3ec | bellard | iov[0].iov_len = sb->sb_rptr - sb->sb_wptr;
|
118 | f0cbd3ec | bellard | /* Should never succeed, but... */
|
119 | f0cbd3ec | bellard | if (iov[0].iov_len > len) |
120 | f0cbd3ec | bellard | iov[0].iov_len = len;
|
121 | f0cbd3ec | bellard | if (iov[0].iov_len > mss) |
122 | f0cbd3ec | bellard | iov[0].iov_len -= iov[0].iov_len%mss; |
123 | f0cbd3ec | bellard | n = 1;
|
124 | f0cbd3ec | bellard | } else {
|
125 | f0cbd3ec | bellard | iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;
|
126 | f0cbd3ec | bellard | /* Should never succeed, but... */
|
127 | f0cbd3ec | bellard | if (iov[0].iov_len > len) iov[0].iov_len = len; |
128 | f0cbd3ec | bellard | len -= iov[0].iov_len;
|
129 | f0cbd3ec | bellard | if (len) {
|
130 | f0cbd3ec | bellard | iov[1].iov_base = sb->sb_data;
|
131 | f0cbd3ec | bellard | iov[1].iov_len = sb->sb_rptr - sb->sb_data;
|
132 | f0cbd3ec | bellard | if(iov[1].iov_len > len) |
133 | f0cbd3ec | bellard | iov[1].iov_len = len;
|
134 | f0cbd3ec | bellard | total = iov[0].iov_len + iov[1].iov_len; |
135 | f0cbd3ec | bellard | if (total > mss) {
|
136 | f0cbd3ec | bellard | lss = total%mss; |
137 | f0cbd3ec | bellard | if (iov[1].iov_len > lss) { |
138 | f0cbd3ec | bellard | iov[1].iov_len -= lss;
|
139 | f0cbd3ec | bellard | n = 2;
|
140 | f0cbd3ec | bellard | } else {
|
141 | f0cbd3ec | bellard | lss -= iov[1].iov_len;
|
142 | f0cbd3ec | bellard | iov[0].iov_len -= lss;
|
143 | f0cbd3ec | bellard | n = 1;
|
144 | f0cbd3ec | bellard | } |
145 | f0cbd3ec | bellard | } else
|
146 | f0cbd3ec | bellard | n = 2;
|
147 | f0cbd3ec | bellard | } else {
|
148 | f0cbd3ec | bellard | if (iov[0].iov_len > mss) |
149 | f0cbd3ec | bellard | iov[0].iov_len -= iov[0].iov_len%mss; |
150 | f0cbd3ec | bellard | n = 1;
|
151 | f0cbd3ec | bellard | } |
152 | f0cbd3ec | bellard | } |
153 | f0cbd3ec | bellard | |
154 | f0cbd3ec | bellard | #ifdef HAVE_READV
|
155 | f0cbd3ec | bellard | nn = readv(so->s, (struct iovec *)iov, n);
|
156 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
|
157 | f0cbd3ec | bellard | #else
|
158 | 02d2c54c | bellard | nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0); |
159 | f0cbd3ec | bellard | #endif
|
160 | f0cbd3ec | bellard | if (nn <= 0) { |
161 | f0cbd3ec | bellard | if (nn < 0 && (errno == EINTR || errno == EAGAIN)) |
162 | f0cbd3ec | bellard | return 0; |
163 | f0cbd3ec | bellard | else {
|
164 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno)));
|
165 | f0cbd3ec | bellard | sofcantrcvmore(so); |
166 | f0cbd3ec | bellard | tcp_sockclosed(sototcpcb(so)); |
167 | f0cbd3ec | bellard | return -1; |
168 | f0cbd3ec | bellard | } |
169 | f0cbd3ec | bellard | } |
170 | f0cbd3ec | bellard | |
171 | f0cbd3ec | bellard | #ifndef HAVE_READV
|
172 | f0cbd3ec | bellard | /*
|
173 | f0cbd3ec | bellard | * If there was no error, try and read the second time round
|
174 | f0cbd3ec | bellard | * We read again if n = 2 (ie, there's another part of the buffer)
|
175 | f0cbd3ec | bellard | * and we read as much as we could in the first read
|
176 | f0cbd3ec | bellard | * We don't test for <= 0 this time, because there legitimately
|
177 | f0cbd3ec | bellard | * might not be any more data (since the socket is non-blocking),
|
178 | f0cbd3ec | bellard | * a close will be detected on next iteration.
|
179 | f0cbd3ec | bellard | * A return of -1 wont (shouldn't) happen, since it didn't happen above
|
180 | f0cbd3ec | bellard | */
|
181 | 17444c9c | bellard | if (n == 2 && nn == iov[0].iov_len) { |
182 | 17444c9c | bellard | int ret;
|
183 | 17444c9c | bellard | ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0); |
184 | 17444c9c | bellard | if (ret > 0) |
185 | 17444c9c | bellard | nn += ret; |
186 | 17444c9c | bellard | } |
187 | f0cbd3ec | bellard | |
188 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
|
189 | f0cbd3ec | bellard | #endif
|
190 | f0cbd3ec | bellard | |
191 | f0cbd3ec | bellard | /* Update fields */
|
192 | f0cbd3ec | bellard | sb->sb_cc += nn; |
193 | f0cbd3ec | bellard | sb->sb_wptr += nn; |
194 | f0cbd3ec | bellard | if (sb->sb_wptr >= (sb->sb_data + sb->sb_datalen))
|
195 | f0cbd3ec | bellard | sb->sb_wptr -= sb->sb_datalen; |
196 | f0cbd3ec | bellard | return nn;
|
197 | f0cbd3ec | bellard | } |
198 | f0cbd3ec | bellard | |
199 | f0cbd3ec | bellard | /*
|
200 | f0cbd3ec | bellard | * Get urgent data
|
201 | f0cbd3ec | bellard | *
|
202 | f0cbd3ec | bellard | * When the socket is created, we set it SO_OOBINLINE,
|
203 | f0cbd3ec | bellard | * so when OOB data arrives, we soread() it and everything
|
204 | f0cbd3ec | bellard | * in the send buffer is sent as urgent data
|
205 | f0cbd3ec | bellard | */
|
206 | f0cbd3ec | bellard | void
|
207 | f0cbd3ec | bellard | sorecvoob(so) |
208 | f0cbd3ec | bellard | struct socket *so;
|
209 | f0cbd3ec | bellard | { |
210 | f0cbd3ec | bellard | struct tcpcb *tp = sototcpcb(so);
|
211 | f0cbd3ec | bellard | |
212 | f0cbd3ec | bellard | DEBUG_CALL("sorecvoob");
|
213 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
214 | f0cbd3ec | bellard | |
215 | f0cbd3ec | bellard | /*
|
216 | f0cbd3ec | bellard | * We take a guess at how much urgent data has arrived.
|
217 | f0cbd3ec | bellard | * In most situations, when urgent data arrives, the next
|
218 | f0cbd3ec | bellard | * read() should get all the urgent data. This guess will
|
219 | f0cbd3ec | bellard | * be wrong however if more data arrives just after the
|
220 | f0cbd3ec | bellard | * urgent data, or the read() doesn't return all the
|
221 | f0cbd3ec | bellard | * urgent data.
|
222 | f0cbd3ec | bellard | */
|
223 | f0cbd3ec | bellard | soread(so); |
224 | f0cbd3ec | bellard | tp->snd_up = tp->snd_una + so->so_snd.sb_cc; |
225 | f0cbd3ec | bellard | tp->t_force = 1;
|
226 | f0cbd3ec | bellard | tcp_output(tp); |
227 | f0cbd3ec | bellard | tp->t_force = 0;
|
228 | f0cbd3ec | bellard | } |
229 | f0cbd3ec | bellard | |
230 | f0cbd3ec | bellard | /*
|
231 | f0cbd3ec | bellard | * Send urgent data
|
232 | f0cbd3ec | bellard | * There's a lot duplicated code here, but...
|
233 | f0cbd3ec | bellard | */
|
234 | f0cbd3ec | bellard | int
|
235 | f0cbd3ec | bellard | sosendoob(so) |
236 | f0cbd3ec | bellard | struct socket *so;
|
237 | f0cbd3ec | bellard | { |
238 | f0cbd3ec | bellard | struct sbuf *sb = &so->so_rcv;
|
239 | f0cbd3ec | bellard | char buff[2048]; /* XXX Shouldn't be sending more oob data than this */ |
240 | f0cbd3ec | bellard | |
241 | f0cbd3ec | bellard | int n, len;
|
242 | f0cbd3ec | bellard | |
243 | f0cbd3ec | bellard | DEBUG_CALL("sosendoob");
|
244 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
245 | f0cbd3ec | bellard | DEBUG_ARG("sb->sb_cc = %d", sb->sb_cc);
|
246 | f0cbd3ec | bellard | |
247 | f0cbd3ec | bellard | if (so->so_urgc > 2048) |
248 | f0cbd3ec | bellard | so->so_urgc = 2048; /* XXXX */ |
249 | f0cbd3ec | bellard | |
250 | f0cbd3ec | bellard | if (sb->sb_rptr < sb->sb_wptr) {
|
251 | f0cbd3ec | bellard | /* We can send it directly */
|
252 | f0cbd3ec | bellard | n = send(so->s, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */
|
253 | f0cbd3ec | bellard | so->so_urgc -= n; |
254 | f0cbd3ec | bellard | |
255 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
|
256 | f0cbd3ec | bellard | } else {
|
257 | f0cbd3ec | bellard | /*
|
258 | f0cbd3ec | bellard | * Since there's no sendv or sendtov like writev,
|
259 | f0cbd3ec | bellard | * we must copy all data to a linear buffer then
|
260 | f0cbd3ec | bellard | * send it all
|
261 | f0cbd3ec | bellard | */
|
262 | f0cbd3ec | bellard | len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr; |
263 | f0cbd3ec | bellard | if (len > so->so_urgc) len = so->so_urgc;
|
264 | f0cbd3ec | bellard | memcpy(buff, sb->sb_rptr, len); |
265 | f0cbd3ec | bellard | so->so_urgc -= len; |
266 | f0cbd3ec | bellard | if (so->so_urgc) {
|
267 | f0cbd3ec | bellard | n = sb->sb_wptr - sb->sb_data; |
268 | f0cbd3ec | bellard | if (n > so->so_urgc) n = so->so_urgc;
|
269 | f0cbd3ec | bellard | memcpy((buff + len), sb->sb_data, n); |
270 | f0cbd3ec | bellard | so->so_urgc -= n; |
271 | f0cbd3ec | bellard | len += n; |
272 | f0cbd3ec | bellard | } |
273 | f0cbd3ec | bellard | n = send(so->s, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
|
274 | f0cbd3ec | bellard | #ifdef DEBUG
|
275 | f0cbd3ec | bellard | if (n != len)
|
276 | f0cbd3ec | bellard | DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
|
277 | f0cbd3ec | bellard | #endif
|
278 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n", n, so->so_urgc));
|
279 | f0cbd3ec | bellard | } |
280 | f0cbd3ec | bellard | |
281 | f0cbd3ec | bellard | sb->sb_cc -= n; |
282 | f0cbd3ec | bellard | sb->sb_rptr += n; |
283 | f0cbd3ec | bellard | if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen))
|
284 | f0cbd3ec | bellard | sb->sb_rptr -= sb->sb_datalen; |
285 | f0cbd3ec | bellard | |
286 | f0cbd3ec | bellard | return n;
|
287 | f0cbd3ec | bellard | } |
288 | f0cbd3ec | bellard | |
289 | f0cbd3ec | bellard | /*
|
290 | f0cbd3ec | bellard | * Write data from so_rcv to so's socket,
|
291 | f0cbd3ec | bellard | * updating all sbuf field as necessary
|
292 | f0cbd3ec | bellard | */
|
293 | f0cbd3ec | bellard | int
|
294 | f0cbd3ec | bellard | sowrite(so) |
295 | f0cbd3ec | bellard | struct socket *so;
|
296 | f0cbd3ec | bellard | { |
297 | f0cbd3ec | bellard | int n,nn;
|
298 | f0cbd3ec | bellard | struct sbuf *sb = &so->so_rcv;
|
299 | f0cbd3ec | bellard | int len = sb->sb_cc;
|
300 | f0cbd3ec | bellard | struct iovec iov[2]; |
301 | f0cbd3ec | bellard | |
302 | f0cbd3ec | bellard | DEBUG_CALL("sowrite");
|
303 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
304 | f0cbd3ec | bellard | |
305 | f0cbd3ec | bellard | if (so->so_urgc) {
|
306 | f0cbd3ec | bellard | sosendoob(so); |
307 | f0cbd3ec | bellard | if (sb->sb_cc == 0) |
308 | f0cbd3ec | bellard | return 0; |
309 | f0cbd3ec | bellard | } |
310 | f0cbd3ec | bellard | |
311 | f0cbd3ec | bellard | /*
|
312 | f0cbd3ec | bellard | * No need to check if there's something to write,
|
313 | f0cbd3ec | bellard | * sowrite wouldn't have been called otherwise
|
314 | f0cbd3ec | bellard | */
|
315 | f0cbd3ec | bellard | |
316 | f0cbd3ec | bellard | len = sb->sb_cc; |
317 | f0cbd3ec | bellard | |
318 | f0cbd3ec | bellard | iov[0].iov_base = sb->sb_rptr;
|
319 | f0cbd3ec | bellard | if (sb->sb_rptr < sb->sb_wptr) {
|
320 | f0cbd3ec | bellard | iov[0].iov_len = sb->sb_wptr - sb->sb_rptr;
|
321 | f0cbd3ec | bellard | /* Should never succeed, but... */
|
322 | f0cbd3ec | bellard | if (iov[0].iov_len > len) iov[0].iov_len = len; |
323 | f0cbd3ec | bellard | n = 1;
|
324 | f0cbd3ec | bellard | } else {
|
325 | f0cbd3ec | bellard | iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr;
|
326 | f0cbd3ec | bellard | if (iov[0].iov_len > len) iov[0].iov_len = len; |
327 | f0cbd3ec | bellard | len -= iov[0].iov_len;
|
328 | f0cbd3ec | bellard | if (len) {
|
329 | f0cbd3ec | bellard | iov[1].iov_base = sb->sb_data;
|
330 | f0cbd3ec | bellard | iov[1].iov_len = sb->sb_wptr - sb->sb_data;
|
331 | f0cbd3ec | bellard | if (iov[1].iov_len > len) iov[1].iov_len = len; |
332 | f0cbd3ec | bellard | n = 2;
|
333 | f0cbd3ec | bellard | } else
|
334 | f0cbd3ec | bellard | n = 1;
|
335 | f0cbd3ec | bellard | } |
336 | f0cbd3ec | bellard | /* Check if there's urgent data to send, and if so, send it */
|
337 | f0cbd3ec | bellard | |
338 | f0cbd3ec | bellard | #ifdef HAVE_READV
|
339 | f0cbd3ec | bellard | nn = writev(so->s, (const struct iovec *)iov, n); |
340 | f0cbd3ec | bellard | |
341 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
|
342 | f0cbd3ec | bellard | #else
|
343 | 02d2c54c | bellard | nn = send(so->s, iov[0].iov_base, iov[0].iov_len,0); |
344 | f0cbd3ec | bellard | #endif
|
345 | f0cbd3ec | bellard | /* This should never happen, but people tell me it does *shrug* */
|
346 | f0cbd3ec | bellard | if (nn < 0 && (errno == EAGAIN || errno == EINTR)) |
347 | f0cbd3ec | bellard | return 0; |
348 | f0cbd3ec | bellard | |
349 | f0cbd3ec | bellard | if (nn <= 0) { |
350 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
|
351 | f0cbd3ec | bellard | so->so_state, errno)); |
352 | f0cbd3ec | bellard | sofcantsendmore(so); |
353 | f0cbd3ec | bellard | tcp_sockclosed(sototcpcb(so)); |
354 | f0cbd3ec | bellard | return -1; |
355 | f0cbd3ec | bellard | } |
356 | f0cbd3ec | bellard | |
357 | f0cbd3ec | bellard | #ifndef HAVE_READV
|
358 | 3bc2175d | bellard | if (n == 2 && nn == iov[0].iov_len) { |
359 | 3bc2175d | bellard | int ret;
|
360 | 3bc2175d | bellard | ret = send(so->s, iov[1].iov_base, iov[1].iov_len,0); |
361 | 3bc2175d | bellard | if (ret > 0) |
362 | 3bc2175d | bellard | nn += ret; |
363 | 3bc2175d | bellard | } |
364 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
|
365 | f0cbd3ec | bellard | #endif
|
366 | f0cbd3ec | bellard | |
367 | f0cbd3ec | bellard | /* Update sbuf */
|
368 | f0cbd3ec | bellard | sb->sb_cc -= nn; |
369 | f0cbd3ec | bellard | sb->sb_rptr += nn; |
370 | f0cbd3ec | bellard | if (sb->sb_rptr >= (sb->sb_data + sb->sb_datalen))
|
371 | f0cbd3ec | bellard | sb->sb_rptr -= sb->sb_datalen; |
372 | f0cbd3ec | bellard | |
373 | f0cbd3ec | bellard | /*
|
374 | f0cbd3ec | bellard | * If in DRAIN mode, and there's no more data, set
|
375 | f0cbd3ec | bellard | * it CANTSENDMORE
|
376 | f0cbd3ec | bellard | */
|
377 | f0cbd3ec | bellard | if ((so->so_state & SS_FWDRAIN) && sb->sb_cc == 0) |
378 | f0cbd3ec | bellard | sofcantsendmore(so); |
379 | f0cbd3ec | bellard | |
380 | f0cbd3ec | bellard | return nn;
|
381 | f0cbd3ec | bellard | } |
382 | f0cbd3ec | bellard | |
383 | f0cbd3ec | bellard | /*
|
384 | f0cbd3ec | bellard | * recvfrom() a UDP socket
|
385 | f0cbd3ec | bellard | */
|
386 | f0cbd3ec | bellard | void
|
387 | f0cbd3ec | bellard | sorecvfrom(so) |
388 | f0cbd3ec | bellard | struct socket *so;
|
389 | f0cbd3ec | bellard | { |
390 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
391 | f0cbd3ec | bellard | int addrlen = sizeof(struct sockaddr_in); |
392 | f0cbd3ec | bellard | |
393 | f0cbd3ec | bellard | DEBUG_CALL("sorecvfrom");
|
394 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
395 | f0cbd3ec | bellard | |
396 | f0cbd3ec | bellard | if (so->so_type == IPPROTO_ICMP) { /* This is a "ping" reply */ |
397 | f0cbd3ec | bellard | char buff[256]; |
398 | f0cbd3ec | bellard | int len;
|
399 | f0cbd3ec | bellard | |
400 | f0cbd3ec | bellard | len = recvfrom(so->s, buff, 256, 0, |
401 | f0cbd3ec | bellard | (struct sockaddr *)&addr, &addrlen);
|
402 | f0cbd3ec | bellard | /* XXX Check if reply is "correct"? */
|
403 | f0cbd3ec | bellard | |
404 | f0cbd3ec | bellard | if(len == -1 || len == 0) { |
405 | f0cbd3ec | bellard | u_char code=ICMP_UNREACH_PORT; |
406 | f0cbd3ec | bellard | |
407 | f0cbd3ec | bellard | if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
|
408 | f0cbd3ec | bellard | else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; |
409 | f0cbd3ec | bellard | |
410 | f0cbd3ec | bellard | DEBUG_MISC((dfd," udp icmp rx errno = %d-%s\n",
|
411 | f0cbd3ec | bellard | errno,strerror(errno))); |
412 | f0cbd3ec | bellard | icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
|
413 | f0cbd3ec | bellard | } else {
|
414 | f0cbd3ec | bellard | icmp_reflect(so->so_m); |
415 | f0cbd3ec | bellard | so->so_m = 0; /* Don't m_free() it again! */ |
416 | f0cbd3ec | bellard | } |
417 | f0cbd3ec | bellard | /* No need for this socket anymore, udp_detach it */
|
418 | f0cbd3ec | bellard | udp_detach(so); |
419 | f0cbd3ec | bellard | } else { /* A "normal" UDP packet */ |
420 | f0cbd3ec | bellard | struct mbuf *m;
|
421 | f0cbd3ec | bellard | int len, n;
|
422 | f0cbd3ec | bellard | |
423 | f0cbd3ec | bellard | if (!(m = m_get())) return; |
424 | f0cbd3ec | bellard | m->m_data += if_maxlinkhdr; |
425 | f0cbd3ec | bellard | |
426 | f0cbd3ec | bellard | /*
|
427 | f0cbd3ec | bellard | * XXX Shouldn't FIONREAD packets destined for port 53,
|
428 | f0cbd3ec | bellard | * but I don't know the max packet size for DNS lookups
|
429 | f0cbd3ec | bellard | */
|
430 | f0cbd3ec | bellard | len = M_FREEROOM(m); |
431 | f0cbd3ec | bellard | /* if (so->so_fport != htons(53)) { */
|
432 | 379ff53d | bellard | ioctlsocket(so->s, FIONREAD, &n); |
433 | f0cbd3ec | bellard | |
434 | f0cbd3ec | bellard | if (n > len) {
|
435 | f0cbd3ec | bellard | n = (m->m_data - m->m_dat) + m->m_len + n + 1;
|
436 | f0cbd3ec | bellard | m_inc(m, n); |
437 | f0cbd3ec | bellard | len = M_FREEROOM(m); |
438 | f0cbd3ec | bellard | } |
439 | f0cbd3ec | bellard | /* } */
|
440 | f0cbd3ec | bellard | |
441 | f0cbd3ec | bellard | m->m_len = recvfrom(so->s, m->m_data, len, 0,
|
442 | f0cbd3ec | bellard | (struct sockaddr *)&addr, &addrlen);
|
443 | f0cbd3ec | bellard | DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
|
444 | f0cbd3ec | bellard | m->m_len, errno,strerror(errno))); |
445 | f0cbd3ec | bellard | if(m->m_len<0) { |
446 | f0cbd3ec | bellard | u_char code=ICMP_UNREACH_PORT; |
447 | f0cbd3ec | bellard | |
448 | f0cbd3ec | bellard | if(errno == EHOSTUNREACH) code=ICMP_UNREACH_HOST;
|
449 | f0cbd3ec | bellard | else if(errno == ENETUNREACH) code=ICMP_UNREACH_NET; |
450 | f0cbd3ec | bellard | |
451 | f0cbd3ec | bellard | DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));
|
452 | f0cbd3ec | bellard | icmp_error(so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
|
453 | f0cbd3ec | bellard | m_free(m); |
454 | f0cbd3ec | bellard | } else {
|
455 | f0cbd3ec | bellard | /*
|
456 | f0cbd3ec | bellard | * Hack: domain name lookup will be used the most for UDP,
|
457 | f0cbd3ec | bellard | * and since they'll only be used once there's no need
|
458 | f0cbd3ec | bellard | * for the 4 minute (or whatever) timeout... So we time them
|
459 | f0cbd3ec | bellard | * out much quicker (10 seconds for now...)
|
460 | f0cbd3ec | bellard | */
|
461 | f0cbd3ec | bellard | if (so->so_expire) {
|
462 | f0cbd3ec | bellard | if (so->so_fport == htons(53)) |
463 | f0cbd3ec | bellard | so->so_expire = curtime + SO_EXPIREFAST; |
464 | f0cbd3ec | bellard | else
|
465 | f0cbd3ec | bellard | so->so_expire = curtime + SO_EXPIRE; |
466 | f0cbd3ec | bellard | } |
467 | f0cbd3ec | bellard | |
468 | f0cbd3ec | bellard | /* if (m->m_len == len) {
|
469 | f0cbd3ec | bellard | * m_inc(m, MINCSIZE);
|
470 | f0cbd3ec | bellard | * m->m_len = 0;
|
471 | f0cbd3ec | bellard | * }
|
472 | f0cbd3ec | bellard | */
|
473 | f0cbd3ec | bellard | |
474 | f0cbd3ec | bellard | /*
|
475 | f0cbd3ec | bellard | * If this packet was destined for CTL_ADDR,
|
476 | f0cbd3ec | bellard | * make it look like that's where it came from, done by udp_output
|
477 | f0cbd3ec | bellard | */
|
478 | f0cbd3ec | bellard | udp_output(so, m, &addr); |
479 | f0cbd3ec | bellard | } /* rx error */
|
480 | f0cbd3ec | bellard | } /* if ping packet */
|
481 | f0cbd3ec | bellard | } |
482 | f0cbd3ec | bellard | |
483 | f0cbd3ec | bellard | /*
|
484 | f0cbd3ec | bellard | * sendto() a socket
|
485 | f0cbd3ec | bellard | */
|
486 | f0cbd3ec | bellard | int
|
487 | f0cbd3ec | bellard | sosendto(so, m) |
488 | f0cbd3ec | bellard | struct socket *so;
|
489 | f0cbd3ec | bellard | struct mbuf *m;
|
490 | f0cbd3ec | bellard | { |
491 | f0cbd3ec | bellard | int ret;
|
492 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
493 | f0cbd3ec | bellard | |
494 | f0cbd3ec | bellard | DEBUG_CALL("sosendto");
|
495 | f0cbd3ec | bellard | DEBUG_ARG("so = %lx", (long)so); |
496 | f0cbd3ec | bellard | DEBUG_ARG("m = %lx", (long)m); |
497 | f0cbd3ec | bellard | |
498 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
499 | f0cbd3ec | bellard | if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) { |
500 | f0cbd3ec | bellard | /* It's an alias */
|
501 | f0cbd3ec | bellard | switch(ntohl(so->so_faddr.s_addr) & 0xff) { |
502 | f0cbd3ec | bellard | case CTL_DNS:
|
503 | f0cbd3ec | bellard | addr.sin_addr = dns_addr; |
504 | f0cbd3ec | bellard | break;
|
505 | f0cbd3ec | bellard | case CTL_ALIAS:
|
506 | f0cbd3ec | bellard | default:
|
507 | f0cbd3ec | bellard | addr.sin_addr = loopback_addr; |
508 | f0cbd3ec | bellard | break;
|
509 | f0cbd3ec | bellard | } |
510 | f0cbd3ec | bellard | } else
|
511 | f0cbd3ec | bellard | addr.sin_addr = so->so_faddr; |
512 | f0cbd3ec | bellard | addr.sin_port = so->so_fport; |
513 | f0cbd3ec | bellard | |
514 | f0cbd3ec | bellard | 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)));
|
515 | f0cbd3ec | bellard | |
516 | f0cbd3ec | bellard | /* Don't care what port we get */
|
517 | f0cbd3ec | bellard | ret = sendto(so->s, m->m_data, m->m_len, 0,
|
518 | f0cbd3ec | bellard | (struct sockaddr *)&addr, sizeof (struct sockaddr)); |
519 | f0cbd3ec | bellard | if (ret < 0) |
520 | f0cbd3ec | bellard | return -1; |
521 | f0cbd3ec | bellard | |
522 | f0cbd3ec | bellard | /*
|
523 | f0cbd3ec | bellard | * Kill the socket if there's no reply in 4 minutes,
|
524 | f0cbd3ec | bellard | * but only if it's an expirable socket
|
525 | f0cbd3ec | bellard | */
|
526 | f0cbd3ec | bellard | if (so->so_expire)
|
527 | f0cbd3ec | bellard | so->so_expire = curtime + SO_EXPIRE; |
528 | f0cbd3ec | bellard | so->so_state = SS_ISFCONNECTED; /* So that it gets select()ed */
|
529 | f0cbd3ec | bellard | return 0; |
530 | f0cbd3ec | bellard | } |
531 | f0cbd3ec | bellard | |
532 | f0cbd3ec | bellard | /*
|
533 | f0cbd3ec | bellard | * XXX This should really be tcp_listen
|
534 | f0cbd3ec | bellard | */
|
535 | f0cbd3ec | bellard | struct socket *
|
536 | f0cbd3ec | bellard | solisten(port, laddr, lport, flags) |
537 | f0cbd3ec | bellard | u_int port; |
538 | f0cbd3ec | bellard | u_int32_t laddr; |
539 | f0cbd3ec | bellard | u_int lport; |
540 | f0cbd3ec | bellard | int flags;
|
541 | f0cbd3ec | bellard | { |
542 | f0cbd3ec | bellard | struct sockaddr_in addr;
|
543 | f0cbd3ec | bellard | struct socket *so;
|
544 | f0cbd3ec | bellard | int s, addrlen = sizeof(addr), opt = 1; |
545 | f0cbd3ec | bellard | |
546 | f0cbd3ec | bellard | DEBUG_CALL("solisten");
|
547 | f0cbd3ec | bellard | DEBUG_ARG("port = %d", port);
|
548 | f0cbd3ec | bellard | DEBUG_ARG("laddr = %x", laddr);
|
549 | f0cbd3ec | bellard | DEBUG_ARG("lport = %d", lport);
|
550 | f0cbd3ec | bellard | DEBUG_ARG("flags = %x", flags);
|
551 | f0cbd3ec | bellard | |
552 | f0cbd3ec | bellard | if ((so = socreate()) == NULL) { |
553 | f0cbd3ec | bellard | /* free(so); Not sofree() ??? free(NULL) == NOP */
|
554 | f0cbd3ec | bellard | return NULL; |
555 | f0cbd3ec | bellard | } |
556 | f0cbd3ec | bellard | |
557 | f0cbd3ec | bellard | /* Don't tcp_attach... we don't need so_snd nor so_rcv */
|
558 | f0cbd3ec | bellard | if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) { |
559 | f0cbd3ec | bellard | free(so); |
560 | f0cbd3ec | bellard | return NULL; |
561 | f0cbd3ec | bellard | } |
562 | f0cbd3ec | bellard | insque(so,&tcb); |
563 | f0cbd3ec | bellard | |
564 | f0cbd3ec | bellard | /*
|
565 | f0cbd3ec | bellard | * SS_FACCEPTONCE sockets must time out.
|
566 | f0cbd3ec | bellard | */
|
567 | f0cbd3ec | bellard | if (flags & SS_FACCEPTONCE)
|
568 | f0cbd3ec | bellard | so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;
|
569 | f0cbd3ec | bellard | |
570 | f0cbd3ec | bellard | so->so_state = (SS_FACCEPTCONN|flags); |
571 | f0cbd3ec | bellard | so->so_lport = lport; /* Kept in network format */
|
572 | f0cbd3ec | bellard | so->so_laddr.s_addr = laddr; /* Ditto */
|
573 | f0cbd3ec | bellard | |
574 | f0cbd3ec | bellard | addr.sin_family = AF_INET; |
575 | f0cbd3ec | bellard | addr.sin_addr.s_addr = INADDR_ANY; |
576 | f0cbd3ec | bellard | addr.sin_port = port; |
577 | f0cbd3ec | bellard | |
578 | f0cbd3ec | bellard | if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) || |
579 | b55669bf | pbrook | (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) || |
580 | f0cbd3ec | bellard | (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) || |
581 | f0cbd3ec | bellard | (listen(s,1) < 0)) { |
582 | f0cbd3ec | bellard | int tmperrno = errno; /* Don't clobber the real reason we failed */ |
583 | f0cbd3ec | bellard | |
584 | f0cbd3ec | bellard | close(s); |
585 | f0cbd3ec | bellard | sofree(so); |
586 | f0cbd3ec | bellard | /* Restore the real errno */
|
587 | 02d2c54c | bellard | #ifdef _WIN32
|
588 | 02d2c54c | bellard | WSASetLastError(tmperrno); |
589 | 02d2c54c | bellard | #else
|
590 | f0cbd3ec | bellard | errno = tmperrno; |
591 | 02d2c54c | bellard | #endif
|
592 | f0cbd3ec | bellard | return NULL; |
593 | f0cbd3ec | bellard | } |
594 | f0cbd3ec | bellard | setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); |
595 | f0cbd3ec | bellard | |
596 | f0cbd3ec | bellard | getsockname(s,(struct sockaddr *)&addr,&addrlen);
|
597 | f0cbd3ec | bellard | so->so_fport = addr.sin_port; |
598 | f0cbd3ec | bellard | if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) |
599 | 8dbca8dd | bellard | so->so_faddr = alias_addr; |
600 | f0cbd3ec | bellard | else
|
601 | f0cbd3ec | bellard | so->so_faddr = addr.sin_addr; |
602 | f0cbd3ec | bellard | |
603 | f0cbd3ec | bellard | so->s = s; |
604 | f0cbd3ec | bellard | return so;
|
605 | f0cbd3ec | bellard | } |
606 | f0cbd3ec | bellard | |
607 | f0cbd3ec | bellard | /*
|
608 | f0cbd3ec | bellard | * Data is available in so_rcv
|
609 | f0cbd3ec | bellard | * Just write() the data to the socket
|
610 | f0cbd3ec | bellard | * XXX not yet...
|
611 | f0cbd3ec | bellard | */
|
612 | f0cbd3ec | bellard | void
|
613 | f0cbd3ec | bellard | sorwakeup(so) |
614 | f0cbd3ec | bellard | struct socket *so;
|
615 | f0cbd3ec | bellard | { |
616 | f0cbd3ec | bellard | /* sowrite(so); */
|
617 | f0cbd3ec | bellard | /* FD_CLR(so->s,&writefds); */
|
618 | f0cbd3ec | bellard | } |
619 | f0cbd3ec | bellard | |
620 | f0cbd3ec | bellard | /*
|
621 | f0cbd3ec | bellard | * Data has been freed in so_snd
|
622 | f0cbd3ec | bellard | * We have room for a read() if we want to
|
623 | f0cbd3ec | bellard | * For now, don't read, it'll be done in the main loop
|
624 | f0cbd3ec | bellard | */
|
625 | f0cbd3ec | bellard | void
|
626 | f0cbd3ec | bellard | sowwakeup(so) |
627 | f0cbd3ec | bellard | struct socket *so;
|
628 | f0cbd3ec | bellard | { |
629 | f0cbd3ec | bellard | /* Nothing, yet */
|
630 | f0cbd3ec | bellard | } |
631 | f0cbd3ec | bellard | |
632 | f0cbd3ec | bellard | /*
|
633 | f0cbd3ec | bellard | * Various session state calls
|
634 | f0cbd3ec | bellard | * XXX Should be #define's
|
635 | f0cbd3ec | bellard | * The socket state stuff needs work, these often get call 2 or 3
|
636 | f0cbd3ec | bellard | * times each when only 1 was needed
|
637 | f0cbd3ec | bellard | */
|
638 | f0cbd3ec | bellard | void
|
639 | f0cbd3ec | bellard | soisfconnecting(so) |
640 | f0cbd3ec | bellard | register struct socket *so; |
641 | f0cbd3ec | bellard | { |
642 | f0cbd3ec | bellard | so->so_state &= ~(SS_NOFDREF|SS_ISFCONNECTED|SS_FCANTRCVMORE| |
643 | f0cbd3ec | bellard | SS_FCANTSENDMORE|SS_FWDRAIN); |
644 | f0cbd3ec | bellard | so->so_state |= SS_ISFCONNECTING; /* Clobber other states */
|
645 | f0cbd3ec | bellard | } |
646 | f0cbd3ec | bellard | |
647 | f0cbd3ec | bellard | void
|
648 | f0cbd3ec | bellard | soisfconnected(so) |
649 | f0cbd3ec | bellard | register struct socket *so; |
650 | f0cbd3ec | bellard | { |
651 | f0cbd3ec | bellard | so->so_state &= ~(SS_ISFCONNECTING|SS_FWDRAIN|SS_NOFDREF); |
652 | f0cbd3ec | bellard | so->so_state |= SS_ISFCONNECTED; /* Clobber other states */
|
653 | f0cbd3ec | bellard | } |
654 | f0cbd3ec | bellard | |
655 | f0cbd3ec | bellard | void
|
656 | f0cbd3ec | bellard | sofcantrcvmore(so) |
657 | f0cbd3ec | bellard | struct socket *so;
|
658 | f0cbd3ec | bellard | { |
659 | f0cbd3ec | bellard | if ((so->so_state & SS_NOFDREF) == 0) { |
660 | f0cbd3ec | bellard | shutdown(so->s,0);
|
661 | 02d2c54c | bellard | if(global_writefds) {
|
662 | 02d2c54c | bellard | FD_CLR(so->s,global_writefds); |
663 | 02d2c54c | bellard | } |
664 | f0cbd3ec | bellard | } |
665 | f0cbd3ec | bellard | so->so_state &= ~(SS_ISFCONNECTING); |
666 | f0cbd3ec | bellard | if (so->so_state & SS_FCANTSENDMORE)
|
667 | f0cbd3ec | bellard | so->so_state = SS_NOFDREF; /* Don't select it */ /* XXX close() here as well? */ |
668 | f0cbd3ec | bellard | else
|
669 | f0cbd3ec | bellard | so->so_state |= SS_FCANTRCVMORE; |
670 | f0cbd3ec | bellard | } |
671 | f0cbd3ec | bellard | |
672 | f0cbd3ec | bellard | void
|
673 | f0cbd3ec | bellard | sofcantsendmore(so) |
674 | f0cbd3ec | bellard | struct socket *so;
|
675 | f0cbd3ec | bellard | { |
676 | f0cbd3ec | bellard | if ((so->so_state & SS_NOFDREF) == 0) { |
677 | 02d2c54c | bellard | shutdown(so->s,1); /* send FIN to fhost */ |
678 | 02d2c54c | bellard | if (global_readfds) {
|
679 | 02d2c54c | bellard | FD_CLR(so->s,global_readfds); |
680 | 02d2c54c | bellard | } |
681 | 02d2c54c | bellard | if (global_xfds) {
|
682 | 02d2c54c | bellard | FD_CLR(so->s,global_xfds); |
683 | 02d2c54c | bellard | } |
684 | f0cbd3ec | bellard | } |
685 | f0cbd3ec | bellard | so->so_state &= ~(SS_ISFCONNECTING); |
686 | f0cbd3ec | bellard | if (so->so_state & SS_FCANTRCVMORE)
|
687 | f0cbd3ec | bellard | so->so_state = SS_NOFDREF; /* as above */
|
688 | f0cbd3ec | bellard | else
|
689 | f0cbd3ec | bellard | so->so_state |= SS_FCANTSENDMORE; |
690 | f0cbd3ec | bellard | } |
691 | f0cbd3ec | bellard | |
692 | f0cbd3ec | bellard | void
|
693 | f0cbd3ec | bellard | soisfdisconnected(so) |
694 | f0cbd3ec | bellard | struct socket *so;
|
695 | f0cbd3ec | bellard | { |
696 | f0cbd3ec | bellard | /* so->so_state &= ~(SS_ISFCONNECTING|SS_ISFCONNECTED); */
|
697 | f0cbd3ec | bellard | /* close(so->s); */
|
698 | f0cbd3ec | bellard | /* so->so_state = SS_ISFDISCONNECTED; */
|
699 | f0cbd3ec | bellard | /*
|
700 | f0cbd3ec | bellard | * XXX Do nothing ... ?
|
701 | f0cbd3ec | bellard | */
|
702 | f0cbd3ec | bellard | } |
703 | f0cbd3ec | bellard | |
704 | f0cbd3ec | bellard | /*
|
705 | f0cbd3ec | bellard | * Set write drain mode
|
706 | f0cbd3ec | bellard | * Set CANTSENDMORE once all data has been write()n
|
707 | f0cbd3ec | bellard | */
|
708 | f0cbd3ec | bellard | void
|
709 | f0cbd3ec | bellard | sofwdrain(so) |
710 | f0cbd3ec | bellard | struct socket *so;
|
711 | f0cbd3ec | bellard | { |
712 | f0cbd3ec | bellard | if (so->so_rcv.sb_cc)
|
713 | f0cbd3ec | bellard | so->so_state |= SS_FWDRAIN; |
714 | f0cbd3ec | bellard | else
|
715 | f0cbd3ec | bellard | sofcantsendmore(so); |
716 | f0cbd3ec | bellard | } |