| version 1.14, 1994/05/04 11:24:06 |
version 1.15, 1994/05/13 06:01:37 |
|
|
| /* |
/* |
| * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California. |
* Copyright (c) 1982, 1986, 1988, 1990, 1993 |
| * All rights reserved. |
* The Regents of the University of California. All rights reserved. |
| * |
* |
| * Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
| * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| * SUCH DAMAGE. |
* SUCH DAMAGE. |
| * |
* |
| * from: @(#)uipc_socket.c 7.28 (Berkeley) 5/4/91 |
* from: @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 |
| * $Id$ |
* $Id$ |
| */ |
*/ |
| |
|
| Line 71 socreate(dom, aso, type, proto) |
|
| Line 71 socreate(dom, aso, type, proto) |
|
| prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
| else |
else |
| prp = pffindtype(dom, type); |
prp = pffindtype(dom, type); |
| if (!prp || !prp->pr_usrreq) |
if (prp == 0 || prp->pr_usrreq == 0) |
| return (EPROTONOSUPPORT); |
return (EPROTONOSUPPORT); |
| if (prp->pr_type != type) |
if (prp->pr_type != type) |
| return (EPROTOTYPE); |
return (EPROTOTYPE); |
|
|
| return (error); |
return (error); |
| } |
} |
| |
|
| |
#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK) |
| /* |
/* |
| * Send on a socket. |
* Send on a socket. |
| * If send must go all at once and message is larger than |
* If send must go all at once and message is larger than |
| Line 325 sosend(so, addr, uio, top, control, flag |
|
| Line 326 sosend(so, addr, uio, top, control, flag |
|
| struct mbuf *control; |
struct mbuf *control; |
| int flags; |
int flags; |
| { |
{ |
| struct proc *p = curproc; /* XXX */ |
struct proc *p = curproc; /* XXX */ |
| struct mbuf **mp; |
struct mbuf **mp; |
| register struct mbuf *m; |
register struct mbuf *m; |
| register long space, len, resid; |
register long space, len, resid; |
| Line 354 sosend(so, addr, uio, top, control, flag |
|
| Line 355 sosend(so, addr, uio, top, control, flag |
|
| #define snderr(errno) { error = errno; splx(s); goto release; } |
#define snderr(errno) { error = errno; splx(s); goto release; } |
| |
|
| restart: |
restart: |
| if (error = sblock(&so->so_snd)) |
if (error = sblock(&so->so_snd, SBLOCKWAIT(flags))) |
| goto out; |
goto out; |
| do { |
do { |
| s = splnet(); |
s = splnet(); |
|
|
| MGET(m, M_WAIT, MT_DATA); |
MGET(m, M_WAIT, MT_DATA); |
| mlen = MLEN; |
mlen = MLEN; |
| } |
} |
| if (resid >= MINCLSIZE) { |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
| MCLGET(m, M_WAIT); |
MCLGET(m, M_WAIT); |
| if ((m->m_flags & M_EXT) == 0) |
if ((m->m_flags & M_EXT) == 0) |
| goto nopages; |
goto nopages; |
| mlen = MCLBYTES; |
mlen = MCLBYTES; |
| len = min(min(mlen, resid), space); |
#ifdef MAPPED_MBUFS |
| |
len = min(MCLBYTES, resid); |
| |
#else |
| |
if (atomic && top == 0) { |
| |
len = min(MCLBYTES - max_hdr, resid); |
| |
m->m_data += max_hdr; |
| |
} else |
| |
len = min(MCLBYTES, resid); |
| |
#endif |
| |
space -= MCLBYTES; |
| } else { |
} else { |
| nopages: |
nopages: |
| len = min(min(mlen, resid), space); |
len = min(min(mlen, resid), space); |
| |
space -= len; |
| /* |
/* |
| * For datagram protocols, leave room |
* For datagram protocols, leave room |
| * for protocol headers in first mbuf. |
* for protocol headers in first mbuf. |
|
|
| if (atomic && top == 0 && len < mlen) |
if (atomic && top == 0 && len < mlen) |
| MH_ALIGN(m, len); |
MH_ALIGN(m, len); |
| } |
} |
| space -= len; |
|
| error = uiomove(mtod(m, caddr_t), (int)len, uio); |
error = uiomove(mtod(m, caddr_t), (int)len, uio); |
| resid = uio->uio_resid; |
resid = uio->uio_resid; |
| m->m_len = len; |
m->m_len = len; |
| Line 492 soreceive(so, paddr, uio, mp0, controlp, |
|
| Line 502 soreceive(so, paddr, uio, mp0, controlp, |
|
| struct mbuf **controlp; |
struct mbuf **controlp; |
| int *flagsp; |
int *flagsp; |
| { |
{ |
| struct proc *p = curproc; /* XXX */ |
|
| register struct mbuf *m, **mp; |
register struct mbuf *m, **mp; |
| register int flags, len, error, s, offset; |
register int flags, len, error, s, offset; |
| struct protosw *pr = so->so_proto; |
struct protosw *pr = so->so_proto; |
|
|
| (struct mbuf *)0, (struct mbuf *)0); |
(struct mbuf *)0, (struct mbuf *)0); |
| |
|
| restart: |
restart: |
| if (error = sblock(&so->so_rcv)) |
if (error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) |
| return (error); |
return (error); |
| s = splnet(); |
s = splnet(); |
| |
|
|
|
| /* |
/* |
| * If we have less data than requested, block awaiting more |
* If we have less data than requested, block awaiting more |
| * (subject to any timeout) if: |
* (subject to any timeout) if: |
| * 1. the current count is less than the low water mark, or |
* 1. the current count is less than the low water mark, |
| * 2. MSG_WAITALL is set, and it is possible to do the entire |
* 2. MSG_WAITALL is set, and it is possible to do the entire |
| * receive operation at once if we block (resid <= hiwat). |
* receive operation at once if we block (resid <= hiwat), or |
| |
* 3. MSG_DONTWAIT is not set. |
| * If MSG_WAITALL is set but resid is larger than the receive buffer, |
* If MSG_WAITALL is set but resid is larger than the receive buffer, |
| * we have to do the receive in sections, and thus risk returning |
* we have to do the receive in sections, and thus risk returning |
| * a short count if a timeout or signal occurs after we start. |
* a short count if a timeout or signal occurs after we start. |
| */ |
*/ |
| while (m == 0 || so->so_rcv.sb_cc < uio->uio_resid && |
if (m == 0 || ((flags & MSG_DONTWAIT) == 0 && |
| |
so->so_rcv.sb_cc < uio->uio_resid) && |
| (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
| ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
| m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) { |
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) { |
|
|
| #endif |
#endif |
| if (so->so_error) { |
if (so->so_error) { |
| if (m) |
if (m) |
| break; |
goto dontblock; |
| error = so->so_error; |
error = so->so_error; |
| if ((flags & MSG_PEEK) == 0) |
if ((flags & MSG_PEEK) == 0) |
| so->so_error = 0; |
so->so_error = 0; |
|
|
| } |
} |
| if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
| if (m) |
if (m) |
| break; |
goto dontblock; |
| else |
else |
| goto release; |
goto release; |
| } |
} |
|
|
| } |
} |
| if (uio->uio_resid == 0) |
if (uio->uio_resid == 0) |
| goto release; |
goto release; |
| if (so->so_state & SS_NBIO) { |
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) { |
| error = EWOULDBLOCK; |
error = EWOULDBLOCK; |
| goto release; |
goto release; |
| } |
} |
|
|
| goto restart; |
goto restart; |
| } |
} |
| dontblock: |
dontblock: |
| p->p_stats->p_ru.ru_msgrcv++; |
#ifdef notyet /* XXXX */ |
| |
if (uio->uio_procp) |
| |
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
| |
#endif |
| nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
| if (pr->pr_flags & PR_ADDR) { |
if (pr->pr_flags & PR_ADDR) { |
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
|
|
| struct sockbuf asb; |
struct sockbuf asb; |
| |
|
| sb->sb_flags |= SB_NOINTR; |
sb->sb_flags |= SB_NOINTR; |
| (void) sblock(sb); |
(void) sblock(sb, M_WAITOK); |
| s = splimp(); |
s = splimp(); |
| socantrcvmore(so); |
socantrcvmore(so); |
| sbunlock(sb); |
sbunlock(sb); |
| Line 849 sosetopt(so, level, optname, m0) |
|
| Line 863 sosetopt(so, level, optname, m0) |
|
| case SO_USELOOPBACK: |
case SO_USELOOPBACK: |
| case SO_BROADCAST: |
case SO_BROADCAST: |
| case SO_REUSEADDR: |
case SO_REUSEADDR: |
| |
case SO_REUSEPORT: |
| case SO_OOBINLINE: |
case SO_OOBINLINE: |
| if (m == NULL || m->m_len < sizeof (int)) { |
if (m == NULL || m->m_len < sizeof (int)) { |
| error = EINVAL; |
error = EINVAL; |
| Line 922 sosetopt(so, level, optname, m0) |
|
| Line 937 sosetopt(so, level, optname, m0) |
|
| error = ENOPROTOOPT; |
error = ENOPROTOOPT; |
| break; |
break; |
| } |
} |
| |
if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { |
| |
(void) ((*so->so_proto->pr_ctloutput) |
| |
(PRCO_SETOPT, so, level, optname, &m0)); |
| |
m = NULL; /* freed by protocol */ |
| |
} |
| } |
} |
| bad: |
bad: |
| if (m) |
if (m) |
| Line 961 sogetopt(so, level, optname, mp) |
|
| Line 981 sogetopt(so, level, optname, mp) |
|
| case SO_DEBUG: |
case SO_DEBUG: |
| case SO_KEEPALIVE: |
case SO_KEEPALIVE: |
| case SO_REUSEADDR: |
case SO_REUSEADDR: |
| |
case SO_REUSEPORT: |
| case SO_BROADCAST: |
case SO_BROADCAST: |
| case SO_OOBINLINE: |
case SO_OOBINLINE: |
| *mtod(m, int *) = so->so_options & optname; |
*mtod(m, int *) = so->so_options & optname; |