Comments (7)
导出IsClose没必要。
- 如果要确保api准确性,需要要存活探测。
- 如果用lazy 的思路做,和WriteMessage探测失败没有区别。
感知失败的一般做法
- OnClose
- WriteMessage发现失败
OnMessage为了保活链接,超时时间一般设置得比较长,所以OnClose只是发现错误的一种可能性,还一种是看下WriteMessage的返回err,由于tcp可靠但不绝对可靠,写入一定要加超时时间,哪怕在内网由于交换机的卡死,不加超时,也有可能tcp坏了,感知不到。
from gws.
调用之前不需要判断是否连接关闭, gws内部有判断. 你可以假设连接都是活跃的, onclose之后剔除断开的连接.
我看别的websocket项目都没有导出IsActive/IsClose方法, 也就设为私有方法了.
from gws.
非必要不导出, 一旦导出就不能随意修改了, 要尽量确保API向下兼容.
from gws.
是不是 只要WriteMessage失败, 不管当前状态如何,ReadLoop那都会正常结束读消息的循环, 然后OnClose回调都会执行啊?
是的
gws.Conn导出方法返回的错误都是可忽略的, 内部有错误处理, 最终回调OnClose.
IO Error => emitError => OnClose
这个过程中会自动关闭连接, 退出ReadLoop循环.
from gws.
ok,这样也可以. 就是在on close中处理好了,谢谢回复.
from gws.
学习了,谢谢大佬! 😃
from gws.
请教一下二位, 我粗看了一下代码,但有点不敢确定.
如果WriteMessage失败后, emitError会调用底层的net close,注释中说close会导致read write立即返回错误.
是不是 只要WriteMessage失败, 不管当前状态如何,ReadLoop那都会正常结束读消息的循环, 然后OnClose回调都会执行啊?
如果我只在OnClose中执行清理工作的话, WriteMessage时失败的错误值不用处理, 也可以保证OnClose会执行啊?
还是说我需要在发现失败后主动调一下OnClose?
谢谢回答, gws的API设计的真好, 👍 ❤️
from gws.
Related Issues (20)
- 这个库我该如何拿到messageType 跟 io.Reader,类似gorilla/websocket 的 NextReader HOT 1
- Graceful termination of ReadLoop HOT 4
- projects using gws HOT 5
- 掩码都没处理对 HOT 2
- How to access request object or context HOT 9
- how to proxy via nginx, i need to use SSL HOT 2
- 这位大师,可以麻烦您把这个项目结合下fasthttp吗? HOT 2
- I'm curious about the Close() method in GWS messaging HOT 4
- 迭代计划
- gin中使用,没有Hijack()接口 HOT 2
- pass SubProtocols to Upgrade HOT 4
- Thread safety of methods WriteMessage, WritePing, WritePong, SetDeadline, WriteClose of gws.Conn HOT 6
- Can library be modified to support (as a client) compression WITH server context takeover? HOT 9
- ClientOption.TlsConfig.ServerName should not contain port number HOT 4
- Support for wasm dialing HOT 1
- contentLength and ReadMaxPayloadSize mismatch HOT 4
- Chat example - gws: websocket version not supported HOT 1
- Nil pointer dereference crash HOT 13
- Broadcaster.Broadcast() then con.WriteClose() HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gws.