去除无用的write属性

This commit is contained in:
kercylan98 2023-05-22 11:48:53 +08:00
parent 147e48a1f2
commit 0006ab049f
1 changed files with 3 additions and 15 deletions

View File

@ -18,10 +18,6 @@ func newKcpConn(server *Server, session *kcp.UDPSession) *Conn {
remoteAddr: session.RemoteAddr(), remoteAddr: session.RemoteAddr(),
ip: session.RemoteAddr().String(), ip: session.RemoteAddr().String(),
kcp: session, kcp: session,
write: func(data []byte) error {
_, err := session.Write(data)
return err
},
data: map[any]any{}, data: map[any]any{},
} }
if index := strings.LastIndex(c.ip, ":"); index != -1 { if index := strings.LastIndex(c.ip, ":"); index != -1 {
@ -38,9 +34,6 @@ func newGNetConn(server *Server, conn gnet.Conn) *Conn {
remoteAddr: conn.RemoteAddr(), remoteAddr: conn.RemoteAddr(),
ip: conn.RemoteAddr().String(), ip: conn.RemoteAddr().String(),
gn: conn, gn: conn,
write: func(data []byte) error {
return conn.AsyncWrite(data)
},
data: map[any]any{}, data: map[any]any{},
} }
if index := strings.LastIndex(c.ip, ":"); index != -1 { if index := strings.LastIndex(c.ip, ":"); index != -1 {
@ -57,9 +50,6 @@ func newWebsocketConn(server *Server, ws *websocket.Conn, ip string) *Conn {
remoteAddr: ws.RemoteAddr(), remoteAddr: ws.RemoteAddr(),
ip: ip, ip: ip,
ws: ws, ws: ws,
write: func(data []byte) error {
return ws.WriteMessage(websocket.BinaryMessage, data)
},
data: map[any]any{}, data: map[any]any{},
} }
go c.writeLoop() go c.writeLoop()
@ -74,7 +64,6 @@ type Conn struct {
ws *websocket.Conn ws *websocket.Conn
gn gnet.Conn gn gnet.Conn
kcp *kcp.UDPSession kcp *kcp.UDPSession
write func(data []byte) error
data map[any]any data map[any]any
mutex sync.Mutex mutex sync.Mutex
packetPool *synchronization.Pool[*connPacket] packetPool *synchronization.Pool[*connPacket]
@ -104,7 +93,6 @@ func (slf *Conn) Close() {
} else if slf.kcp != nil { } else if slf.kcp != nil {
_ = slf.kcp.Close() _ = slf.kcp.Close()
} }
slf.write = nil
if slf.packetPool != nil { if slf.packetPool != nil {
slf.packetPool.Close() slf.packetPool.Close()
} }