websocket讀寫消息不是線程安全問(wèn)題
為什么說(shuō)websocket讀寫消息不是線程安全,上節(jié)課講的,因?yàn)橐粋€(gè)http對(duì)應(yīng)一個(gè)協(xié)程,這個(gè)方法綁定有一個(gè)協(xié)程的呢,為啥會(huì)不安全呢
為什么說(shuō)websocket讀寫消息不是線程安全,上節(jié)課講的,因?yàn)橐粋€(gè)http對(duì)應(yīng)一個(gè)協(xié)程,這個(gè)方法綁定有一個(gè)協(xié)程的呢,為啥會(huì)不安全呢
舉報(bào)
2019-11-26
在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.