套接字编程send()返回值 [英] Socket programming send() return value

查看:112
本文介绍了套接字编程send()返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在linux或Windows socket编程中

In linux, or windows socket programming

我知道read返回一个值,该值指示 成功接收到的字节数.

I know that read returns a value which indicates the number of successfully received number of bytes.

此返回值可能小于请求的长度. (即read(sd,buf,100)如果接收缓冲区可能返回50 只有50个字节)

this return value might be less than requested length. (i.e, read(sd, buf, 100) might return 50 if the receive buffer only has 50 bytes)

有可能

send(sd, buf, 100);

返回1到99之间的值? 如果是,那是什么情况? 我想知道具体的示例情况.

returns a value between 1~99?? if it is, what is the occasion? I want to know specific example situation.

先谢谢您

推荐答案

有关正式规范,请参见man页,或者如果您正在谈论Winsock,请参见MSDN文档.

See the man pages, or the MSDN documentation if you are talking about Winsock, for the offical specification.

实践中, send()在阻塞模式下将发送所有数据,无论文档说什么,除非有错误,在这种情况下都不会发送任何信息.

In practice, send() in blocking mode sends all the data, regardless of what the documentation says, unless there was an error, in which case nothing is sent.

在非阻塞模式下,它将发送适合套接字发送缓冲区的所有内容,如果> 0,则返回该长度.如果套接字发送缓冲区已满,则返回errno = EWOULDBLOCK/EAGAIN的-1.

In non-blocking mode, it sends whatever will fit into the socket send buffer and returns that length if > 0. If the socket send buffer is full, it returns -1 with errno = EWOULDBLOCK/EAGAIN.

这篇关于套接字编程send()返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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