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.NewRequest(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.NewError(500, err) } else { buf, wErr = reqCodec.NewResponse(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.NewNotification(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() }