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