overflow_discovery/server/server_handlers.go
crusader 9775e5ea4e ing
2017-10-31 19:27:26 +09:00

43 lines
751 B
Go

package server
import (
"io"
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/server/ipc"
rpcServer "git.loafle.net/overflow/overflow_discovery/server/rpc"
)
func NewServerHandler(addr string, registry rpc.Registry) *ServerHandlers {
sh := &ServerHandlers{}
sh.Addr = addr
sh.rpcServer = rpcServer.New(registry)
return sh
}
type ServerHandlers struct {
ipc.ServerHandlers
rpcServer rpcServer.Server
}
func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) {
Loop:
for {
if err := sh.rpcServer.Handle(rwc, rwc); nil != err && sh.IsClientDisconnect(err) {
stopChan <- struct{}{}
break Loop
}
select {
case <-stopChan:
rwc.Close()
return
default:
}
}
}