This commit is contained in:
crusader 2017-11-28 18:53:24 +09:00
parent ecd5ad53bf
commit 0554027333
3 changed files with 11 additions and 48 deletions

View File

@ -1,42 +0,0 @@
codec, err := sh.gwRPCSH.GetCodec(soc.Context().GetAttribute("contentType").(string))
if nil != err {
log.Printf("RPC Handle: %v", err)
doneChan <- struct{}{}
return
}
var socConn *cwf.SocketConn
ctx := context.WithValue(context.Background(), oogw.ServletSocketKey, rpcSoc)
// conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
for {
if socConn, err = rpcSoc.WaitRequest(); nil != err {
doneChan <- struct{}{}
return
}
// // "git.loafle.net/commons_go/websocket_fasthttp/websocket"
// switch socConn.MessageType {
// case websocket.TextMessage:
// case websocket.BinaryMessage:
// }
if err = gateway.Handle(ctx, sh.gwRPCSH, codec, socConn, socConn); nil != err {
if server.IsClientDisconnect(err) {
doneChan <- struct{}{}
return
}
log.Printf("RPC: %v", err)
}
if err = socConn.Close(); nil != err {
doneChan <- struct{}{}
return
}
select {
case <-stopChan:
return
default:
}
}

View File

@ -40,8 +40,6 @@ func (sh *GatewayRPCServletHandlers) Invoke(servletCTX rpc.ServletContext, reque
} }
return r, nil return r, nil
return
} }
func (sh *GatewayRPCServletHandlers) Validate() { func (sh *GatewayRPCServletHandlers) Validate() {

View File

@ -60,18 +60,25 @@ func (sh *RPCGatewayServletHandlers) OnConnect(soc cwf.Socket) {
soc.Context().SetAttribute(cRPC.ContentTypeKey, json.Name) soc.Context().SetAttribute(cRPC.ContentTypeKey, json.Name)
} }
func (sh *RPCGatewayServletHandlers) Handle(soc cwf.Socket, stopChan <-chan struct{}, doneChan chan<- struct{}) { func (sh *RPCGatewayServletHandlers) Handle(soc cwf.Socket, stopChan <-chan struct{}, doneChan chan<- error) {
var err error
rpcServlet := retainRPCServlet(sh.gwRPCSH) rpcServlet := retainRPCServlet(sh.gwRPCSH)
if err := rpcServlet.Start(soc.Context(), soc, soc); nil != err { defer func() {
doneChan <- struct{}{} releaseRPCServlet(rpcServlet)
doneChan <- err
}()
rpcDoneChan := make(chan error, 1)
if err = rpcServlet.Start(soc.Context(), soc, rpcDoneChan); nil != err {
return return
} }
select { select {
case err = <-rpcDoneChan:
case <-stopChan: case <-stopChan:
rpcServlet.Stop() rpcServlet.Stop()
return
} }
} }