This commit is contained in:
crusader 2017-11-29 19:29:58 +09:00
parent 18eac21b52
commit 28f0cbb621
2 changed files with 15 additions and 18 deletions

View File

@ -151,7 +151,6 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) {
}
socketCTX := socketHandler.SocketContext(s.ctx)
logging.Logger().Debug(fmt.Sprintf("Server: Client is SocketContext."))
soc := newSocket(socketHandler, socketCTX, conn, socketID)
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))

View File

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