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 { type ClientReadWriteCloseHandlers struct {
ReadMtx sync.RWMutex ReadMtx sync.Mutex
WriteMtx sync.RWMutex WriteMtx sync.Mutex
} }
func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX ClientContext) (interface{}, error) { 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) { func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
soc := conn.(csc.Socket) soc := conn.(csc.Socket)
crwch.ReadMtx.RLock() crwch.ReadMtx.Lock()
resCodec, err := codec.NewResponse(soc) resCodec, err := codec.NewResponse(soc)
crwch.ReadMtx.RUnlock() crwch.ReadMtx.Unlock()
return resCodec, err return resCodec, err
} }
@ -40,9 +40,9 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
) )
soc := conn.(csc.Socket) soc := conn.(csc.Socket)
crwch.WriteMtx.RLock() crwch.WriteMtx.Lock()
wErr = codec.WriteRequest(soc, method, params, id) wErr = codec.WriteRequest(soc, method, params, id)
crwch.WriteMtx.RUnlock() crwch.WriteMtx.Unlock()
return wErr 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) { func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
soc := conn.(cwfc.Socket) soc := conn.(cwfc.Socket)
crwch.ReadMtx.RLock() crwch.ReadMtx.Lock()
_, r, err := soc.NextReader() _, r, err := soc.NextReader()
resCodec, err := codec.NewResponse(r) resCodec, err := codec.NewResponse(r)
crwch.ReadMtx.RUnlock() crwch.ReadMtx.Unlock()
return resCodec, err return resCodec, err
} }
@ -45,10 +45,10 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
) )
soc := conn.(cwfc.Socket) soc := conn.(cwfc.Socket)
crwch.WriteMtx.RLock() crwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage) wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr { if nil != wErr {
crwch.WriteMtx.RUnlock() crwch.WriteMtx.Unlock()
return wErr return wErr
} }
defer func() { defer func() {
@ -57,7 +57,7 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
wErr = codec.WriteRequest(wc, method, params, id) wErr = codec.WriteRequest(wc, method, params, id)
crwch.WriteMtx.RUnlock() crwch.WriteMtx.Unlock()
return wErr 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) { func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
soc := conn.(server.Socket) soc := conn.(server.Socket)
srwch.ReadMtx.RLock() srwch.ReadMtx.Lock()
reqCodec, err := codec.NewRequest(soc) reqCodec, err := codec.NewRequest(soc)
srwch.ReadMtx.RUnlock() srwch.ReadMtx.Unlock()
return reqCodec, err return reqCodec, err
} }
@ -30,13 +30,13 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
) )
soc := conn.(server.Socket) soc := conn.(server.Socket)
srwch.WriteMtx.RLock() srwch.WriteMtx.Lock()
if nil != err { if nil != err {
wErr = reqCodec.WriteError(soc, 500, err) wErr = reqCodec.WriteError(soc, 500, err)
} else { } else {
wErr = reqCodec.WriteResponse(soc, result) wErr = reqCodec.WriteResponse(soc, result)
} }
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr return wErr
} }
@ -47,9 +47,9 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
) )
soc := conn.(server.Socket) soc := conn.(server.Socket)
srwch.WriteMtx.RLock() srwch.WriteMtx.Lock()
wErr = codec.WriteNotification(soc, method, params) wErr = codec.WriteNotification(soc, method, params)
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr 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) { func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
soc := conn.(cwf.Socket) soc := conn.(cwf.Socket)
srwch.ReadMtx.RLock() srwch.ReadMtx.Lock()
_, r, err := soc.NextReader() _, r, err := soc.NextReader()
requestCodec, err := codec.NewRequest(r) requestCodec, err := codec.NewRequest(r)
srwch.ReadMtx.RUnlock() srwch.ReadMtx.Unlock()
return requestCodec, err return requestCodec, err
} }
@ -35,10 +35,10 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
) )
soc := conn.(cwf.Socket) soc := conn.(cwf.Socket)
srwch.WriteMtx.RLock() srwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage) wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr { if nil != wErr {
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr return wErr
} }
@ -51,7 +51,7 @@ func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.Servlet
} else { } else {
wErr = requestCodec.WriteResponse(wc, result) wErr = requestCodec.WriteResponse(wc, result)
} }
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr return wErr
} }
@ -63,10 +63,10 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
) )
soc := conn.(cwf.Socket) soc := conn.(cwf.Socket)
srwch.WriteMtx.RLock() srwch.WriteMtx.Lock()
wc, wErr = soc.NextWriter(websocket.TextMessage) wc, wErr = soc.NextWriter(websocket.TextMessage)
if nil != wErr { if nil != wErr {
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr return wErr
} }
@ -75,7 +75,7 @@ func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.Ser
}() }()
wErr = codec.WriteNotification(wc, method, params) wErr = codec.WriteNotification(wc, method, params)
srwch.WriteMtx.RUnlock() srwch.WriteMtx.Unlock()
return wErr return wErr
} }

View File

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