在C TCP套接字,可以“发送”归零? [英] With C TCP sockets, can 'send' return zero?

查看:89
本文介绍了在C TCP套接字,可以“发送”归零?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能为C 发送函数返回零使用TCP套接字时?该名男子页面只是说,它会返回发送的字节数,但我不知道这是否只是返回-1,当它不能发送任何数据。

Is it ever possible for the C send function to return zero when using TCP sockets? The man page just says that it will return the number of bytes sent, but I am not sure if it will just return -1 when it can't send any data.

推荐答案

我是pretty一定的,虽然内存是在时间的迷雾深,我已经看到它之前返回零,在这种情况海量数据的传输,其中另一端没有跟上。

I'm pretty certain, though the memory is deep in the mists of time, that I've seen it return zero before, in the situation of massive data transfers where the other end was not keeping up.

从内存,在这种情况下,远程TCP堆栈的缓冲区已经填满,堆栈已通知本端,这是推迟,直到一些空间被清理出来,当地的缓冲区已经填满为好。

From memory, in that case, the remote TCP stack buffers had filled up, the stack had notified the local end that it was to delay until some space was cleared out and the local buffers had filled up as well.

在这一点上,它不是技术上的错误(因此没有返回-1),但没有数据可通过本地堆栈被接受。

At that point, it's not technically an error (hence no -1 returned) but no data could be accepted by the local stack.

我不的完全的一定是这样的话,因为现在目前的POSIX标准似乎表明它只会在这种情况下块(或如果它被设置为非阻塞失败)。

I'm not entirely certain that's the case now since the current Posix standard seems to indicate it will simply block in that case (or fail if it's set up for non-blocking).

不过,我怀疑这是一个有争议的问题。您的的有可能性,它会返回的的比字节您请求发送,因此,你应该有code的地方来处理。

However, I suspect it's a moot point. You do have the possibility that it will return less than the bytes you requested to send and you therefore should have code in place to handle that.

和,因为这将是pretty大致相同的逻辑处理一不到你的要求是什么为处理零字节',你不妨假定它可以返回零。

And, since it will be pretty much the same logic handling 'one less than what you requested' as handling 'zero bytes', you may as well assume it can return zero.

这篇关于在C TCP套接字,可以“发送”归零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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