ing
This commit is contained in:
parent
87d41a5c4f
commit
c4e482999b
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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{}) {
|
||||
|
||||
Loop:
|
||||
for {
|
||||
if err := sh.rpcServer.Handle(rwc, rwc); nil != err && sh.IsClientDisconnect(err) {
|
||||
stopChan <- struct{}{}
|
||||
break Loop
|
||||
func (sh *ServerHandlers) OnStart() {
|
||||
// no op
|
||||
}
|
||||
|
||||
select {
|
||||
case <-stopChan:
|
||||
rwc.Close()
|
||||
return
|
||||
default:
|
||||
}
|
||||
func (sh *ServerHandlers) OnStop() {
|
||||
// no op
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user