qq_慕粉1313705
2019-07-25 23:31
为什么说websocket读写消息不是线程安全,上节课讲的,因为一个http对应一个协程,这个方法绑定有一个协程的呢,为啥会不安全呢
在Godoc文档中有这一段
Concurrency
Connections support one concurrent reader and one concurrent writer.
Applications are responsible for ensuring that no more than one goroutine calls the write methods (NextWriter, SetWriteDeadline, WriteMessage, WriteJSON, EnableWriteCompression, SetCompressionLevel) concurrently and that no more than one goroutine calls the read methods (NextReader, SetReadDeadline, ReadMessage, ReadJSON, SetPongHandler, SetPingHandler) concurrently.
The Close and WriteControl methods can be called concurrently with all other
methods.
GO实现千万级WebSocket消息推送服务
21352 学习 · 56 问题
相似问题