代码拉取完成,页面将自动刷新
package network
import (
"bytes"
"github.com/gorilla/websocket"
"net"
"sync"
)
type WebsocketConnSet map[*websocket.Conn]struct{}
type WSConn struct {
sync.Mutex
conn *websocket.Conn
}
func newWSConn(conn *websocket.Conn, pendingWriteNum int, maxMsgLen uint32) *WSConn {
wsConn := new(WSConn)
wsConn.conn = conn
return wsConn
}
func (wsConn *WSConn) Close() {
wsConn.Lock()
defer wsConn.Unlock()
wsConn.conn.UnderlyingConn().(*net.TCPConn).SetLinger(0)
wsConn.conn.Close()
}
func (wsConn *WSConn) LocalAddr() net.Addr {
return wsConn.conn.LocalAddr()
}
func (wsConn *WSConn) RemoteAddr() net.Addr {
return wsConn.conn.RemoteAddr()
}
func (wsConn *WSConn) Read(buffer []byte) (int, error) {
return 0, nil
}
// goroutine not safe
func (wsConn *WSConn) ReadMsg(buf *bytes.Buffer) error {
//_, b, err := wsConn.conn.ReadMessage()
messageType, r, err := wsConn.conn.NextReader()
_ = messageType
if err != nil {
return err
}
_, err = buf.ReadFrom(r)
return err
}
func (wsConn *WSConn) WriteMessage(buf []byte) error {
return wsConn.conn.WriteMessage(websocket.BinaryMessage, buf)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。