This commit is contained in:
crusader
2017-10-27 15:01:09 +09:00
parent 97acdddce5
commit dc520fdb24
7 changed files with 73 additions and 78 deletions

View File

@@ -1,12 +0,0 @@
package rpc
import (
"log"
)
type DiscoveryService struct {
}
func (ds *DiscoveryService) Start() {
log.Print("DiscoveryService.Start")
}

View File

@@ -2,16 +2,10 @@ package server
import (
"git.loafle.net/commons_go/rpc"
"git.loafle.net/commons_go/rpc/protocol/json"
"git.loafle.net/commons_go/server"
dRPC "git.loafle.net/overflow/overflow_discovery/server/rpc"
)
func New(addr string) server.Server {
registry := rpc.NewRegistry()
registry.RegisterCodec(json.NewCodec(), "json")
registry.RegisterService(new(dRPC.DiscoveryService), "")
func New(addr string, registry rpc.Registry) server.Server {
sh := NewServerHandler(addr, registry)
sh.workersChan = make(chan struct{}, 10)

View File

@@ -26,12 +26,17 @@ type ServerHandlers struct {
func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) {
contentType := "json"
Loop:
for {
sh.registry.Invoke(contentType, rwc, rwc, nil, nil)
if err := sh.registry.Invoke(contentType, rwc, rwc, nil, nil); nil != err && sh.IsClientDisconnect(err) {
stopChan <- struct{}{}
break Loop
}
select {
case <-stopChan:
return
default:
}
}