我相当肯定这是从等效的tcp版本移植相同的recv循环的结果.但这让我很奇怪.可以recv返回0为udp?在tcp上,信号通知另一端已经关闭了连接. udp没有连接的概念,所以它可以返回0?如果可以的话,这是什么意思?
解决方法
udp doesn’t have the concept of a connection so can it return 0? and
if it can,what is it’s meaning
Writing a datagram of length 0 is acceptable. In the case of UDP,this
results in an IP datagram containing an IP header (normally 20 bytes
for IPv4 and 40 bytes for IPv6),an 8-byte UDP header,and no data.
This also means that a return value of 0 from recvfrom is acceptable for a datagram protocol: It does not mean that the peer has closed the connection,as does a return value of 0 from read on a TCP socket. Since UDP is connectionless,there is no such thing as closing a UDP connection.
原文地址:https://www.jb51.cc/linux/401916.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。