JSON-RPC2 to handle multiple connections via goroutines, fixes #674

This commit is contained in:
DanB
2017-06-15 19:01:24 +02:00
parent 597558174a
commit 5573ed2da7
3 changed files with 12 additions and 7 deletions

View File

@@ -174,8 +174,8 @@ func startSmGeneric(internalSMGChan chan *sessionmanager.SMGeneric, internalRate
for method, handler := range smgBiRpc.Handlers() {
server.BiRPCRegisterName(method, handler)
}
//server.BiRPCRegister(smgBiRpc)
go server.ServeBiJSON(cfg.SmGenericConfig.ListenBijson)
server.ServeBiJSON(cfg.SmGenericConfig.ListenBijson)
exitChan <- true
}
}

View File

@@ -80,7 +80,10 @@ func TestSMGBiRPCStartEngine(t *testing.T) {
// Connect rpc client to rater
func TestSMGBiRPCApierRpcConn(t *testing.T) {
clntHandlers := map[string]interface{}{"SMGClientV1.DisconnectSession": handleDisconnectSession}
if smgBiRPC, err = utils.NewBiJSONrpcClient(smgBiRPCCfg.SmGenericConfig.ListenBijson, clntHandlers); err != nil { // Connect also simple RPC so we can check accounts and such
if _, err = utils.NewBiJSONrpcClient(smgBiRPCCfg.SmGenericConfig.ListenBijson, clntHandlers); err != nil { // First attempt is to make sure multiple clients are supported
t.Fatal(err)
}
if smgBiRPC, err = utils.NewBiJSONrpcClient(smgBiRPCCfg.SmGenericConfig.ListenBijson, clntHandlers); err != nil {
t.Fatal(err)
}
if smgRPC, err = jsonrpc.Dial("tcp", smgBiRPCCfg.RPCJSONListen); err != nil { // Connect also simple RPC so we can check accounts and such

View File

@@ -193,11 +193,13 @@ func (s *Server) ServeBiJSON(addr string) {
log.Fatal("ServeBiJSON listen error:", e)
}
Logger.Info(fmt.Sprintf("Starting CGRateS BiJSON server at <%s>", addr))
conn, err := lBiJSON.Accept()
if err != nil {
log.Fatal(err)
for {
conn, err := lBiJSON.Accept()
if err != nil {
log.Fatal(err)
}
go s.birpcSrv.ServeCodec(rpc2_jsonrpc.NewJSONCodec(conn))
}
s.birpcSrv.ServeCodec(rpc2_jsonrpc.NewJSONCodec(conn))
}
// rpcRequest represents a RPC request.