- /*
- * Pre-packetize the data in the sockbuf
- * according to negotiated mtu. Do it here
- * where we can safely wait for mbufs.
- *
- * This presumes knowledge of sockbuf conventions.
- */
- if (n = sb->sb_mb)
- while (n->m_act)
- n = n->m_act;
- if ((nn = n) && n->m_pkthdr.len < maxsize) {
- u_int space = maxsize - n->m_pkthdr.len;
-
- do {
- if (n->m_flags & M_EOR)
- goto on1;
- } while (n->m_next && (n = n->m_next));
- if (totlen <= space) {
- TPNagle1++;
- n->m_next = m;
- nn->m_pkthdr.len += totlen;
- while (n = n->m_next)
- sballoc(sb, n);
- if (eotsdu)
- nn->m_flags |= M_EOR;
- goto on2;
- } else {
- /*
- * Can't sleep here, because when you wake up
- * packet you want to attach to may be gone!
- */
- if (TNew && (n->m_next = m_copym(m, 0, space, M_NOWAIT))) {
- nn->m_pkthdr.len += space;
- TPNagle2++;
- while (n = n->m_next)
- sballoc(sb, n);
- m_adj(m, space);
- }
- }
- }
- on1: mbufcnt++;
- for (n = m; n->m_pkthdr.len > maxsize;) {
- nn = m_copym(n, 0, maxsize, M_WAIT);
- sbappendrecord(sb, nn);
- m_adj(n, maxsize);
- mbufcnt++;
- }
- if (eotsdu)
- n->m_flags |= M_EOR;
- sbappendrecord(sb, n);
- on2:
- IFTRACE(D_DATA)
- tptraceTPCB(TPPTmisc,
- "SEND BF: maxsize totlen mbufcnt eotsdu",
- maxsize, totlen, mbufcnt, eotsdu);
- ENDTRACE