uipc_socket.c revision 1.1 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd *
33 1.1 cgd * @(#)uipc_socket.c 7.28 (Berkeley) 5/4/91
34 1.1 cgd */
35 1.1 cgd
36 1.1 cgd #include "param.h"
37 1.1 cgd #include "proc.h"
38 1.1 cgd #include "file.h"
39 1.1 cgd #include "malloc.h"
40 1.1 cgd #include "mbuf.h"
41 1.1 cgd #include "domain.h"
42 1.1 cgd #include "kernel.h"
43 1.1 cgd #include "protosw.h"
44 1.1 cgd #include "socket.h"
45 1.1 cgd #include "socketvar.h"
46 1.1 cgd #include "resourcevar.h"
47 1.1 cgd
48 1.1 cgd /*
49 1.1 cgd * Socket operation routines.
50 1.1 cgd * These routines are called by the routines in
51 1.1 cgd * sys_socket.c or from a system process, and
52 1.1 cgd * implement the semantics of socket operations by
53 1.1 cgd * switching out to the protocol specific routines.
54 1.1 cgd */
55 1.1 cgd /*ARGSUSED*/
56 1.1 cgd socreate(dom, aso, type, proto)
57 1.1 cgd struct socket **aso;
58 1.1 cgd register int type;
59 1.1 cgd int proto;
60 1.1 cgd {
61 1.1 cgd struct proc *p = curproc; /* XXX */
62 1.1 cgd register struct protosw *prp;
63 1.1 cgd register struct socket *so;
64 1.1 cgd register int error;
65 1.1 cgd
66 1.1 cgd if (proto)
67 1.1 cgd prp = pffindproto(dom, proto, type);
68 1.1 cgd else
69 1.1 cgd prp = pffindtype(dom, type);
70 1.1 cgd if (prp == 0)
71 1.1 cgd return (EPROTONOSUPPORT);
72 1.1 cgd if (prp->pr_type != type)
73 1.1 cgd return (EPROTOTYPE);
74 1.1 cgd MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT);
75 1.1 cgd bzero((caddr_t)so, sizeof(*so));
76 1.1 cgd so->so_type = type;
77 1.1 cgd if (p->p_ucred->cr_uid == 0)
78 1.1 cgd so->so_state = SS_PRIV;
79 1.1 cgd so->so_proto = prp;
80 1.1 cgd error =
81 1.1 cgd (*prp->pr_usrreq)(so, PRU_ATTACH,
82 1.1 cgd (struct mbuf *)0, (struct mbuf *)proto, (struct mbuf *)0);
83 1.1 cgd if (error) {
84 1.1 cgd so->so_state |= SS_NOFDREF;
85 1.1 cgd sofree(so);
86 1.1 cgd return (error);
87 1.1 cgd }
88 1.1 cgd *aso = so;
89 1.1 cgd return (0);
90 1.1 cgd }
91 1.1 cgd
92 1.1 cgd sobind(so, nam)
93 1.1 cgd struct socket *so;
94 1.1 cgd struct mbuf *nam;
95 1.1 cgd {
96 1.1 cgd int s = splnet();
97 1.1 cgd int error;
98 1.1 cgd
99 1.1 cgd error =
100 1.1 cgd (*so->so_proto->pr_usrreq)(so, PRU_BIND,
101 1.1 cgd (struct mbuf *)0, nam, (struct mbuf *)0);
102 1.1 cgd splx(s);
103 1.1 cgd return (error);
104 1.1 cgd }
105 1.1 cgd
106 1.1 cgd solisten(so, backlog)
107 1.1 cgd register struct socket *so;
108 1.1 cgd int backlog;
109 1.1 cgd {
110 1.1 cgd int s = splnet(), error;
111 1.1 cgd
112 1.1 cgd error =
113 1.1 cgd (*so->so_proto->pr_usrreq)(so, PRU_LISTEN,
114 1.1 cgd (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0);
115 1.1 cgd if (error) {
116 1.1 cgd splx(s);
117 1.1 cgd return (error);
118 1.1 cgd }
119 1.1 cgd if (so->so_q == 0)
120 1.1 cgd so->so_options |= SO_ACCEPTCONN;
121 1.1 cgd if (backlog < 0)
122 1.1 cgd backlog = 0;
123 1.1 cgd so->so_qlimit = min(backlog, SOMAXCONN);
124 1.1 cgd splx(s);
125 1.1 cgd return (0);
126 1.1 cgd }
127 1.1 cgd
128 1.1 cgd sofree(so)
129 1.1 cgd register struct socket *so;
130 1.1 cgd {
131 1.1 cgd
132 1.1 cgd if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)
133 1.1 cgd return;
134 1.1 cgd if (so->so_head) {
135 1.1 cgd if (!soqremque(so, 0) && !soqremque(so, 1))
136 1.1 cgd panic("sofree dq");
137 1.1 cgd so->so_head = 0;
138 1.1 cgd }
139 1.1 cgd sbrelease(&so->so_snd);
140 1.1 cgd sorflush(so);
141 1.1 cgd FREE(so, M_SOCKET);
142 1.1 cgd }
143 1.1 cgd
144 1.1 cgd /*
145 1.1 cgd * Close a socket on last file table reference removal.
146 1.1 cgd * Initiate disconnect if connected.
147 1.1 cgd * Free socket when disconnect complete.
148 1.1 cgd */
149 1.1 cgd soclose(so)
150 1.1 cgd register struct socket *so;
151 1.1 cgd {
152 1.1 cgd int s = splnet(); /* conservative */
153 1.1 cgd int error = 0;
154 1.1 cgd
155 1.1 cgd if (so->so_options & SO_ACCEPTCONN) {
156 1.1 cgd while (so->so_q0)
157 1.1 cgd (void) soabort(so->so_q0);
158 1.1 cgd while (so->so_q)
159 1.1 cgd (void) soabort(so->so_q);
160 1.1 cgd }
161 1.1 cgd if (so->so_pcb == 0)
162 1.1 cgd goto discard;
163 1.1 cgd if (so->so_state & SS_ISCONNECTED) {
164 1.1 cgd if ((so->so_state & SS_ISDISCONNECTING) == 0) {
165 1.1 cgd error = sodisconnect(so);
166 1.1 cgd if (error)
167 1.1 cgd goto drop;
168 1.1 cgd }
169 1.1 cgd if (so->so_options & SO_LINGER) {
170 1.1 cgd if ((so->so_state & SS_ISDISCONNECTING) &&
171 1.1 cgd (so->so_state & SS_NBIO))
172 1.1 cgd goto drop;
173 1.1 cgd while (so->so_state & SS_ISCONNECTED)
174 1.1 cgd if (error = tsleep((caddr_t)&so->so_timeo,
175 1.1 cgd PSOCK | PCATCH, netcls, so->so_linger))
176 1.1 cgd break;
177 1.1 cgd }
178 1.1 cgd }
179 1.1 cgd drop:
180 1.1 cgd if (so->so_pcb) {
181 1.1 cgd int error2 =
182 1.1 cgd (*so->so_proto->pr_usrreq)(so, PRU_DETACH,
183 1.1 cgd (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0);
184 1.1 cgd if (error == 0)
185 1.1 cgd error = error2;
186 1.1 cgd }
187 1.1 cgd discard:
188 1.1 cgd if (so->so_state & SS_NOFDREF)
189 1.1 cgd panic("soclose: NOFDREF");
190 1.1 cgd so->so_state |= SS_NOFDREF;
191 1.1 cgd sofree(so);
192 1.1 cgd splx(s);
193 1.1 cgd return (error);
194 1.1 cgd }
195 1.1 cgd
196 1.1 cgd /*
197 1.1 cgd * Must be called at splnet...
198 1.1 cgd */
199 1.1 cgd soabort(so)
200 1.1 cgd struct socket *so;
201 1.1 cgd {
202 1.1 cgd
203 1.1 cgd return (
204 1.1 cgd (*so->so_proto->pr_usrreq)(so, PRU_ABORT,
205 1.1 cgd (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0));
206 1.1 cgd }
207 1.1 cgd
208 1.1 cgd soaccept(so, nam)
209 1.1 cgd register struct socket *so;
210 1.1 cgd struct mbuf *nam;
211 1.1 cgd {
212 1.1 cgd int s = splnet();
213 1.1 cgd int error;
214 1.1 cgd
215 1.1 cgd if ((so->so_state & SS_NOFDREF) == 0)
216 1.1 cgd panic("soaccept: !NOFDREF");
217 1.1 cgd so->so_state &= ~SS_NOFDREF;
218 1.1 cgd error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT,
219 1.1 cgd (struct mbuf *)0, nam, (struct mbuf *)0);
220 1.1 cgd splx(s);
221 1.1 cgd return (error);
222 1.1 cgd }
223 1.1 cgd
224 1.1 cgd soconnect(so, nam)
225 1.1 cgd register struct socket *so;
226 1.1 cgd struct mbuf *nam;
227 1.1 cgd {
228 1.1 cgd int s;
229 1.1 cgd int error;
230 1.1 cgd
231 1.1 cgd if (so->so_options & SO_ACCEPTCONN)
232 1.1 cgd return (EOPNOTSUPP);
233 1.1 cgd s = splnet();
234 1.1 cgd /*
235 1.1 cgd * If protocol is connection-based, can only connect once.
236 1.1 cgd * Otherwise, if connected, try to disconnect first.
237 1.1 cgd * This allows user to disconnect by connecting to, e.g.,
238 1.1 cgd * a null address.
239 1.1 cgd */
240 1.1 cgd if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING) &&
241 1.1 cgd ((so->so_proto->pr_flags & PR_CONNREQUIRED) ||
242 1.1 cgd (error = sodisconnect(so))))
243 1.1 cgd error = EISCONN;
244 1.1 cgd else
245 1.1 cgd error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,
246 1.1 cgd (struct mbuf *)0, nam, (struct mbuf *)0);
247 1.1 cgd splx(s);
248 1.1 cgd return (error);
249 1.1 cgd }
250 1.1 cgd
251 1.1 cgd soconnect2(so1, so2)
252 1.1 cgd register struct socket *so1;
253 1.1 cgd struct socket *so2;
254 1.1 cgd {
255 1.1 cgd int s = splnet();
256 1.1 cgd int error;
257 1.1 cgd
258 1.1 cgd error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2,
259 1.1 cgd (struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0);
260 1.1 cgd splx(s);
261 1.1 cgd return (error);
262 1.1 cgd }
263 1.1 cgd
264 1.1 cgd sodisconnect(so)
265 1.1 cgd register struct socket *so;
266 1.1 cgd {
267 1.1 cgd int s = splnet();
268 1.1 cgd int error;
269 1.1 cgd
270 1.1 cgd if ((so->so_state & SS_ISCONNECTED) == 0) {
271 1.1 cgd error = ENOTCONN;
272 1.1 cgd goto bad;
273 1.1 cgd }
274 1.1 cgd if (so->so_state & SS_ISDISCONNECTING) {
275 1.1 cgd error = EALREADY;
276 1.1 cgd goto bad;
277 1.1 cgd }
278 1.1 cgd error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT,
279 1.1 cgd (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0);
280 1.1 cgd bad:
281 1.1 cgd splx(s);
282 1.1 cgd return (error);
283 1.1 cgd }
284 1.1 cgd
285 1.1 cgd /*
286 1.1 cgd * Send on a socket.
287 1.1 cgd * If send must go all at once and message is larger than
288 1.1 cgd * send buffering, then hard error.
289 1.1 cgd * Lock against other senders.
290 1.1 cgd * If must go all at once and not enough room now, then
291 1.1 cgd * inform user that this would block and do nothing.
292 1.1 cgd * Otherwise, if nonblocking, send as much as possible.
293 1.1 cgd * The data to be sent is described by "uio" if nonzero,
294 1.1 cgd * otherwise by the mbuf chain "top" (which must be null
295 1.1 cgd * if uio is not). Data provided in mbuf chain must be small
296 1.1 cgd * enough to send all at once.
297 1.1 cgd *
298 1.1 cgd * Returns nonzero on error, timeout or signal; callers
299 1.1 cgd * must check for short counts if EINTR/ERESTART are returned.
300 1.1 cgd * Data and control buffers are freed on return.
301 1.1 cgd */
302 1.1 cgd sosend(so, addr, uio, top, control, flags)
303 1.1 cgd register struct socket *so;
304 1.1 cgd struct mbuf *addr;
305 1.1 cgd struct uio *uio;
306 1.1 cgd struct mbuf *top;
307 1.1 cgd struct mbuf *control;
308 1.1 cgd int flags;
309 1.1 cgd {
310 1.1 cgd struct proc *p = curproc; /* XXX */
311 1.1 cgd struct mbuf **mp;
312 1.1 cgd register struct mbuf *m;
313 1.1 cgd register long space, len, resid;
314 1.1 cgd int clen = 0, error, s, dontroute, mlen;
315 1.1 cgd int atomic = sosendallatonce(so) || top;
316 1.1 cgd
317 1.1 cgd if (uio)
318 1.1 cgd resid = uio->uio_resid;
319 1.1 cgd else
320 1.1 cgd resid = top->m_pkthdr.len;
321 1.1 cgd dontroute =
322 1.1 cgd (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
323 1.1 cgd (so->so_proto->pr_flags & PR_ATOMIC);
324 1.1 cgd p->p_stats->p_ru.ru_msgsnd++;
325 1.1 cgd if (control)
326 1.1 cgd clen = control->m_len;
327 1.1 cgd #define snderr(errno) { error = errno; splx(s); goto release; }
328 1.1 cgd
329 1.1 cgd restart:
330 1.1 cgd if (error = sblock(&so->so_snd))
331 1.1 cgd goto out;
332 1.1 cgd do {
333 1.1 cgd s = splnet();
334 1.1 cgd if (so->so_state & SS_CANTSENDMORE)
335 1.1 cgd snderr(EPIPE);
336 1.1 cgd if (so->so_error)
337 1.1 cgd snderr(so->so_error);
338 1.1 cgd if ((so->so_state & SS_ISCONNECTED) == 0) {
339 1.1 cgd if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
340 1.1 cgd if ((so->so_state & SS_ISCONFIRMING) == 0 &&
341 1.1 cgd !(resid == 0 && clen != 0))
342 1.1 cgd snderr(ENOTCONN);
343 1.1 cgd } else if (addr == 0)
344 1.1 cgd snderr(EDESTADDRREQ);
345 1.1 cgd }
346 1.1 cgd space = sbspace(&so->so_snd);
347 1.1 cgd if (flags & MSG_OOB)
348 1.1 cgd space += 1024;
349 1.1 cgd if (space < resid + clen &&
350 1.1 cgd (atomic || space < so->so_snd.sb_lowat || space < clen)) {
351 1.1 cgd if (atomic && resid > so->so_snd.sb_hiwat ||
352 1.1 cgd clen > so->so_snd.sb_hiwat)
353 1.1 cgd snderr(EMSGSIZE);
354 1.1 cgd if (so->so_state & SS_NBIO)
355 1.1 cgd snderr(EWOULDBLOCK);
356 1.1 cgd sbunlock(&so->so_snd);
357 1.1 cgd error = sbwait(&so->so_snd);
358 1.1 cgd splx(s);
359 1.1 cgd if (error)
360 1.1 cgd goto out;
361 1.1 cgd goto restart;
362 1.1 cgd }
363 1.1 cgd splx(s);
364 1.1 cgd mp = ⊤
365 1.1 cgd space -= clen;
366 1.1 cgd do {
367 1.1 cgd if (uio == NULL) {
368 1.1 cgd /*
369 1.1 cgd * Data is prepackaged in "top".
370 1.1 cgd */
371 1.1 cgd resid = 0;
372 1.1 cgd if (flags & MSG_EOR)
373 1.1 cgd top->m_flags |= M_EOR;
374 1.1 cgd } else do {
375 1.1 cgd if (top == 0) {
376 1.1 cgd MGETHDR(m, M_WAIT, MT_DATA);
377 1.1 cgd mlen = MHLEN;
378 1.1 cgd m->m_pkthdr.len = 0;
379 1.1 cgd m->m_pkthdr.rcvif = (struct ifnet *)0;
380 1.1 cgd } else {
381 1.1 cgd MGET(m, M_WAIT, MT_DATA);
382 1.1 cgd mlen = MLEN;
383 1.1 cgd }
384 1.1 cgd if (resid >= MINCLSIZE && space >= MCLBYTES) {
385 1.1 cgd MCLGET(m, M_WAIT);
386 1.1 cgd if ((m->m_flags & M_EXT) == 0)
387 1.1 cgd goto nopages;
388 1.1 cgd mlen = MCLBYTES;
389 1.1 cgd #ifdef MAPPED_MBUFS
390 1.1 cgd len = min(MCLBYTES, resid);
391 1.1 cgd #else
392 1.1 cgd if (top == 0) {
393 1.1 cgd len = min(MCLBYTES - max_hdr, resid);
394 1.1 cgd m->m_data += max_hdr;
395 1.1 cgd } else
396 1.1 cgd len = min(MCLBYTES, resid);
397 1.1 cgd #endif
398 1.1 cgd space -= MCLBYTES;
399 1.1 cgd } else {
400 1.1 cgd nopages:
401 1.1 cgd len = min(min(mlen, resid), space);
402 1.1 cgd space -= len;
403 1.1 cgd /*
404 1.1 cgd * For datagram protocols, leave room
405 1.1 cgd * for protocol headers in first mbuf.
406 1.1 cgd */
407 1.1 cgd if (atomic && top == 0 && len < mlen)
408 1.1 cgd MH_ALIGN(m, len);
409 1.1 cgd }
410 1.1 cgd error = uiomove(mtod(m, caddr_t), (int)len, uio);
411 1.1 cgd resid = uio->uio_resid;
412 1.1 cgd m->m_len = len;
413 1.1 cgd *mp = m;
414 1.1 cgd top->m_pkthdr.len += len;
415 1.1 cgd if (error)
416 1.1 cgd goto release;
417 1.1 cgd mp = &m->m_next;
418 1.1 cgd if (resid <= 0) {
419 1.1 cgd if (flags & MSG_EOR)
420 1.1 cgd top->m_flags |= M_EOR;
421 1.1 cgd break;
422 1.1 cgd }
423 1.1 cgd } while (space > 0 && atomic);
424 1.1 cgd if (dontroute)
425 1.1 cgd so->so_options |= SO_DONTROUTE;
426 1.1 cgd s = splnet(); /* XXX */
427 1.1 cgd error = (*so->so_proto->pr_usrreq)(so,
428 1.1 cgd (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
429 1.1 cgd top, addr, control);
430 1.1 cgd splx(s);
431 1.1 cgd if (dontroute)
432 1.1 cgd so->so_options &= ~SO_DONTROUTE;
433 1.1 cgd clen = 0;
434 1.1 cgd control = 0;
435 1.1 cgd top = 0;
436 1.1 cgd mp = ⊤
437 1.1 cgd if (error)
438 1.1 cgd goto release;
439 1.1 cgd } while (resid && space > 0);
440 1.1 cgd } while (resid);
441 1.1 cgd
442 1.1 cgd release:
443 1.1 cgd sbunlock(&so->so_snd);
444 1.1 cgd out:
445 1.1 cgd if (top)
446 1.1 cgd m_freem(top);
447 1.1 cgd if (control)
448 1.1 cgd m_freem(control);
449 1.1 cgd return (error);
450 1.1 cgd }
451 1.1 cgd
452 1.1 cgd /*
453 1.1 cgd * Implement receive operations on a socket.
454 1.1 cgd * We depend on the way that records are added to the sockbuf
455 1.1 cgd * by sbappend*. In particular, each record (mbufs linked through m_next)
456 1.1 cgd * must begin with an address if the protocol so specifies,
457 1.1 cgd * followed by an optional mbuf or mbufs containing ancillary data,
458 1.1 cgd * and then zero or more mbufs of data.
459 1.1 cgd * In order to avoid blocking network interrupts for the entire time here,
460 1.1 cgd * we splx() while doing the actual copy to user space.
461 1.1 cgd * Although the sockbuf is locked, new data may still be appended,
462 1.1 cgd * and thus we must maintain consistency of the sockbuf during that time.
463 1.1 cgd *
464 1.1 cgd * The caller may receive the data as a single mbuf chain by supplying
465 1.1 cgd * an mbuf **mp0 for use in returning the chain. The uio is then used
466 1.1 cgd * only for the count in uio_resid.
467 1.1 cgd */
468 1.1 cgd soreceive(so, paddr, uio, mp0, controlp, flagsp)
469 1.1 cgd register struct socket *so;
470 1.1 cgd struct mbuf **paddr;
471 1.1 cgd struct uio *uio;
472 1.1 cgd struct mbuf **mp0;
473 1.1 cgd struct mbuf **controlp;
474 1.1 cgd int *flagsp;
475 1.1 cgd {
476 1.1 cgd struct proc *p = curproc; /* XXX */
477 1.1 cgd register struct mbuf *m, **mp;
478 1.1 cgd register int flags, len, error, s, offset;
479 1.1 cgd struct protosw *pr = so->so_proto;
480 1.1 cgd struct mbuf *nextrecord;
481 1.1 cgd int moff, type;
482 1.1 cgd
483 1.1 cgd mp = mp0;
484 1.1 cgd if (paddr)
485 1.1 cgd *paddr = 0;
486 1.1 cgd if (controlp)
487 1.1 cgd *controlp = 0;
488 1.1 cgd if (flagsp)
489 1.1 cgd flags = *flagsp &~ MSG_EOR;
490 1.1 cgd else
491 1.1 cgd flags = 0;
492 1.1 cgd if (flags & MSG_OOB) {
493 1.1 cgd m = m_get(M_WAIT, MT_DATA);
494 1.1 cgd error = (*pr->pr_usrreq)(so, PRU_RCVOOB,
495 1.1 cgd m, (struct mbuf *)(flags & MSG_PEEK), (struct mbuf *)0);
496 1.1 cgd if (error)
497 1.1 cgd goto bad;
498 1.1 cgd do {
499 1.1 cgd error = uiomove(mtod(m, caddr_t),
500 1.1 cgd (int) min(uio->uio_resid, m->m_len), uio);
501 1.1 cgd m = m_free(m);
502 1.1 cgd } while (uio->uio_resid && error == 0 && m);
503 1.1 cgd bad:
504 1.1 cgd if (m)
505 1.1 cgd m_freem(m);
506 1.1 cgd return (error);
507 1.1 cgd }
508 1.1 cgd if (mp)
509 1.1 cgd *mp = (struct mbuf *)0;
510 1.1 cgd if (so->so_state & SS_ISCONFIRMING && uio->uio_resid)
511 1.1 cgd (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
512 1.1 cgd (struct mbuf *)0, (struct mbuf *)0);
513 1.1 cgd
514 1.1 cgd restart:
515 1.1 cgd if (error = sblock(&so->so_rcv))
516 1.1 cgd return (error);
517 1.1 cgd s = splnet();
518 1.1 cgd
519 1.1 cgd m = so->so_rcv.sb_mb;
520 1.1 cgd /*
521 1.1 cgd * If we have less data than requested, block awaiting more
522 1.1 cgd * (subject to any timeout) if:
523 1.1 cgd * 1. the current count is less than the low water mark, or
524 1.1 cgd * 2. MSG_WAITALL is set, and it is possible to do the entire
525 1.1 cgd * receive operation at once if we block (resid <= hiwat).
526 1.1 cgd * If MSG_WAITALL is set but resid is larger than the receive buffer,
527 1.1 cgd * we have to do the receive in sections, and thus risk returning
528 1.1 cgd * a short count if a timeout or signal occurs after we start.
529 1.1 cgd */
530 1.1 cgd while (m == 0 || so->so_rcv.sb_cc < uio->uio_resid &&
531 1.1 cgd (so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||
532 1.1 cgd ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&
533 1.1 cgd m->m_nextpkt == 0) {
534 1.1 cgd #ifdef DIAGNOSTIC
535 1.1 cgd if (m == 0 && so->so_rcv.sb_cc)
536 1.1 cgd panic("receive 1");
537 1.1 cgd #endif
538 1.1 cgd if (so->so_error) {
539 1.1 cgd if (m)
540 1.1 cgd break;
541 1.1 cgd error = so->so_error;
542 1.1 cgd if ((flags & MSG_PEEK) == 0)
543 1.1 cgd so->so_error = 0;
544 1.1 cgd goto release;
545 1.1 cgd }
546 1.1 cgd if (so->so_state & SS_CANTRCVMORE) {
547 1.1 cgd if (m)
548 1.1 cgd break;
549 1.1 cgd else
550 1.1 cgd goto release;
551 1.1 cgd }
552 1.1 cgd for (; m; m = m->m_next)
553 1.1 cgd if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) {
554 1.1 cgd m = so->so_rcv.sb_mb;
555 1.1 cgd goto dontblock;
556 1.1 cgd }
557 1.1 cgd if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) == 0 &&
558 1.1 cgd (so->so_proto->pr_flags & PR_CONNREQUIRED)) {
559 1.1 cgd error = ENOTCONN;
560 1.1 cgd goto release;
561 1.1 cgd }
562 1.1 cgd if (uio->uio_resid == 0)
563 1.1 cgd goto release;
564 1.1 cgd if (so->so_state & SS_NBIO) {
565 1.1 cgd error = EWOULDBLOCK;
566 1.1 cgd goto release;
567 1.1 cgd }
568 1.1 cgd sbunlock(&so->so_rcv);
569 1.1 cgd error = sbwait(&so->so_rcv);
570 1.1 cgd splx(s);
571 1.1 cgd if (error)
572 1.1 cgd return (error);
573 1.1 cgd goto restart;
574 1.1 cgd }
575 1.1 cgd dontblock:
576 1.1 cgd p->p_stats->p_ru.ru_msgrcv++;
577 1.1 cgd nextrecord = m->m_nextpkt;
578 1.1 cgd if (pr->pr_flags & PR_ADDR) {
579 1.1 cgd #ifdef DIAGNOSTIC
580 1.1 cgd if (m->m_type != MT_SONAME)
581 1.1 cgd panic("receive 1a");
582 1.1 cgd #endif
583 1.1 cgd if (flags & MSG_PEEK) {
584 1.1 cgd if (paddr)
585 1.1 cgd *paddr = m_copy(m, 0, m->m_len);
586 1.1 cgd m = m->m_next;
587 1.1 cgd } else {
588 1.1 cgd sbfree(&so->so_rcv, m);
589 1.1 cgd if (paddr) {
590 1.1 cgd *paddr = m;
591 1.1 cgd so->so_rcv.sb_mb = m->m_next;
592 1.1 cgd m->m_next = 0;
593 1.1 cgd m = so->so_rcv.sb_mb;
594 1.1 cgd } else {
595 1.1 cgd MFREE(m, so->so_rcv.sb_mb);
596 1.1 cgd m = so->so_rcv.sb_mb;
597 1.1 cgd }
598 1.1 cgd }
599 1.1 cgd }
600 1.1 cgd while (m && m->m_type == MT_CONTROL && error == 0) {
601 1.1 cgd if (flags & MSG_PEEK) {
602 1.1 cgd if (controlp)
603 1.1 cgd *controlp = m_copy(m, 0, m->m_len);
604 1.1 cgd m = m->m_next;
605 1.1 cgd } else {
606 1.1 cgd sbfree(&so->so_rcv, m);
607 1.1 cgd if (controlp) {
608 1.1 cgd if (pr->pr_domain->dom_externalize &&
609 1.1 cgd mtod(m, struct cmsghdr *)->cmsg_type ==
610 1.1 cgd SCM_RIGHTS)
611 1.1 cgd error = (*pr->pr_domain->dom_externalize)(m);
612 1.1 cgd *controlp = m;
613 1.1 cgd so->so_rcv.sb_mb = m->m_next;
614 1.1 cgd m->m_next = 0;
615 1.1 cgd m = so->so_rcv.sb_mb;
616 1.1 cgd } else {
617 1.1 cgd MFREE(m, so->so_rcv.sb_mb);
618 1.1 cgd m = so->so_rcv.sb_mb;
619 1.1 cgd }
620 1.1 cgd }
621 1.1 cgd if (controlp)
622 1.1 cgd controlp = &(*controlp)->m_next;
623 1.1 cgd }
624 1.1 cgd if (m) {
625 1.1 cgd if ((flags & MSG_PEEK) == 0)
626 1.1 cgd m->m_nextpkt = nextrecord;
627 1.1 cgd type = m->m_type;
628 1.1 cgd if (type == MT_OOBDATA)
629 1.1 cgd flags |= MSG_OOB;
630 1.1 cgd }
631 1.1 cgd moff = 0;
632 1.1 cgd offset = 0;
633 1.1 cgd while (m && uio->uio_resid > 0 && error == 0) {
634 1.1 cgd if (m->m_type == MT_OOBDATA) {
635 1.1 cgd if (type != MT_OOBDATA)
636 1.1 cgd break;
637 1.1 cgd } else if (type == MT_OOBDATA)
638 1.1 cgd break;
639 1.1 cgd #ifdef DIAGNOSTIC
640 1.1 cgd else if (m->m_type != MT_DATA && m->m_type != MT_HEADER)
641 1.1 cgd panic("receive 3");
642 1.1 cgd #endif
643 1.1 cgd so->so_state &= ~SS_RCVATMARK;
644 1.1 cgd len = uio->uio_resid;
645 1.1 cgd if (so->so_oobmark && len > so->so_oobmark - offset)
646 1.1 cgd len = so->so_oobmark - offset;
647 1.1 cgd if (len > m->m_len - moff)
648 1.1 cgd len = m->m_len - moff;
649 1.1 cgd /*
650 1.1 cgd * If mp is set, just pass back the mbufs.
651 1.1 cgd * Otherwise copy them out via the uio, then free.
652 1.1 cgd * Sockbuf must be consistent here (points to current mbuf,
653 1.1 cgd * it points to next record) when we drop priority;
654 1.1 cgd * we must note any additions to the sockbuf when we
655 1.1 cgd * block interrupts again.
656 1.1 cgd */
657 1.1 cgd if (mp == 0) {
658 1.1 cgd splx(s);
659 1.1 cgd error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio);
660 1.1 cgd s = splnet();
661 1.1 cgd } else
662 1.1 cgd uio->uio_resid -= len;
663 1.1 cgd if (len == m->m_len - moff) {
664 1.1 cgd if (m->m_flags & M_EOR)
665 1.1 cgd flags |= MSG_EOR;
666 1.1 cgd if (flags & MSG_PEEK) {
667 1.1 cgd m = m->m_next;
668 1.1 cgd moff = 0;
669 1.1 cgd } else {
670 1.1 cgd nextrecord = m->m_nextpkt;
671 1.1 cgd sbfree(&so->so_rcv, m);
672 1.1 cgd if (mp) {
673 1.1 cgd *mp = m;
674 1.1 cgd mp = &m->m_next;
675 1.1 cgd so->so_rcv.sb_mb = m = m->m_next;
676 1.1 cgd *mp = (struct mbuf *)0;
677 1.1 cgd } else {
678 1.1 cgd MFREE(m, so->so_rcv.sb_mb);
679 1.1 cgd m = so->so_rcv.sb_mb;
680 1.1 cgd }
681 1.1 cgd if (m)
682 1.1 cgd m->m_nextpkt = nextrecord;
683 1.1 cgd }
684 1.1 cgd } else {
685 1.1 cgd if (flags & MSG_PEEK)
686 1.1 cgd moff += len;
687 1.1 cgd else {
688 1.1 cgd if (mp)
689 1.1 cgd *mp = m_copym(m, 0, len, M_WAIT);
690 1.1 cgd m->m_data += len;
691 1.1 cgd m->m_len -= len;
692 1.1 cgd so->so_rcv.sb_cc -= len;
693 1.1 cgd }
694 1.1 cgd }
695 1.1 cgd if (so->so_oobmark) {
696 1.1 cgd if ((flags & MSG_PEEK) == 0) {
697 1.1 cgd so->so_oobmark -= len;
698 1.1 cgd if (so->so_oobmark == 0) {
699 1.1 cgd so->so_state |= SS_RCVATMARK;
700 1.1 cgd break;
701 1.1 cgd }
702 1.1 cgd } else
703 1.1 cgd offset += len;
704 1.1 cgd }
705 1.1 cgd if (flags & MSG_EOR)
706 1.1 cgd break;
707 1.1 cgd /*
708 1.1 cgd * If the MSG_WAITALL flag is set (for non-atomic socket),
709 1.1 cgd * we must not quit until "uio->uio_resid == 0" or an error
710 1.1 cgd * termination. If a signal/timeout occurs, return
711 1.1 cgd * with a short count but without error.
712 1.1 cgd * Keep sockbuf locked against other readers.
713 1.1 cgd */
714 1.1 cgd while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 &&
715 1.1 cgd !sosendallatonce(so)) {
716 1.1 cgd if (so->so_error || so->so_state & SS_CANTRCVMORE)
717 1.1 cgd break;
718 1.1 cgd error = sbwait(&so->so_rcv);
719 1.1 cgd if (error) {
720 1.1 cgd sbunlock(&so->so_rcv);
721 1.1 cgd splx(s);
722 1.1 cgd return (0);
723 1.1 cgd }
724 1.1 cgd if (m = so->so_rcv.sb_mb)
725 1.1 cgd nextrecord = m->m_nextpkt;
726 1.1 cgd }
727 1.1 cgd }
728 1.1 cgd if ((flags & MSG_PEEK) == 0) {
729 1.1 cgd if (m == 0)
730 1.1 cgd so->so_rcv.sb_mb = nextrecord;
731 1.1 cgd else if (pr->pr_flags & PR_ATOMIC) {
732 1.1 cgd flags |= MSG_TRUNC;
733 1.1 cgd (void) sbdroprecord(&so->so_rcv);
734 1.1 cgd }
735 1.1 cgd if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
736 1.1 cgd (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
737 1.1 cgd (struct mbuf *)flags, (struct mbuf *)0,
738 1.1 cgd (struct mbuf *)0);
739 1.1 cgd }
740 1.1 cgd if (flagsp)
741 1.1 cgd *flagsp |= flags;
742 1.1 cgd release:
743 1.1 cgd sbunlock(&so->so_rcv);
744 1.1 cgd splx(s);
745 1.1 cgd return (error);
746 1.1 cgd }
747 1.1 cgd
748 1.1 cgd soshutdown(so, how)
749 1.1 cgd register struct socket *so;
750 1.1 cgd register int how;
751 1.1 cgd {
752 1.1 cgd register struct protosw *pr = so->so_proto;
753 1.1 cgd
754 1.1 cgd how++;
755 1.1 cgd if (how & FREAD)
756 1.1 cgd sorflush(so);
757 1.1 cgd if (how & FWRITE)
758 1.1 cgd return ((*pr->pr_usrreq)(so, PRU_SHUTDOWN,
759 1.1 cgd (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0));
760 1.1 cgd return (0);
761 1.1 cgd }
762 1.1 cgd
763 1.1 cgd sorflush(so)
764 1.1 cgd register struct socket *so;
765 1.1 cgd {
766 1.1 cgd register struct sockbuf *sb = &so->so_rcv;
767 1.1 cgd register struct protosw *pr = so->so_proto;
768 1.1 cgd register int s;
769 1.1 cgd struct sockbuf asb;
770 1.1 cgd
771 1.1 cgd sb->sb_flags |= SB_NOINTR;
772 1.1 cgd (void) sblock(sb);
773 1.1 cgd s = splimp();
774 1.1 cgd socantrcvmore(so);
775 1.1 cgd sbunlock(sb);
776 1.1 cgd asb = *sb;
777 1.1 cgd bzero((caddr_t)sb, sizeof (*sb));
778 1.1 cgd splx(s);
779 1.1 cgd if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
780 1.1 cgd (*pr->pr_domain->dom_dispose)(asb.sb_mb);
781 1.1 cgd sbrelease(&asb);
782 1.1 cgd }
783 1.1 cgd
784 1.1 cgd sosetopt(so, level, optname, m0)
785 1.1 cgd register struct socket *so;
786 1.1 cgd int level, optname;
787 1.1 cgd struct mbuf *m0;
788 1.1 cgd {
789 1.1 cgd int error = 0;
790 1.1 cgd register struct mbuf *m = m0;
791 1.1 cgd
792 1.1 cgd if (level != SOL_SOCKET) {
793 1.1 cgd if (so->so_proto && so->so_proto->pr_ctloutput)
794 1.1 cgd return ((*so->so_proto->pr_ctloutput)
795 1.1 cgd (PRCO_SETOPT, so, level, optname, &m0));
796 1.1 cgd error = ENOPROTOOPT;
797 1.1 cgd } else {
798 1.1 cgd switch (optname) {
799 1.1 cgd
800 1.1 cgd case SO_LINGER:
801 1.1 cgd if (m == NULL || m->m_len != sizeof (struct linger)) {
802 1.1 cgd error = EINVAL;
803 1.1 cgd goto bad;
804 1.1 cgd }
805 1.1 cgd so->so_linger = mtod(m, struct linger *)->l_linger;
806 1.1 cgd /* fall thru... */
807 1.1 cgd
808 1.1 cgd case SO_DEBUG:
809 1.1 cgd case SO_KEEPALIVE:
810 1.1 cgd case SO_DONTROUTE:
811 1.1 cgd case SO_USELOOPBACK:
812 1.1 cgd case SO_BROADCAST:
813 1.1 cgd case SO_REUSEADDR:
814 1.1 cgd case SO_OOBINLINE:
815 1.1 cgd if (m == NULL || m->m_len < sizeof (int)) {
816 1.1 cgd error = EINVAL;
817 1.1 cgd goto bad;
818 1.1 cgd }
819 1.1 cgd if (*mtod(m, int *))
820 1.1 cgd so->so_options |= optname;
821 1.1 cgd else
822 1.1 cgd so->so_options &= ~optname;
823 1.1 cgd break;
824 1.1 cgd
825 1.1 cgd case SO_SNDBUF:
826 1.1 cgd case SO_RCVBUF:
827 1.1 cgd case SO_SNDLOWAT:
828 1.1 cgd case SO_RCVLOWAT:
829 1.1 cgd if (m == NULL || m->m_len < sizeof (int)) {
830 1.1 cgd error = EINVAL;
831 1.1 cgd goto bad;
832 1.1 cgd }
833 1.1 cgd switch (optname) {
834 1.1 cgd
835 1.1 cgd case SO_SNDBUF:
836 1.1 cgd case SO_RCVBUF:
837 1.1 cgd if (sbreserve(optname == SO_SNDBUF ?
838 1.1 cgd &so->so_snd : &so->so_rcv,
839 1.1 cgd (u_long) *mtod(m, int *)) == 0) {
840 1.1 cgd error = ENOBUFS;
841 1.1 cgd goto bad;
842 1.1 cgd }
843 1.1 cgd break;
844 1.1 cgd
845 1.1 cgd case SO_SNDLOWAT:
846 1.1 cgd so->so_snd.sb_lowat = *mtod(m, int *);
847 1.1 cgd break;
848 1.1 cgd case SO_RCVLOWAT:
849 1.1 cgd so->so_rcv.sb_lowat = *mtod(m, int *);
850 1.1 cgd break;
851 1.1 cgd }
852 1.1 cgd break;
853 1.1 cgd
854 1.1 cgd case SO_SNDTIMEO:
855 1.1 cgd case SO_RCVTIMEO:
856 1.1 cgd {
857 1.1 cgd struct timeval *tv;
858 1.1 cgd short val;
859 1.1 cgd
860 1.1 cgd if (m == NULL || m->m_len < sizeof (*tv)) {
861 1.1 cgd error = EINVAL;
862 1.1 cgd goto bad;
863 1.1 cgd }
864 1.1 cgd tv = mtod(m, struct timeval *);
865 1.1 cgd if (tv->tv_sec > SHRT_MAX / hz - hz) {
866 1.1 cgd error = EDOM;
867 1.1 cgd goto bad;
868 1.1 cgd }
869 1.1 cgd val = tv->tv_sec * hz + tv->tv_usec / tick;
870 1.1 cgd
871 1.1 cgd switch (optname) {
872 1.1 cgd
873 1.1 cgd case SO_SNDTIMEO:
874 1.1 cgd so->so_snd.sb_timeo = val;
875 1.1 cgd break;
876 1.1 cgd case SO_RCVTIMEO:
877 1.1 cgd so->so_rcv.sb_timeo = val;
878 1.1 cgd break;
879 1.1 cgd }
880 1.1 cgd break;
881 1.1 cgd }
882 1.1 cgd
883 1.1 cgd default:
884 1.1 cgd error = ENOPROTOOPT;
885 1.1 cgd break;
886 1.1 cgd }
887 1.1 cgd }
888 1.1 cgd bad:
889 1.1 cgd if (m)
890 1.1 cgd (void) m_free(m);
891 1.1 cgd return (error);
892 1.1 cgd }
893 1.1 cgd
894 1.1 cgd sogetopt(so, level, optname, mp)
895 1.1 cgd register struct socket *so;
896 1.1 cgd int level, optname;
897 1.1 cgd struct mbuf **mp;
898 1.1 cgd {
899 1.1 cgd register struct mbuf *m;
900 1.1 cgd
901 1.1 cgd if (level != SOL_SOCKET) {
902 1.1 cgd if (so->so_proto && so->so_proto->pr_ctloutput) {
903 1.1 cgd return ((*so->so_proto->pr_ctloutput)
904 1.1 cgd (PRCO_GETOPT, so, level, optname, mp));
905 1.1 cgd } else
906 1.1 cgd return (ENOPROTOOPT);
907 1.1 cgd } else {
908 1.1 cgd m = m_get(M_WAIT, MT_SOOPTS);
909 1.1 cgd m->m_len = sizeof (int);
910 1.1 cgd
911 1.1 cgd switch (optname) {
912 1.1 cgd
913 1.1 cgd case SO_LINGER:
914 1.1 cgd m->m_len = sizeof (struct linger);
915 1.1 cgd mtod(m, struct linger *)->l_onoff =
916 1.1 cgd so->so_options & SO_LINGER;
917 1.1 cgd mtod(m, struct linger *)->l_linger = so->so_linger;
918 1.1 cgd break;
919 1.1 cgd
920 1.1 cgd case SO_USELOOPBACK:
921 1.1 cgd case SO_DONTROUTE:
922 1.1 cgd case SO_DEBUG:
923 1.1 cgd case SO_KEEPALIVE:
924 1.1 cgd case SO_REUSEADDR:
925 1.1 cgd case SO_BROADCAST:
926 1.1 cgd case SO_OOBINLINE:
927 1.1 cgd *mtod(m, int *) = so->so_options & optname;
928 1.1 cgd break;
929 1.1 cgd
930 1.1 cgd case SO_TYPE:
931 1.1 cgd *mtod(m, int *) = so->so_type;
932 1.1 cgd break;
933 1.1 cgd
934 1.1 cgd case SO_ERROR:
935 1.1 cgd *mtod(m, int *) = so->so_error;
936 1.1 cgd so->so_error = 0;
937 1.1 cgd break;
938 1.1 cgd
939 1.1 cgd case SO_SNDBUF:
940 1.1 cgd *mtod(m, int *) = so->so_snd.sb_hiwat;
941 1.1 cgd break;
942 1.1 cgd
943 1.1 cgd case SO_RCVBUF:
944 1.1 cgd *mtod(m, int *) = so->so_rcv.sb_hiwat;
945 1.1 cgd break;
946 1.1 cgd
947 1.1 cgd case SO_SNDLOWAT:
948 1.1 cgd *mtod(m, int *) = so->so_snd.sb_lowat;
949 1.1 cgd break;
950 1.1 cgd
951 1.1 cgd case SO_RCVLOWAT:
952 1.1 cgd *mtod(m, int *) = so->so_rcv.sb_lowat;
953 1.1 cgd break;
954 1.1 cgd
955 1.1 cgd case SO_SNDTIMEO:
956 1.1 cgd case SO_RCVTIMEO:
957 1.1 cgd {
958 1.1 cgd int val = (optname == SO_SNDTIMEO ?
959 1.1 cgd so->so_snd.sb_timeo : so->so_rcv.sb_timeo);
960 1.1 cgd
961 1.1 cgd m->m_len = sizeof(struct timeval);
962 1.1 cgd mtod(m, struct timeval *)->tv_sec = val / hz;
963 1.1 cgd mtod(m, struct timeval *)->tv_usec =
964 1.1 cgd (val % hz) / tick;
965 1.1 cgd break;
966 1.1 cgd }
967 1.1 cgd
968 1.1 cgd default:
969 1.1 cgd (void)m_free(m);
970 1.1 cgd return (ENOPROTOOPT);
971 1.1 cgd }
972 1.1 cgd *mp = m;
973 1.1 cgd return (0);
974 1.1 cgd }
975 1.1 cgd }
976 1.1 cgd
977 1.1 cgd sohasoutofband(so)
978 1.1 cgd register struct socket *so;
979 1.1 cgd {
980 1.1 cgd struct proc *p;
981 1.1 cgd
982 1.1 cgd if (so->so_pgid < 0)
983 1.1 cgd gsignal(-so->so_pgid, SIGURG);
984 1.1 cgd else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)
985 1.1 cgd psignal(p, SIGURG);
986 1.1 cgd if (so->so_rcv.sb_sel) {
987 1.1 cgd selwakeup(so->so_rcv.sb_sel, so->so_rcv.sb_flags & SB_COLL);
988 1.1 cgd so->so_rcv.sb_sel = 0;
989 1.1 cgd so->so_rcv.sb_flags &= ~SB_COLL;
990 1.1 cgd }
991 1.1 cgd }
992