设置了SO_TIMEOUT为0,Socket读依然超时

结贴是美德 2014-03-14 03:00:38
API原文:

public void setSoTimeout(int timeout) throws SocketException

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.


我的理解是设置SO_TIMEOUT为0,那么如操作一直阻塞也没关系,不会抛出异常。
...全文
494 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
结贴是美德 2014-03-16
  • 打赏
  • 举报
回复
求助啊 怎么没人啊

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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