Code Monkey home page Code Monkey logo

Comments (7)

guonaihong avatar guonaihong commented on May 21, 2024 2

导出IsClose没必要。

  1. 如果要确保api准确性,需要要存活探测。
  2. 如果用lazy 的思路做,和WriteMessage探测失败没有区别。

感知失败的一般做法

  1. OnClose
  2. WriteMessage发现失败
    OnMessage为了保活链接,超时时间一般设置得比较长,所以OnClose只是发现错误的一种可能性,还一种是看下WriteMessage的返回err,由于tcp可靠但不绝对可靠,写入一定要加超时时间,哪怕在内网由于交换机的卡死,不加超时,也有可能tcp坏了,感知不到。

from gws.

lxzan avatar lxzan commented on May 21, 2024 1

调用之前不需要判断是否连接关闭, gws内部有判断. 你可以假设连接都是活跃的, onclose之后剔除断开的连接.

我看别的websocket项目都没有导出IsActive/IsClose方法, 也就设为私有方法了.

from gws.

lxzan avatar lxzan commented on May 21, 2024 1

非必要不导出, 一旦导出就不能随意修改了, 要尽量确保API向下兼容.

from gws.

lxzan avatar lxzan commented on May 21, 2024 1

是不是 只要WriteMessage失败, 不管当前状态如何,ReadLoop那都会正常结束读消息的循环, 然后OnClose回调都会执行啊?

是的

gws.Conn导出方法返回的错误都是可忽略的, 内部有错误处理, 最终回调OnClose.

IO Error => emitError => OnClose

这个过程中会自动关闭连接, 退出ReadLoop循环.

from gws.

davidxifeng avatar davidxifeng commented on May 21, 2024

ok,这样也可以. 就是在on close中处理好了,谢谢回复.

from gws.

davidxifeng avatar davidxifeng commented on May 21, 2024

学习了,谢谢大佬! 😃

from gws.

davidxifeng avatar davidxifeng commented on May 21, 2024

请教一下二位, 我粗看了一下代码,但有点不敢确定.

如果WriteMessage失败后, emitError会调用底层的net close,注释中说close会导致read write立即返回错误.

是不是 只要WriteMessage失败, 不管当前状态如何,ReadLoop那都会正常结束读消息的循环, 然后OnClose回调都会执行啊?

如果我只在OnClose中执行清理工作的话, WriteMessage时失败的错误值不用处理, 也可以保证OnClose会执行啊?

还是说我需要在发现失败后主动调一下OnClose?


谢谢回答, gws的API设计的真好, 👍 ❤️

from gws.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.