From 6ac6a2c21bc1d3c9f6810cada538be93617691fc Mon Sep 17 00:00:00 2001 From: crusader Date: Wed, 29 Nov 2017 19:07:49 +0900 Subject: [PATCH] ing --- client/client.go | 19 +++++--------- client/client_handlers.go | 26 +++++++++++++++++++ .../rpc/gateway_rpc_servlet_handlers.go | 14 ---------- .../rpc/rpc_gateway_servlet_handlers.go | 10 ++++--- 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/client/client.go b/client/client.go index cdbea3f..6751b83 100644 --- a/client/client.go +++ b/client/client.go @@ -3,20 +3,13 @@ package client import ( "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/client" - "git.loafle.net/commons_go/rpc/protocol" ) -func NewClientHandler(addr string, codec protocol.ClientCodec, notifyRegistry rpc.Registry) ClientHandler { - ch := &ClientHandlers{} - ch.addr = addr - ch.RPCRegistry = notifyRegistry - ch.Codec = codec +func New(addr string, registry rpc.Registry) client.Client { - return ch -} - -type ClientHandlers struct { - client.ClientHandlers - - addr string + ch := NewClientHandler(addr, registry) + + c := client.New(ch) + + return c } diff --git a/client/client_handlers.go b/client/client_handlers.go index b1a4ed5..0e242ed 100644 --- a/client/client_handlers.go +++ b/client/client_handlers.go @@ -1,2 +1,28 @@ package client +import ( + "net" + + "git.loafle.net/commons_go/rpc" + "git.loafle.net/commons_go/rpc/client" + "git.loafle.net/commons_go/rpc/protocol/json" +) + +func NewClientHandler(addr string, registry rpc.Registry) ClientHandler { + ch := &ClientHandlers{} + ch.addr = addr + ch.RPCRegistry = registry + ch.Codec = json.NewClientCodec() + + return ch +} + +type ClientHandlers struct { + client.ClientHandlers + + addr string +} + +func (ch *ClientHandlers) Connect() (net.Conn, error) { + return net.Dial("unix", ch.addr) +} diff --git a/internal/server/rpc/gateway_rpc_servlet_handlers.go b/internal/server/rpc/gateway_rpc_servlet_handlers.go index d628d45..38cda9a 100644 --- a/internal/server/rpc/gateway_rpc_servlet_handlers.go +++ b/internal/server/rpc/gateway_rpc_servlet_handlers.go @@ -5,7 +5,6 @@ import ( "git.loafle.net/commons_go/logging" "git.loafle.net/commons_go/rpc" - crcwf "git.loafle.net/commons_go/rpc/connection/websocket/fasthttp" "git.loafle.net/commons_go/rpc/gateway" "git.loafle.net/commons_go/rpc/protocol" "git.loafle.net/commons_go/rpc/protocol/json" @@ -19,19 +18,6 @@ func newGatewayRPCServletHandler() GatewayRPCServletHandler { type GatewayRPCServletHandlers struct { gateway.ServletHandlers - rpcIO crcwf.ServletHandlers -} - -func (sh *GatewayRPCServletHandlers) ReadRequest(servletCTX rpc.ServletContext, codec protocol.ServerCodec, conn interface{}) (protocol.ServerRequestCodec, error) { - return sh.rpcIO.ReadRequest(servletCTX, codec, conn) -} - -func (sh *GatewayRPCServletHandlers) WriteResponse(servletCTX rpc.ServletContext, conn interface{}, requestCodec protocol.ServerRequestCodec, result interface{}, err error) error { - return sh.rpcIO.WriteResponse(servletCTX, conn, requestCodec, result, err) -} - -func (sh *GatewayRPCServletHandlers) WriteNotification(servletCTX rpc.ServletContext, conn interface{}, codec protocol.ServerCodec, method string, args []interface{}) error { - return sh.rpcIO.WriteNotification(servletCTX, conn, codec, method, args) } func (sh *GatewayRPCServletHandlers) Invoke(servletCTX rpc.ServletContext, requestCodec protocol.RegistryCodec) (result interface{}, err error) { diff --git a/internal/server/rpc/rpc_gateway_servlet_handlers.go b/internal/server/rpc/rpc_gateway_servlet_handlers.go index ccc813d..c1827c7 100644 --- a/internal/server/rpc/rpc_gateway_servlet_handlers.go +++ b/internal/server/rpc/rpc_gateway_servlet_handlers.go @@ -7,6 +7,7 @@ import ( cRPC "git.loafle.net/commons_go/rpc" "git.loafle.net/commons_go/rpc/protocol/json" + crsrwf "git.loafle.net/commons_go/rpc/server/rwc/websocket/fasthttp" cwf "git.loafle.net/commons_go/websocket_fasthttp" oogw "git.loafle.net/overflow/overflow_gateway_websocket" "git.loafle.net/overflow/overflow_gateway_websocket/rpc" @@ -15,9 +16,11 @@ import ( func NewRPCGatewayServletHandler(gwRPCHandler rpc.GatewayRPCHandler) RPCGatewayServletHandler { gwRPCSH := newGatewayRPCServletHandler() + rpcRWCSH := crsrwf.New() sh := &RPCGatewayServletHandlers{ gwRPCSH: gwRPCSH, + rpcRWCSH: rpcRWCSH, gwRPCHandler: gwRPCHandler, } @@ -28,6 +31,7 @@ type RPCGatewayServletHandlers struct { servlet.ServletHandlers gwRPCSH GatewayRPCServletHandler + rpcRWCSH cRPC.ServletReadWriteCloseHandler gwRPCHandler rpc.GatewayRPCHandler } @@ -64,7 +68,7 @@ func (sh *RPCGatewayServletHandlers) OnConnect(soc cwf.Socket) { func (sh *RPCGatewayServletHandlers) Handle(soc cwf.Socket, stopChan <-chan struct{}, doneChan chan<- error) { var err error - rpcServlet := retainRPCServlet(sh.gwRPCSH) + rpcServlet := retainRPCServlet(sh.gwRPCSH, sh.rpcRWCSH) defer func() { releaseRPCServlet(rpcServlet) @@ -106,10 +110,10 @@ func (sh *RPCGatewayServletHandlers) Validate() { var rpcServletPool sync.Pool -func retainRPCServlet(sh GatewayRPCServletHandler) cRPC.Servlet { +func retainRPCServlet(sh GatewayRPCServletHandler, rpcRWCSH cRPC.ServletReadWriteCloseHandler) cRPC.Servlet { v := rpcServletPool.Get() if v == nil { - return cRPC.NewServlet(sh) + return cRPC.NewServlet(sh, rpcRWCSH) } return v.(cRPC.Servlet) }