Chinaunix

标题: 如果recv返回超时?返回什么内容. [打印本页]

作者: wflyfox    时间: 2007-05-21 13:06
标题: 如果recv返回超时?返回什么内容.
recv返回超时的话,返回值是什么呢?
作者: wflyfox    时间: 2007-05-21 15:11
标题: 莫非阻塞模式的socket,没有收到数据会一直阻塞?
莫非阻塞模式的socket,没有收到数据会一直阻塞?
作者: 福瑞哈哥    时间: 2007-05-21 15:20
可惜長這麼大,也搞了不少socket編程,就是沒用過這個recv。
作者: wflyfox    时间: 2007-05-21 15:22
标题: 啊?怎么会.
楼上的开玩笑,我看到帖子的第一反应就是看看是不是recv拼写错误了.
汗.
作者: 福瑞哈哥    时间: 2007-05-21 15:26
原帖由 wflyfox 于 2007-5-21 15:22 发表
楼上的开玩笑,我看到帖子的第一反应就是看看是不是recv拼写错误了.
汗.

我是說真的。
作者: wflyfox    时间: 2007-05-21 15:32
找到答案了.
阻塞模式下可以用setsockopt设置SO_RCVTIMEO
SO_RCVTIMEO
              Sets  the  timeout  value  that specifies the maximum amount of time an input function waits until it completes. It accepts a timeval structure with the number of seconds and microseconds specifying the limit on how long to wait for an input operation to  complete. If a receive operation has blocked for this much time without receiving additional data, it shall return with apartial count or errno set to [EAGAIN] or [EWOULDBLOCK] if no data is received. The default for this option  is  zero,  which  indicates  that  a receive operation shall not time out. This option takes a timeval structure. Note that not all implementa- tions allow this option to be set.

多谢大家




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2