本文原创为freas_1990,转载请标明出处:http://blog.csdn.net/freas_1990/article/details/11264237
大家都知道TCP是面向stream,而UDP是面向datagram的。
那,到底什么是stream呢?
我们来看一下以下代码
/* Now we need to check if we have a half built packet. */
if ((skb = tcp_dequeue_partial(sk)) != NULL) {
int hdrlen; /* IP header + TCP header */
hdrlen = ((unsigned long)skb->h.th - (unsigned long)skb->data)
+ sizeof(struct tcphdr); /* Add more stuff to the end of skb->len */
if (!(flags & MSG_OOB)) {
copy = min(sk->mss - (skb->len - hdrlen), len);
/* FIXME: this is really a bug. */
if (copy <= 0) {
printk("TCP: **bug**: \"copy\" <= 0!!\n");
copy = 0;
} memcpy_fromfs(skb->data + skb->len, from, copy);
skb->len += copy;
from += copy;
copied += copy;
len -= copy;
sk->write_seq += copy;
}
if ((skb->len - hdrlen) >= sk->mss ||
(flags & MSG_OOB) ||
!sk->packets_out)
tcp_send_skb(sk, skb);
else
tcp_enqueue_partial(skb, sk);
continue;
}
明白了吧?