This commit is contained in:
crusader 2017-11-30 18:35:23 +09:00
parent 526dce9cce
commit 38b336e1bb

View File

@ -1,28 +1,38 @@
package socket package socket
import ( import (
"git.loafle.net/commons_go/logging"
"git.loafle.net/commons_go/rpc/client" "git.loafle.net/commons_go/rpc/client"
"git.loafle.net/commons_go/rpc/protocol" "git.loafle.net/commons_go/rpc/protocol"
"git.loafle.net/commons_go/server" csc "git.loafle.net/commons_go/server/client"
) )
func New() client.ClientReadWriteCloseHandler { func New(socketBuilder csc.SocketBuilder) client.ClientReadWriteCloseHandler {
return &ClientReadWriteCloseHandlers{} return &ClientReadWriteCloseHandlers{
SocketBuilder: socketBuilder,
}
} }
type ClientReadWriteCloseHandlers struct { type ClientReadWriteCloseHandlers struct {
client.ClientReadWriteCloseHandlers client.ClientReadWriteCloseHandlers
SocketBuilder csc.SocketBuilder
}
func (crwch *ClientReadWriteCloseHandlers) Connect(clientCTX client.ClientContext) (interface{}, error) {
return csc.NewSocket(crwch.SocketBuilder, clientCTX)
} }
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.(server.Socket) soc := conn.(csc.Socket)
resCodec, err := codec.NewResponse(soc) resCodec, err := codec.NewResponse(soc)
return resCodec, err return resCodec, err
} }
func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params interface{}, id interface{}) error { func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params interface{}, id interface{}) error {
soc := conn.(server.Socket) soc := conn.(csc.Socket)
if wErr := codec.WriteRequest(soc, method, params, id); nil != wErr { if wErr := codec.WriteRequest(soc, method, params, id); nil != wErr {
return wErr return wErr
@ -32,10 +42,14 @@ func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientC
} }
func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) { func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) {
soc := conn.(server.Socket) soc := conn.(csc.Socket)
soc.Close() soc.Close()
} }
func (crwch *ClientReadWriteCloseHandlers) Validate() { func (crwch *ClientReadWriteCloseHandlers) Validate() {
crwch.ClientReadWriteCloseHandlers.Validate() crwch.ClientReadWriteCloseHandlers.Validate()
if nil == crwch.SocketBuilder {
logging.Logger().Panic("RPC Client: SocketBuilder must be specified")
}
} }