diff options
author | Bas van Kervel <basvankervel@ziggo.nl> | 2015-04-17 01:23:57 +0800 |
---|---|---|
committer | Bas van Kervel <basvankervel@ziggo.nl> | 2015-04-17 01:23:57 +0800 |
commit | ead3dd9759c9cc8076ad716fe10cf641751b65b0 (patch) | |
tree | 53330cd1a9f247189cdfb6783cc055b8c29ce9d3 /rpc/http.go | |
parent | 57f93d25bd9a09f4a68307342ad44a5af1d5dc26 (diff) | |
download | go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar.gz go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar.bz2 go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar.lz go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar.xz go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.tar.zst go-tangerine-ead3dd9759c9cc8076ad716fe10cf641751b65b0.zip |
Stop accepted and alive connections (http keep-alive) when the rpc service is stopped
Diffstat (limited to 'rpc/http.go')
-rw-r--r-- | rpc/http.go | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/rpc/http.go b/rpc/http.go index 61f8da549..882aff7ea 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -14,7 +14,7 @@ import ( ) var rpclogger = logger.NewLogger("RPC") -var rpclistener *ControllableTCPListener +var rpclistener *StoppableTCPListener const ( jsonrpcver = "2.0" @@ -22,12 +22,14 @@ const ( ) func Start(pipe *xeth.XEth, config RpcConfig) error { - if rpclistener != nil { // listener already running - glog.Infoln("RPC listener already running") - return fmt.Errorf("RPC already running on %s", rpclistener.Addr().String()) + if rpclistener != nil { + if fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort) != rpclistener.Addr().String() { + return fmt.Errorf("RPC service already running on %s ", rpclistener.Addr().String()) + } + return nil // RPC service already running on given host/port } - l, err := NewControllableTCPListener(fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort)) + l, err := NewStoppableTCPListener(fmt.Sprintf("%s:%d", config.ListenAddress, config.ListenPort)) if err != nil { rpclogger.Errorf("Can't listen on %s:%d: %v", config.ListenAddress, config.ListenPort, err) return err @@ -41,7 +43,7 @@ func Start(pipe *xeth.XEth, config RpcConfig) error { opts.AllowedOrigins = []string{config.CorsDomain} c := cors.New(opts) - handler = c.Handler(JSONRPC(pipe)) + handler = NewStoppableHandler(c.Handler(JSONRPC(pipe)), l.stop) } else { handler = JSONRPC(pipe) } @@ -52,13 +54,11 @@ func Start(pipe *xeth.XEth, config RpcConfig) error { } func Stop() error { - if rpclistener == nil { // listener not running - glog.Infoln("RPC listener not running") - return nil + if rpclistener != nil { + rpclistener.Stop() + rpclistener = nil } - rpclistener.Stop() - rpclistener = nil return nil } |