ing
This commit is contained in:
parent
18eac21b52
commit
28f0cbb621
|
@ -151,7 +151,6 @@ func (s *server) handleRequest(ctx *fasthttp.RequestCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
socketCTX := socketHandler.SocketContext(s.ctx)
|
socketCTX := socketHandler.SocketContext(s.ctx)
|
||||||
logging.Logger().Debug(fmt.Sprintf("Server: Client is SocketContext."))
|
|
||||||
|
|
||||||
soc := newSocket(socketHandler, socketCTX, conn, socketID)
|
soc := newSocket(socketHandler, socketCTX, conn, socketID)
|
||||||
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
logging.Logger().Debug(fmt.Sprintf("Server: Client[%s] is connected.", soc.RemoteAddr()))
|
||||||
|
|
32
socket.go
32
socket.go
|
@ -3,7 +3,6 @@ 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"
|
||||||
|
@ -148,7 +147,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 := retainSocket()
|
s := &fasthttpWebSocket{}
|
||||||
s.Conn = conn
|
s.Conn = conn
|
||||||
s.sh = socketHandler
|
s.sh = socketHandler
|
||||||
s.id = id
|
s.id = id
|
||||||
|
@ -220,7 +219,6 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,23 +278,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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user