Carve off the code that builds a TCP data packet into its own

function, and inline it, except when profiling... so we can
profile it.
This commit is contained in:
thorpej 2001-07-31 02:25:22 +00:00
parent 0d8e804191
commit 35df06a642
1 changed files with 63 additions and 50 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tcp_output.c,v 1.69 2001/07/31 00:57:45 thorpej Exp $ */
/* $NetBSD: tcp_output.c,v 1.70 2001/07/31 02:25:22 thorpej Exp $ */
/*
%%% portions-copyright-nrl-95
@ -316,6 +316,66 @@ tcp_segsize(struct tcpcb *tp, int *txsegsizep, int *rxsegsizep)
}
}
static
#ifndef GPROF
__inline
#endif
int
tcp_build_datapkt(struct tcpcb *tp, struct socket *so, int off,
long len, int hdrlen, struct mbuf **mp)
{
struct mbuf *m;
if (tp->t_force && len == 1)
tcpstat.tcps_sndprobe++;
else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
tcpstat.tcps_sndrexmitpack++;
tcpstat.tcps_sndrexmitbyte += len;
} else {
tcpstat.tcps_sndpack++;
tcpstat.tcps_sndbyte += len;
}
#ifdef notyet
if ((m = m_copypack(so->so_snd.sb_mb, off,
(int)len, max_linkhdr + hdrlen)) == 0)
return (ENOBUFS);
/*
* m_copypack left space for our hdr; use it.
*/
m->m_len += hdrlen;
m->m_data -= hdrlen;
#else
MGETHDR(m, M_DONTWAIT, MT_HEADER);
if (m != NULL &&
(max_linkhdr + hdrlen > MHLEN ||
max_linkhdr + hdrlen + len <= MCLBYTES)) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
m = NULL;
}
}
if (m == NULL)
return (ENOBUFS);
m->m_data += max_linkhdr;
m->m_len = hdrlen;
if (len <= M_TRAILINGSPACE(m)) {
m_copydata(so->so_snd.sb_mb, off, (int) len,
mtod(m, caddr_t) + hdrlen);
m->m_len += len;
} else {
m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
if (m->m_next == NULL) {
m_freem(m);
return (ENOBUFS);
}
}
#endif
*mp = m;
return (0);
}
/*
* Tcp output routine: figure out what should be sent and send it.
*/
@ -693,56 +753,9 @@ send:
* the template for sends on this connection.
*/
if (len) {
if (tp->t_force && len == 1)
tcpstat.tcps_sndprobe++;
else if (SEQ_LT(tp->snd_nxt, tp->snd_max)) {
tcpstat.tcps_sndrexmitpack++;
tcpstat.tcps_sndrexmitbyte += len;
} else {
tcpstat.tcps_sndpack++;
tcpstat.tcps_sndbyte += len;
}
#ifdef notyet
if ((m = m_copypack(so->so_snd.sb_mb, off,
(int)len, max_linkhdr + hdrlen)) == 0) {
error = ENOBUFS;
error = tcp_build_datapkt(tp, so, off, len, hdrlen, &m);
if (error)
goto out;
}
/*
* m_copypack left space for our hdr; use it.
*/
m->m_len += hdrlen;
m->m_data -= hdrlen;
#else
MGETHDR(m, M_DONTWAIT, MT_HEADER);
if (m != NULL &&
(max_linkhdr + hdrlen > MHLEN ||
max_linkhdr + hdrlen + len <= MCLBYTES)) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
m = NULL;
}
}
if (m == NULL) {
error = ENOBUFS;
goto out;
}
m->m_data += max_linkhdr;
m->m_len = hdrlen;
if (len <= M_TRAILINGSPACE(m)) {
m_copydata(so->so_snd.sb_mb, off, (int) len,
mtod(m, caddr_t) + hdrlen);
m->m_len += len;
} else {
m->m_next = m_copy(so->so_snd.sb_mb, off, (int) len);
if (m->m_next == NULL) {
m_freem(m);
error = ENOBUFS;
goto out;
}
}
#endif
/*
* If we're sending everything we've got, set PUSH.
* (This will keep happy those implementations which only