1 Star 0 Fork 0

jmesyan/impetus

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ws_conn.go 1.09 KB
一键复制 编辑 原始数据 按行查看 历史
jmesyan 提交于 2020-12-12 22:03 . init
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)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jmesyan/impetus.git
git@gitee.com:jmesyan/impetus.git
jmesyan
impetus
impetus
v1.1.1

搜索帮助