overflow_discovery/server/socket_handlers.go

56 lines
1.2 KiB
Go
Raw Normal View History

2017-11-29 05:19:36 +00:00
package server
import (
"net"
2017-11-29 05:46:47 +00:00
cRPC "git.loafle.net/commons_go/rpc"
2017-11-29 05:19:36 +00:00
"git.loafle.net/commons_go/server"
2017-11-29 05:46:47 +00:00
"git.loafle.net/overflow/overflow_discovery/discovery"
2017-12-05 05:58:32 +00:00
oopc "git.loafle.net/overflow/overflow_probe_container"
oopcs "git.loafle.net/overflow/overflow_probe_container/server"
2017-11-29 05:19:36 +00:00
)
2017-12-05 05:58:32 +00:00
func newSocketHandler(rpcSH oopcs.RPCServletHandler) SocketHandler {
sh := &SocketHandlers{}
sh.SocketHandler = oopcs.NewSocketHandler(rpcSH)
2017-11-29 05:19:36 +00:00
return sh
}
type SocketHandlers struct {
2017-12-05 05:58:32 +00:00
oopcs.SocketHandler
2017-11-29 05:19:36 +00:00
}
func (sh *SocketHandlers) Init(serverCTX server.ServerContext) error {
2017-12-05 05:58:32 +00:00
if err := sh.SocketHandler.Init(serverCTX); nil != err {
2017-11-29 05:19:36 +00:00
return err
}
return nil
}
2017-12-01 08:29:54 +00:00
func (sh *SocketHandlers) Handshake(socketCTX server.SocketContext, conn net.Conn) (id string) {
2017-12-05 06:10:16 +00:00
return "DiscoveryContainer"
2017-11-29 05:19:36 +00:00
}
func (sh *SocketHandlers) OnConnect(soc server.Socket) {
2017-12-05 05:58:32 +00:00
sh.SocketHandler.OnConnect(soc)
2017-11-29 05:46:47 +00:00
2017-12-05 05:58:32 +00:00
discovery.RPCServlet = soc.Context().GetAttribute(oopc.RPCServletKey).(cRPC.Servlet)
2017-11-29 05:19:36 +00:00
}
func (sh *SocketHandlers) OnDisconnect(soc server.Socket) {
2017-12-05 05:58:32 +00:00
discovery.RPCServlet = nil
2017-11-29 05:19:36 +00:00
2017-12-05 05:58:32 +00:00
sh.SocketHandler.OnDisconnect(soc)
2017-11-29 05:19:36 +00:00
}
func (sh *SocketHandlers) Destroy() {
2017-12-05 05:58:32 +00:00
sh.SocketHandler.Destroy()
2017-11-29 05:19:36 +00:00
}
func (sh *SocketHandlers) Validate() {
2017-12-05 06:10:16 +00:00
sh.SocketHandler.Validate()
2017-11-29 05:19:36 +00:00
}