• 8959阅读
  • 4回复

[提问]qt 网络编程read函数理解 求指导 [复制链接]

上一主题 下一主题
离线jxhxfen2008
 

只看楼主 倒序阅读 楼主  发表于: 2013-03-29
最近做tcp编程,遇到接收数据这个函数read,但对它的英文解释看不太懂,用过的朋友帮忙指导一下吧。




qint64 QIODevice::read ( char * data, qint64 maxSize )


Reads at most maxSize bytes from the device into data, and returns the number of bytes read. If an error occurs, such as when attempting to read from a device opened in WriteOnly mode, this function returns -1.
0 is returned when no more data is available for reading. However, reading past the end of the stream is considered an error, so this function returns -1 in those cases (that is, reading on a closed socket or after a process has died).


返回 0 :没有数据可读了
返回 -1:错误
However, reading past the end of the stream is considered an error???这句话不明白,和没有数据可读有什么区别,仅仅是先前接收了,后边接收完就返回-1么??


糊涂了,请各位老师们指导一下吧



离线ffii4455

只看该作者 1楼 发表于: 2013-03-29
说的很清楚啊,括号里更是解释了。
在数据流结束后继续读取的话函数会返回-1,比如在已经关闭的嵌套字上尝试读取会返回错误。
离线jxhxfen2008

只看该作者 2楼 发表于: 2013-03-29
引用第1楼ffii4455于2013-03-29 20:22发表的  :
说的很清楚啊,括号里更是解释了。
在数据流结束后继续读取的话函数会返回-1,比如在已经关闭的嵌套字上尝试读取会返回错误。

数据流结束是什么意思呢
离线ffii4455

只看该作者 3楼 发表于: 2013-03-29
回 2楼(jxhxfen2008) 的帖子
你不用纠结这里,你尝试read一个无效的嵌套字(已关闭,或者对方强行停止),就是返回-1
离线jxhxfen2008

只看该作者 4楼 发表于: 2013-03-30
Re:回 2楼(jxhxfen2008) 的帖子
引用第3楼ffii4455于2013-03-29 21:24发表的 回 2楼(jxhxfen2008) 的帖子 :
你不用纠结这里,你尝试read一个无效的嵌套字(已关闭,或者对方强行停止),就是返回-1

恩,谢谢你啦
快速回复
限100 字节
 
上一个 下一个