version 1.6.2.1, 1993/09/24 08:51:53 |
version 1.11, 1994/04/25 08:22:07 |
|
|
* $Id$ |
* $Id$ |
*/ |
*/ |
|
|
#include "param.h" |
#include <sys/param.h> |
#include "systm.h" |
#include <sys/systm.h> |
#include "proc.h" |
#include <sys/proc.h> |
#include "file.h" |
#include <sys/file.h> |
#include "malloc.h" |
#include <sys/malloc.h> |
#include "mbuf.h" |
#include <sys/mbuf.h> |
#include "domain.h" |
#include <sys/domain.h> |
#include "kernel.h" |
#include <sys/kernel.h> |
#include "select.h" |
#include <sys/protosw.h> |
#include "protosw.h" |
#include <sys/socket.h> |
#include "socket.h" |
#include <sys/socketvar.h> |
#include "socketvar.h" |
#include <sys/resourcevar.h> |
#include "resourcevar.h" |
|
|
|
#include "machine/cpu.h" |
|
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
socreate(dom, aso, type, proto) |
socreate(dom, aso, type, proto) |
|
int dom; |
struct socket **aso; |
struct socket **aso; |
register int type; |
register int type; |
int proto; |
int proto; |
Line 91 socreate(dom, aso, type, proto) |
|
Line 89 socreate(dom, aso, type, proto) |
|
sofree(so); |
sofree(so); |
return (error); |
return (error); |
} |
} |
|
#ifdef COMPAT_SUNOS |
|
if (p->p_emul == EMUL_SUNOS && type == SOCK_DGRAM) |
|
so->so_options |= SO_BROADCAST; |
|
#endif |
*aso = so; |
*aso = so; |
return (0); |
return (0); |
} |
} |
Line 323 sosend(so, addr, uio, top, control, flag |
|
Line 325 sosend(so, addr, uio, top, control, flag |
|
struct mbuf *control; |
struct mbuf *control; |
int flags; |
int flags; |
{ |
{ |
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 334 sosend(so, addr, uio, top, control, flag |
|
Line 335 sosend(so, addr, uio, top, control, flag |
|
resid = uio->uio_resid; |
resid = uio->uio_resid; |
else |
else |
resid = top->m_pkthdr.len; |
resid = top->m_pkthdr.len; |
|
/* |
|
* In theory resid should be unsigned. |
|
* However, space must be signed, as it might be less than 0 |
|
* if we over-committed, and we must use a signed comparison |
|
* of space and resid. On the other hand, a negative resid |
|
* causes us to loop sending 0-length segments to the protocol. |
|
*/ |
|
if (resid < 0) |
|
return (EINVAL); |
dontroute = |
dontroute = |
(flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && |
(flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && |
(so->so_proto->pr_flags & PR_ATOMIC); |
(so->so_proto->pr_flags & PR_ATOMIC); |
p->p_stats->p_ru.ru_msgsnd++; |
if (uio->uio_procp) |
|
uio->uio_procp->p_stats->p_ru.ru_msgsnd++; |
if (control) |
if (control) |
clen = control->m_len; |
clen = control->m_len; |
#define snderr(errno) { error = errno; splx(s); goto release; } |
#define snderr(errno) { error = errno; splx(s); goto release; } |
|
|
space = sbspace(&so->so_snd); |
space = sbspace(&so->so_snd); |
if (flags & MSG_OOB) |
if (flags & MSG_OOB) |
space += 1024; |
space += 1024; |
if (space < resid + clen && |
if (atomic && resid > so->so_snd.sb_hiwat || |
|
clen > so->so_snd.sb_hiwat) |
|
snderr(EMSGSIZE); |
|
if (space < resid + clen && uio && |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
if (atomic && resid > so->so_snd.sb_hiwat || |
|
clen > so->so_snd.sb_hiwat) |
|
snderr(EMSGSIZE); |
|
if (so->so_state & SS_NBIO) |
if (so->so_state & SS_NBIO) |
snderr(EWOULDBLOCK); |
snderr(EWOULDBLOCK); |
sbunlock(&so->so_snd); |
sbunlock(&so->so_snd); |
|
|
if ((m->m_flags & M_EXT) == 0) |
if ((m->m_flags & M_EXT) == 0) |
goto nopages; |
goto nopages; |
mlen = MCLBYTES; |
mlen = MCLBYTES; |
#ifdef MAPPED_MBUFS |
len = min(min(mlen, resid), space); |
len = min(MCLBYTES, resid); |
|
#else |
|
if (top == 0) { |
|
len = min(MCLBYTES - max_hdr, resid); |
|
m->m_data += max_hdr; |
|
} else |
|
len = min(MCLBYTES, resid); |
|
#endif |
|
len = min(len, space); |
|
space -= len; |
|
} 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 491 soreceive(so, paddr, uio, mp0, controlp, |
|
Line 492 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; |
|
|
goto restart; |
goto restart; |
} |
} |
dontblock: |
dontblock: |
p->p_stats->p_ru.ru_msgrcv++; |
if (uio->uio_procp) |
|
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
if (pr->pr_flags & PR_ADDR) { |
if (pr->pr_flags & PR_ADDR) { |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
|
|
so->so_state |= SS_RCVATMARK; |
so->so_state |= SS_RCVATMARK; |
break; |
break; |
} |
} |
} else |
} else { |
offset += len; |
offset += len; |
|
if (offset == so->so_oobmark) |
|
break; |
|
} |
} |
} |
if (flags & MSG_EOR) |
if (flags & MSG_EOR) |
break; |
break; |