setsockopt和select在设置超时方面的区别

zxhong 2007-01-09 08:27:37
对于read,write 操作,setsockopt和select在设置非阻塞方面都可以
它们有什么区别呢?
...全文
558 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhousqy 2007-01-10
  • 打赏
  • 举报
回复
setsockopt方法只要設置一次就行了,以後每個read操作前不需要再設置
而select的話,每個read操作都需要設置一下timeout。

We set this option once for a descriptor, specifying the timeout value, and this timeout then applies to all read operations on that descriptor. The nice thing about this method is that we set the option only once, compared to the previous two methods, which required doing something before every operation on which we wanted to place a time limit.
hu_zy 2007-01-10
  • 打赏
  • 举报
回复
setsockopt是通过信号来处理的, 超时的时候,read/write返回-1, 而且精度是毫秒级,同时只能一个句柄阻塞.
select可以设置更高的精度(微秒), 同时可以处理多个句柄的阻塞.

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧