This commit is contained in:
crusader 2018-03-23 13:42:39 +09:00
parent b36507490a
commit a3d9c8941a
6 changed files with 27 additions and 27 deletions

View File

@ -8,8 +8,8 @@ import (
)
type ClientReadWriteCloseHandlers struct {
ReadMtx sync.RWMutex
WriteMtx sync.RWMutex
ReadMtx sync.Mutex
WriteMtx sync.Mutex
}
func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX ClientContext) (interface{}, error) {

View File

@ -27,9 +27,9 @@ func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX client.ClientContex
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
soc := conn.(csc.Socket)
crwch.ReadMtx.RLock()
crwch.ReadMtx.Lock()
resCodec, err := codec.NewResponse(soc)
crwch.ReadMtx.RUnlock()
crwch.ReadMtx.Unlock()
return resCodec, err
}
@ -40,9 +40,9 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
)
soc := conn.(csc.Socket)
crwch.WriteMtx.RLock()
crwch.WriteMtx.Lock()
wErr = codec.WriteRequest(soc, method, params, id)
crwch.WriteMtx.RUnlock()
crwch.WriteMtx.Unlock()
return wErr
}

View File

@ -30,10 +30,10 @@ func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX client.ClientContex
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
soc := conn.(cwfc.Socket)
crwch.ReadMtx.RLock()
crwch.ReadMtx.Lock()
_, r, err := soc.NextReader()
resCodec, err := codec.NewResponse(r)
crwch.ReadMtx.RUnlock()
crwch.ReadMtx.Unlock()
return resCodec, err
}
@ -45,10 +45,10 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
)
soc := conn.(cwfc.Socket)
crwch.WriteMtx.RLock()
crwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr {
crwch.WriteMtx.RUnlock()
crwch.WriteMtx.Unlock()
return wErr
}
defer func() {
@ -57,7 +57,7 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
wErr = codec.WriteRequest(wc, method, params, id)
crwch.WriteMtx.RUnlock()
crwch.WriteMtx.Unlock()
return wErr
}

View File

@ -17,9 +17,9 @@ type ServletReadWriteCloseHandlers struct {
func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
soc := conn.(server.Socket)
srwch.ReadMtx.RLock()
srwch.ReadMtx.Lock()
reqCodec, err := codec.NewRequest(soc)
srwch.ReadMtx.RUnlock()
srwch.ReadMtx.Unlock()
return reqCodec, err
}
@ -30,13 +30,13 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
)
soc := conn.(server.Socket)
srwch.WriteMtx.RLock()
srwch.WriteMtx.Lock()
if nil != err {
wErr = reqCodec.WriteError(soc, 500, err)
} else {
wErr = reqCodec.WriteResponse(soc, result)
}
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}
@ -47,9 +47,9 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
)
soc := conn.(server.Socket)
srwch.WriteMtx.RLock()
srwch.WriteMtx.Lock()
wErr = codec.WriteNotification(soc, method, params)
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}

View File

@ -20,10 +20,10 @@ type ServletReadWriteCloseHandlers struct {
func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
soc := conn.(cwf.Socket)
srwch.ReadMtx.RLock()
srwch.ReadMtx.Lock()
_, r, err := soc.NextReader()
requestCodec, err := codec.NewRequest(r)
srwch.ReadMtx.RUnlock()
srwch.ReadMtx.Unlock()
return requestCodec, err
}
@ -35,10 +35,10 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
)
soc := conn.(cwf.Socket)
srwch.WriteMtx.RLock()
srwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr {
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}
@ -51,7 +51,7 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
} else {
wErr = requestCodec.WriteResponse(wc, result)
}
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}
@ -63,10 +63,10 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
)
soc := conn.(cwf.Socket)
srwch.WriteMtx.RLock()
srwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr {
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}
@ -75,7 +75,7 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
}()
wErr = codec.WriteNotification(wc, method, params)
srwch.WriteMtx.RUnlock()
srwch.WriteMtx.Unlock()
return wErr
}

View File

@ -8,8 +8,8 @@ import (
)
type ServletReadWriteCloseHandlers struct {
ReadMtx sync.RWMutex
WriteMtx sync.RWMutex
ReadMtx sync.Mutex
WriteMtx sync.Mutex
}
func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {