45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
|
package socket
|
||
|
|
||
|
import (
|
||
|
"git.loafle.net/commons_go/rpc"
|
||
|
"git.loafle.net/commons_go/rpc/protocol"
|
||
|
"git.loafle.net/commons_go/server"
|
||
|
)
|
||
|
|
||
|
type ServletReadWriteCloseHandler struct {
|
||
|
rpc.ServletReadWriteCloseHandler
|
||
|
}
|
||
|
|
||
|
func (srwch *ServletReadWriteCloseHandler) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
|
||
|
soc := conn.(server.Socket)
|
||
|
reqCodec, err := codec.NewRequest(soc)
|
||
|
|
||
|
return reqCodec, err
|
||
|
}
|
||
|
|
||
|
func (srwch *ServletReadWriteCloseHandler) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, reqCodec protocol.ServerRequestCodec, result interface{}, err error) error {
|
||
|
soc := conn.(server.Socket)
|
||
|
|
||
|
if nil != err {
|
||
|
if wErr := reqCodec.WriteError(soc, 500, err); nil != wErr {
|
||
|
return wErr
|
||
|
}
|
||
|
} else {
|
||
|
if wErr := reqCodec.WriteResponse(soc, result); nil != wErr {
|
||
|
return wErr
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (srwch *ServletReadWriteCloseHandler) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, params interface{}) error {
|
||
|
soc := conn.(server.Socket)
|
||
|
|
||
|
if wErr := codec.WriteNotification(soc, method, params); nil != wErr {
|
||
|
return wErr
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|