package socket import ( "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/protocol" "git.loafle.net/commons_go/server" ) func New() rpc.ServletReadWriteCloseHandler { return &ServletReadWriteCloseHandlers{} } type ServletReadWriteCloseHandlers struct { rpc.ServletReadWriteCloseHandlers } func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) { var ( buf []byte rErr error ) soc := conn.(server.Socket) buf, rErr = rpc.TCPReadData(soc) if nil != rErr { return nil, rErr } return codec.NewRequestB(buf) } func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, reqCodec protocol.ServerRequestCodec, result interface{}, err error) error { var ( buf []byte wErr error ) soc := conn.(server.Socket) if nil != err { buf, wErr = reqCodec.NewErrorB(500, err) } else { buf, wErr = reqCodec.NewResponseB(result) } if nil != wErr { return wErr } wErr = rpc.TCPWriteData(soc, buf) if nil != wErr { return wErr } return nil } func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, params []interface{}) error { var ( buf []byte wErr error ) soc := conn.(server.Socket) buf, wErr = codec.NewNotificationB(method, params) if nil != wErr { return wErr } wErr = rpc.TCPWriteData(soc, buf) if nil != wErr { return wErr } return nil } func (srwch *ServletReadWriteCloseHandlers) Validate() { srwch.ServletReadWriteCloseHandlers.Validate() }