2017-11-29 09:55:24 +00:00
|
|
|
package socket
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.loafle.net/commons_go/rpc/client"
|
|
|
|
"git.loafle.net/commons_go/rpc/protocol"
|
|
|
|
"git.loafle.net/commons_go/server"
|
|
|
|
)
|
|
|
|
|
2017-11-30 04:59:46 +00:00
|
|
|
func New() client.ClientReadWriteCloseHandler {
|
|
|
|
return &ClientReadWriteCloseHandlers{}
|
2017-11-29 10:02:33 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 09:55:24 +00:00
|
|
|
type ClientReadWriteCloseHandlers struct {
|
|
|
|
client.ClientReadWriteCloseHandlers
|
|
|
|
}
|
|
|
|
|
2017-11-30 03:36:03 +00:00
|
|
|
func (crwch *ClientReadWriteCloseHandlers) ReadResponse(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}) (protocol.ClientResponseCodec, error) {
|
2017-11-29 09:55:24 +00:00
|
|
|
soc := conn.(server.Socket)
|
|
|
|
resCodec, err := codec.NewResponse(soc)
|
|
|
|
|
|
|
|
return resCodec, err
|
|
|
|
}
|
|
|
|
|
2017-11-30 03:36:03 +00:00
|
|
|
func (crwch *ClientReadWriteCloseHandlers) WriteRequest(clientCTX client.ClientContext, codec protocol.ClientCodec, conn interface{}, method string, params interface{}, id interface{}) error {
|
2017-11-29 09:55:24 +00:00
|
|
|
soc := conn.(server.Socket)
|
|
|
|
|
2017-11-30 04:59:46 +00:00
|
|
|
if wErr := codec.WriteRequest(soc, method, params, id); nil != wErr {
|
2017-11-29 09:55:24 +00:00
|
|
|
return wErr
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-30 03:36:03 +00:00
|
|
|
func (crwch *ClientReadWriteCloseHandlers) Disconnect(clientCTX client.ClientContext, conn interface{}) {
|
2017-11-29 09:55:24 +00:00
|
|
|
soc := conn.(server.Socket)
|
|
|
|
soc.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (crwch *ClientReadWriteCloseHandlers) Validate() {
|
2017-11-30 04:59:46 +00:00
|
|
|
crwch.ClientReadWriteCloseHandlers.Validate()
|
2017-11-29 09:55:24 +00:00
|
|
|
}
|