如果没有将POSIX的`recv`称为“足够快",会发生什么? [英] What happens if one doesn't call POSIX's `recv` "fast enough"?

查看:94
本文介绍了如果没有将POSIX的`recv`称为“足够快",会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想考虑一个可能的情况,即我的TCP/IP流套接字服务的客户端向服务发送数据的速度超过了它使用并使用它.

I want to account for a possible scenario where clients of my TCP/IP stream socket service send data to my service faster than it manages to move the data to its buffers (I am talking about application buffers, naturally) with recv and work with it.

那么,基本上,在这种情况下会发生什么?

So basically, what happens in such scenarios?

很明显,我的服务之下的某种服务是用户应用程序,必须接收传入的流并将其存储在某个位置,直到我发出"recv",对吗?肯定是操作系统.

Obviously, some sort of service beneath my service which is a user application, has to receive incoming stream and store it somewhere until I issue 'recv', right? Most certainly the operating system.

我不想重新打开旧的问题,但是我似乎无法找到这个看似显而易见的问题的答案?

I don't want to re-open old questions, but I can't seem to find an answer to this seemingly obvious one?

推荐答案

TCP提供了流控制 . TCP堆栈(在发送方和接收方)都可以为您缓冲一些数据,这通常是在OS内核中完成的.

TCP provides flow control . The TCP stack (both on the sender and receiver side) will be able to buffer some data for you, and this is usually done in the OS kernel.

当接收器缓冲区已满时,发送器将知道该信息,并停止发送更多数据,最终导致发送应用程序阻塞(否则将无法发送更多数据),直到空间再次可用为止.

When the receiver buffers fill up, the sender will know about it, and stop sending more data, eventually leading to the sending application blocking(or otherwise not being able to send more data) until space becomes available again.

简而言之,发送的每个TCP数据包(段)都包含可以缓冲的数据大小-窗口大小.这意味着另一端始终都知道可以发送多少数据而不会因为缓冲区已满而使接收方丢弃它.如果窗口大小变为0,则缓冲区已满,将不再发送任何数据(如果发送方被阻塞,则send()调用将被阻塞),这里有探测tcp窗口是否仍为0的过程,因此发送数据用完后可以再次恢复.

Shortly described, every TCP packet(segment) sent includes the size of data that can be buffered - the window size. This means the other end at all times know how much data it can send without the receiver throwing it away because the buffers are full. If the window size becomes 0, buffers are full and no more data will be sent (and in case of the sender being blocking, a send() call will block), Theres procedures for probing whether the tcp window is still 0, so sending can resume again when the data has been consumed.

还有更多详细信息,此处

这篇关于如果没有将POSIX的`recv`称为“足够快",会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆