mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-09 02:28:16 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9945c29a5c | ||
|
|
173d84f7e6 |
@@ -21,7 +21,7 @@ type WSServer struct {
|
||||
NewAgent func(*WSConn) Agent
|
||||
ln net.Listener
|
||||
handler *WSHandler
|
||||
messageType int
|
||||
messageType int
|
||||
}
|
||||
|
||||
type WSHandler struct {
|
||||
@@ -33,10 +33,10 @@ type WSHandler struct {
|
||||
conns WebsocketConnSet
|
||||
mutexConns sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
messageType int
|
||||
messageType int
|
||||
}
|
||||
|
||||
func (handler *WSHandler) SetMessageType(messageType int){
|
||||
func (handler *WSHandler) SetMessageType(messageType int) {
|
||||
handler.messageType = messageType
|
||||
}
|
||||
|
||||
@@ -51,7 +51,9 @@ func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
conn.SetReadLimit(int64(handler.maxMsgLen))
|
||||
handler.messageType = websocket.TextMessage
|
||||
if handler.messageType == 0 {
|
||||
handler.messageType = websocket.TextMessage
|
||||
}
|
||||
|
||||
handler.wg.Add(1)
|
||||
defer handler.wg.Done()
|
||||
@@ -71,7 +73,7 @@ func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
handler.conns[conn] = struct{}{}
|
||||
handler.mutexConns.Unlock()
|
||||
|
||||
wsConn := newWSConn(conn, handler.pendingWriteNum, handler.maxMsgLen,handler.messageType)
|
||||
wsConn := newWSConn(conn, handler.pendingWriteNum, handler.maxMsgLen, handler.messageType)
|
||||
agent := handler.newAgent(wsConn)
|
||||
agent.Run()
|
||||
|
||||
@@ -83,9 +85,9 @@ func (handler *WSHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
agent.OnClose()
|
||||
}
|
||||
|
||||
func (server *WSServer) SetMessageType(messageType int){
|
||||
func (server *WSServer) SetMessageType(messageType int) {
|
||||
server.messageType = messageType
|
||||
if server.handler!= nil {
|
||||
if server.handler != nil {
|
||||
server.handler.SetMessageType(messageType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ func NewPool(C chan interface{},New func()interface{}) *Pool{
|
||||
func NewPoolEx(C chan IPoolData,New func()IPoolData) *PoolEx{
|
||||
var pool PoolEx
|
||||
pool.C = C
|
||||
//pool.New = New
|
||||
pool.syncPool.New = func() interface{} {
|
||||
return New()
|
||||
}
|
||||
@@ -61,10 +60,18 @@ func NewPoolEx(C chan IPoolData,New func()IPoolData) *PoolEx{
|
||||
func (pool *PoolEx) Get() IPoolData{
|
||||
select {
|
||||
case d := <-pool.C:
|
||||
if d.IsRef() {
|
||||
panic("Pool data is in use.")
|
||||
}
|
||||
|
||||
d.Ref()
|
||||
return d
|
||||
default:
|
||||
data := pool.syncPool.Get().(IPoolData)
|
||||
if data.IsRef() {
|
||||
panic("Pool data is in use.")
|
||||
}
|
||||
|
||||
data.Ref()
|
||||
return data
|
||||
}
|
||||
@@ -76,7 +83,10 @@ func (pool *PoolEx) Put(data IPoolData){
|
||||
if data.IsRef() == false {
|
||||
panic("Repeatedly freeing memory")
|
||||
}
|
||||
//提前解引用,防止递归释放
|
||||
data.UnRef()
|
||||
data.Reset()
|
||||
//再次解引用,防止Rest时错误标记
|
||||
data.UnRef()
|
||||
select {
|
||||
case pool.C <- data:
|
||||
|
||||
Reference in New Issue
Block a user