rpc/server/rwc/socket/servlet_handlers.go

49 lines
1.3 KiB
Go
Raw Normal View History

2017-11-29 09:55:24 +00:00
package socket
import (
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol"
"git.loafle.net/commons_go/server"
)
2017-11-29 10:02:33 +00:00
func New() rpc.ServletReadWriteCloseHandler {
return &ServletReadWriteCloseHandlers{}
2017-11-29 09:55:24 +00:00
}
2017-11-29 10:02:33 +00:00
type ServletReadWriteCloseHandlers struct {
rpc.ServletReadWriteCloseHandlers
}
func (srwch *ServletReadWriteCloseHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) {
2017-11-29 09:55:24 +00:00
soc := conn.(server.Socket)
reqCodec, err := codec.NewRequest(soc)
return reqCodec, err
}
2017-11-29 10:02:33 +00:00
func (srwch *ServletReadWriteCloseHandlers) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, reqCodec protocol.ServerRequestCodec, result interface{}, err error) error {
2017-11-29 09:55:24 +00:00
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
}
2017-11-29 10:02:33 +00:00
func (srwch *ServletReadWriteCloseHandlers) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, params interface{}) error {
2017-11-29 09:55:24 +00:00
soc := conn.(server.Socket)
if wErr := codec.WriteNotification(soc, method, params); nil != wErr {
return wErr
}
return nil
}