rem: int orig_resid = uio->uio_resid;
add: uint orig_resid = uio->uio_resid;
context: static int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, struct mbuf**mp0,		struct mbuf **controlp, int *flagsp){	struct mbuf *m, **mp;	int flags = 0;	int len, error = 0, offset;	struct mbuf *nextrecord;	int moff, type = 0;	int orig_resid = uio->uio_resid;	struct protosw *pr = so->so_proto;	mp = mp0;	if (paddr)		*paddr = NULL;	if (controlp)		*controlp = NULL;	/* ensure we don't have MSG_EOR set */	if (flagsp)		flags = (*flagsp) & ~MSG_EOR;	if (flags & MSG_OOB) {		m = m_get(MT_DATA);		error = (*pr->pr_userreq)(so, PRU_RCVOOB, m, (struct mbuf*)(flags & MSG_PEEK), NULL);		if (error)			goto bad;		do {			error = uiomove(mtod(m, caddr_t), (int) min(uio->uio_resid, m->m_len), uio);			m = m_free(m);		} while (uio->uio_resid && error == 0 && m);bad:		if (m)			m_freem(m);		return error;	}	if (mp)		*mp = NULL;	if ((so->so_state & SS_ISCONFIRMING) && uio->uio_resid)		(*pr->pr_userreq)(so, PRU_RCVD, NULL, NULL, NULL);		restart:	if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))))		return error;	m = so->so_rcv.sb_mb;	/*	 * If we have less data than requested, block awaiting more	 * (subject to any timeout) if:	 *   1. the current count is less than the low water mark,	 *   2. MSG_WAITALL is set, and it is possible to do the entire	 *	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,	 * we have to do the receive in sections, and thus risk returning	 * a short count if a timeout or signal occurs after we start.	 */	if (m == NULL || (((flags & MSG_DONTWAIT) == 0 &&	    so->so_rcv.sb_cc < uio->uio_resid) &&	    (so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||	    ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&	    m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) {		if (so->so_error) {			if (m)				goto dontblock;			error = so->so_error;			if ((flags & MSG_PEEK) == 0)				so->so_error = 0;			goto release;		}		if ((so->so_state & SS_CANTRCVMORE)) {			if (m)				goto dontblock;			else				goto release;		}		for (;m; m = m->m_next)			if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) {				m = so->so_rcv.sb_mb;				goto dontblock;			}		if ((so->so_state & (SS_ISCONNECTED | SS_ISCONNECTING)) == 0 &&			(so->so_proto->pr_flags & PR_CONNREQUIRED)) {			error = ENOTCONN;			goto release;		}		if (uio->uio_resid == 0)			goto release;		if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {			error = EWOULDBLOCK;				goto release;		}		sbunlock(&so->so_rcv);		error = sockbuf_wait(&so->so_rcv);		if (error)			return error;		goto restart;	}dontblock:	nextrecord = m->m_nextpkt;	if (pr->pr_flags & PR_ADDR) {		orig_resid = 0;		if (flags & MSG_PEEK) {			if (!paddr)				*paddr = m_copym(m, 0, m->m_len);			m = m->m_next;		} else {			sbfree(&so->so_rcv, m);			if (paddr) {				*paddr = m;				so->so_rcv.sb_mb = m->m_next;				m->m_next = NULL;				m = so->so_rcv.sb_mb;			} else {				MFREE(m, so->so_rcv.sb_mb);				m = so->so_rcv.sb_mb;			}		}	}	while (m && m->m_type == MT_CONTROL && error == 0) {		if ((flags & MSG_PEEK)) {			if (controlp)				*controlp = m_copym(m, 0, m->m_len);			m = m->m_next;		} else {			sbfree(&so->so_rcv, m);			if (controlp) {				/* XXX technically we should look at control rights here,				 * but so far we have no notion of them...				 */				*controlp = m;				so->so_rcv.sb_mb = m->m_next;				m->m_next = NULL;				m = so->so_rcv.sb_mb;			} else {				MFREE(m, so->so_rcv.sb_mb);				m = so->so_rcv.sb_mb;			}		}		if (controlp) {			orig_resid = 0;			controlp = &(*controlp)->m_next;		}	}	if (m) {		if ((flags & MSG_PEEK) == 0)			m->m_nextpkt = nextrecord;		type = m->m_type;		if (type == MT_OOBDATA)			flags |= MSG_OOB;	}	moff = 0;	offset = 0;	while (m && uio->uio_resid > 0 && error == 0) {		if (m->m_type == MT_OOBDATA) {			if (type != MT_OOBDATA)				break;		} else if (type == MT_OOBDATA) {				break;		}		so->so_state &= ~SS_RCVATMARK;		len = uio->uio_resid;		if (so->so_oobmark && len > so->so_oobmark - offset)			len = so->so_oobmark - offset;		if (len > m->m_len - moff)			len = m->m_len - moff;		if (!mp)			error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio);		else			uio->uio_resid -= len;		if (len == m->m_len - moff) {			if (m->m_flags & M_EOR)				flags |= MSG_EOR;			if (flags & MSG_PEEK) {				m = m->m_next;				moff = 0;			} else {				nextrecord = m->m_nextpkt;				sbfree(&so->so_rcv, m);				if (mp) {					*mp = m;					mp = &m->m_next;					so->so_rcv.sb_mb = m = m->m_next;					*mp = NULL;				} else {					MFREE(m, so->so_rcv.sb_mb);					m = so->so_rcv.sb_mb;				}				if (m)					m->m_nextpkt = nextrecord;			}		} else {			if ((flags & MSG_PEEK))				moff += len;			else {				if (mp)					*mp = m_copym(m, 0, len);				m->m_data += len;				m->m_len -= len;				so->so_rcv.sb_cc -= len;			}		}		if (so->so_oobmark) {			if ((flags & MSG_PEEK) == 0) {				so->so_oobmark -= len;				if (so->so_oobmark == 0) {					so->so_state |= SS_RCVATMARK;					break;				}			} else {				offset += len;				if (offset == so->so_oobmark)					break;			}		}		if (flags & MSG_EOR)			break;		while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 &&		       !sosendallatonce(so) && !nextrecord) {			if (so->so_error || so->so_state & SS_CANTRCVMORE)				break;			error = sockbuf_wait(&so->so_rcv);			if (error) {				sbunlock(&so->so_rcv);				return 0;			}			if ((m = so->so_rcv.sb_mb))				nextrecord = m->m_nextpkt;		}	}	if (m && pr->pr_flags & PR_ATOMIC) {		flags |= MSG_TRUNC;		if ((flags & MSG_PEEK) == 0) 			sockbuf_droprecord(&so->so_rcv);	}	if ((flags & MSG_PEEK) == 0) {		if (!m)			so->so_rcv.sb_mb = nextrecord;		if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)			(*pr->pr_userreq)(so, PRU_RCVD, (struct mbuf*)flags, NULL, NULL);	}	if (orig_resid == uio->uio_resid && orig_resid &&		(flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {		sbunlock(&so->so_rcv);		goto restart;	}	if (flagsp)		*flagsp |= flags;release:	sbunlock(&so->so_rcv);	return error;}