-firstempty(tp)
- register struct tcb *tp;
-{
- register struct th *p, *q;
-COUNT(FIRSTEMPTY);
-
- if ((p = tp->tcb_hd.seg_next) == (struct th *)tp ||
- tp->rcv_nxt < p->t_seq)
- return (tp->rcv_nxt);
- while ((q = p->t_next) != (struct th *)tp &&
- (t_end(p) + 1) == q->t_seq)
- p = q;
- return (t_end(p) + 1);
-}
-
-struct mbuf *
-tcp_sndcopy(tp, start, end)
- struct tcb *tp;
- u_long start, end;
-{
- register struct mbuf *m, *n, **np;
- u_long off;
- register int len;
- int adj;
- struct mbuf *top, *p;
-COUNT(TCP_SNDCOPY);
-
- if (start >= end)
- return (NULL);
- off = tp->snd_off;
- m = tp->t_socket->so_snd.sb_mb;
- while (m != NULL && start >= (off + m->m_len)) {
- off += m->m_len;
- m = m->m_next;
- }
- np = ⊤
- top = 0;
- adj = start - off;
- len = end - start;
- while (m && len > 0) {
- MGET(n, 1);
- *np = n;
- if (n == 0)
- goto nospace;
- n->m_len = MIN(len, m->m_len - adj);
- if (m->m_off > MMAXOFF) {
- p = mtod(m, struct mbuf *);
- n->m_off = ((int)p - (int)n) + adj;
- mprefcnt[mtopf(p)]++;
- } else {
- n->m_off = MMINOFF;
- bcopy(mtod(m, caddr_t)+adj, mtod(n, caddr_t),
- n->m_len);
- }
- len -= n->m_len;
- adj = 0;
- m = m->m_next;
- /* SHOULD TRY PACKING INTO SMALL MBUFS HERE */
- np = &n->m_next;
- }
- /* SHOULD NEVER RUN OUT OF m WHEN LEN */
- if (len)
- printf("snd_copy: m %x len %d\n", m, len);
- return (top);
-nospace:
- printf("snd_copy: no space\n");
- m_freem(top);
- return (0);
-}
-