This commit is contained in:
crusader 2017-11-29 19:32:29 +09:00
parent 28f0cbb621
commit 27ca509636

View File

@ -3,6 +3,7 @@ package websocket_fasthttp
import ( import (
"io" "io"
"net" "net"
"sync"
"time" "time"
"git.loafle.net/commons_go/websocket_fasthttp/websocket" "git.loafle.net/commons_go/websocket_fasthttp/websocket"
@ -147,7 +148,7 @@ type Socket interface {
} }
func newSocket(socketHandler SocketHandler, socketCTX SocketContext, conn *websocket.Conn, id string) Socket { func newSocket(socketHandler SocketHandler, socketCTX SocketContext, conn *websocket.Conn, id string) Socket {
s := &fasthttpWebSocket{} s := retainSocket()
s.Conn = conn s.Conn = conn
s.sh = socketHandler s.sh = socketHandler
s.id = id s.id = id
@ -219,6 +220,7 @@ func (s *fasthttpWebSocket) WriteMessage(messageType int, data []byte) error {
func (s *fasthttpWebSocket) Close() error { func (s *fasthttpWebSocket) Close() error {
err := s.Conn.Close() err := s.Conn.Close()
releaseSocket(s)
return err return err
} }
@ -278,23 +280,23 @@ func (s *fasthttpWebSocket) Close() error {
// return sc.s.SetWriteDeadline(t) // return sc.s.SetWriteDeadline(t)
// } // }
// var socketPool sync.Pool var socketPool sync.Pool
// func retainSocket() *fasthttpWebSocket { func retainSocket() *fasthttpWebSocket {
// v := socketPool.Get() v := socketPool.Get()
// if v == nil { if v == nil {
// return &fasthttpWebSocket{} return &fasthttpWebSocket{}
// } }
// return v.(*fasthttpWebSocket) return v.(*fasthttpWebSocket)
// } }
// func releaseSocket(s *fasthttpWebSocket) { func releaseSocket(s *fasthttpWebSocket) {
// s.sh = nil s.sh = nil
// s.ctx = nil s.ctx = nil
// s.id = "" s.id = ""
// socketPool.Put(s) socketPool.Put(s)
// } }
// var socketConnPool sync.Pool // var socketConnPool sync.Pool