package socket import ( "git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/client" "git.loafle.net/commons_go/rpc/protocol" csc "git.loafle.net/commons_go/server/client" ) func New(socketBuilder csc.SocketBuilder) client.ClientReadWriteCloseHandler { return &ClientReadWriteCloseHandlers{ SocketBuilder: socketBuilder, } } type ClientReadWriteCloseHandlers struct { 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) { var ( buf []byte rErr error ) soc := conn.(csc.Socket) buf, rErr = rpc.TCPReadData(soc) if nil != rErr { return nil, rErr } return codec.NewResponse(buf) } func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params []interface{}, id interface{}) error { var ( buf []byte wErr error ) soc := conn.(csc.Socket) buf, wErr = codec.NewRequest(method, params, id) if nil != wErr { return wErr } wErr = rpc.TCPWriteData(soc, buf) if nil != wErr { return wErr } return nil } func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) { soc := conn.(csc.Socket) soc.Close() } func (crwch *ClientReadWriteCloseHandlers) Validate() { crwch.ClientReadWriteCloseHandlers.Validate() if nil == crwch.SocketBuilder { logging.Logger().Panicf("RPC Client: SocketBuilder must be specified") } }