From c4e482999b2f514a4bf7e83322bc223778c262bb Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 1 Nov 2017 15:35:03 +0900 Subject: [PATCH] ing --- server/rpc/server.go | 21 ---------- server/rpc/server_handlers.go | 47 ---------------------- server/server.go | 2 +- server/server_handlers.go | 74 +++++++++++++++++++++++++---------- 4 files changed, 55 insertions(+), 89 deletions(-) delete mode 100644 server/rpc/server.go delete mode 100644 server/rpc/server_handlers.go diff --git a/server/rpc/server.go b/server/rpc/server.go deleted file mode 100644 index 4c45124..0000000 --- a/server/rpc/server.go +++ /dev/null @@ -1,21 +0,0 @@ -package rpc - -import ( - "git.loafle.net/commons_go/rpc" - "git.loafle.net/commons_go/rpc/protocol/json" - rpcServer "git.loafle.net/commons_go/rpc/server" -) - -func New(registry rpc.Registry) Server { - - sh := NewServerHandler(registry) - sh.RegisterCodec(json.NewServerCodec(), "json") - - s := rpcServer.New(sh) - - return s -} - -type Server interface { - rpcServer.Server -} diff --git a/server/rpc/server_handlers.go b/server/rpc/server_handlers.go deleted file mode 100644 index 5911948..0000000 --- a/server/rpc/server_handlers.go +++ /dev/null @@ -1,47 +0,0 @@ -package rpc - -import ( - "io" - - "git.loafle.net/commons_go/rpc" - rpcServer "git.loafle.net/commons_go/rpc/server" -) - -func NewServerHandler(registry rpc.Registry) *ServerHandlers { - sh := &ServerHandlers{} - sh.RPCRegistry = registry - - return sh -} - -type ServerHandlers struct { - rpcServer.ServerHandlers -} - -func (sh *ServerHandlers) GetContentType(r io.Reader) string { - return "json" -} - -func (sh *ServerHandlers) OnPreRead(r io.Reader) { - // no op -} - -func (sh *ServerHandlers) OnPostRead(r io.Reader) { - // no op -} - -func (sh *ServerHandlers) OnPreWriteResult(w io.Writer, result interface{}) { - // no op -} - -func (sh *ServerHandlers) OnPostWriteResult(w io.Writer, result interface{}) { - // no op -} - -func (sh *ServerHandlers) OnPreWriteError(w io.Writer, err error) { - // no op -} - -func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) { - // no op -} diff --git a/server/server.go b/server/server.go index 860006d..09121b3 100644 --- a/server/server.go +++ b/server/server.go @@ -9,7 +9,7 @@ func New(addr string, registry rpc.Registry) server.Server { sh := NewServerHandler(addr, registry) - s := server.NewServer(sh) + s := server.New(sh) return s } diff --git a/server/server_handlers.go b/server/server_handlers.go index 0aaac69..963d71a 100644 --- a/server/server_handlers.go +++ b/server/server_handlers.go @@ -2,41 +2,75 @@ package server import ( "io" + "net" + "os" "git.loafle.net/commons_go/rpc" - "git.loafle.net/commons_go/server/ipc" - rpcServer "git.loafle.net/overflow/overflow_discovery/server/rpc" + "git.loafle.net/commons_go/rpc/protocol/json" + "git.loafle.net/commons_go/rpc/server" ) func NewServerHandler(addr string, registry rpc.Registry) *ServerHandlers { sh := &ServerHandlers{} - sh.Addr = addr - sh.rpcServer = rpcServer.New(registry) + sh.RPCRegistry = registry + sh.addr = addr + + sh.RegisterCodec(json.NewServerCodec(), "json") return sh } type ServerHandlers struct { - ipc.ServerHandlers + server.ServerHandlers - rpcServer rpcServer.Server + addr string } -func (sh *ServerHandlers) Handle(remoteAddr string, rwc io.ReadWriteCloser, stopChan chan struct{}) { +func (sh *ServerHandlers) OnStart() { + // no op +} -Loop: - for { - if err := sh.rpcServer.Handle(rwc, rwc); nil != err && sh.IsClientDisconnect(err) { - stopChan <- struct{}{} - break Loop - } +func (sh *ServerHandlers) OnStop() { + // no op +} - select { - case <-stopChan: - rwc.Close() - return - default: - } +func (sh *ServerHandlers) Listen() (net.Listener, error) { + os.Remove(sh.addr) + l, err := net.ListenUnix("unix", &net.UnixAddr{Name: sh.addr, Net: "unix"}) + if nil == err { + os.Chmod(sh.addr, 0777) } - + return l, err +} + +func (sh *ServerHandlers) OnAccept(conn net.Conn) (net.Conn, error) { + return conn, nil +} + +func (sh *ServerHandlers) GetContentType(r io.Reader) string { + return "json" +} + +func (sh *ServerHandlers) OnPreRead(r io.Reader) { + // no op +} + +func (sh *ServerHandlers) OnPostRead(r io.Reader) { + // no op +} + +func (sh *ServerHandlers) OnPreWriteResult(w io.Writer, result interface{}) { + // no op +} + +func (sh *ServerHandlers) OnPostWriteResult(w io.Writer, result interface{}) { + // no op +} + +func (sh *ServerHandlers) OnPreWriteError(w io.Writer, err error) { + // no op +} + +func (sh *ServerHandlers) OnPostWriteError(w io.Writer, err error) { + // no op }