1. 首页
  2. 主题
  3. Go问与答

go net.Conn 可以非阻塞地判断是否可读吗?

wubbalubbaaa · · 2035 次点击
比如下面的代码: ```go for { beforeRead() c.Read(buf) } ``` 这样会导致beforeRead()被调用两次, 进入第二次循环, 先调用了beforeRead之后, 才调用Read被阻塞 有什么好的办法解决这个问题吗,谢谢!
goroutine + channel 不好吗? 两个goroutine 一个从 net.Conn 中读取,并写入 channel 另一个从 channel 中取出数据。
#4
更多评论
jan-bar
想要拥有,必定付出。
我感觉你需要peek一下,我以前弄数据读的时候用peek探测能读多少数据。
#2

用户登录

没有账号?注册

今日阅读排行

    加载中

一周阅读排行

    加载中