overflow_discovery/server/socket_handlers.go
crusader b30f3d10ea ing
2017-12-05 14:58:32 +09:00

56 lines
1.2 KiB
Go

package server
import (
"net"
cRPC "git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/server"
"git.loafle.net/overflow/overflow_discovery/discovery"
oopc "git.loafle.net/overflow/overflow_probe_container"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
)
func newSocketHandler(rpcSH oopcs.RPCServletHandler) SocketHandler {
sh := &SocketHandlers{}
sh.SocketHandler = oopcs.NewSocketHandler(rpcSH)
return sh
}
type SocketHandlers struct {
oopcs.SocketHandler
}
func (sh *SocketHandlers) Init(serverCTX server.ServerContext) error {
if err := sh.SocketHandler.Init(serverCTX); nil != err {
return err
}
return nil
}
func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Conn) (id string) {
return "discovery"
}
func (sh *SocketHandlers) OnConnect(soc server.Socket) {
sh.SocketHandler.OnConnect(soc)
discovery.RPCServlet = soc.Context().GetAttribute(oopc.RPCServletKey).(cRPC.Servlet)
}
func (sh *SocketHandlers) OnDisconnect(soc server.Socket) {
discovery.RPCServlet = nil
sh.SocketHandler.OnDisconnect(soc)
}
func (sh *SocketHandlers) Destroy() {
sh.SocketHandler.Destroy()
}
func (sh *SocketHandlers) Validate() {
}