Use custom http transport settings in bitcoind rpc
This commit is contained in:
parent
1eb77fbc27
commit
a04fd8642e
@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -180,17 +181,13 @@ type BitcoinRPC struct {
|
|||||||
|
|
||||||
// NewBitcoinRPC returns new BitcoinRPC instance.
|
// NewBitcoinRPC returns new BitcoinRPC instance.
|
||||||
func NewBitcoinRPC(url string, user string, password string, timeout time.Duration) *BitcoinRPC {
|
func NewBitcoinRPC(url string, user string, password string, timeout time.Duration) *BitcoinRPC {
|
||||||
// set higher MaxIdleConnsPerHost to not to deplete pool of sockets
|
transport := &http.Transport{
|
||||||
defaultTransportPointer, ok := http.DefaultTransport.(*http.Transport)
|
Dial: (&net.Dialer{KeepAlive: 600 * time.Second}).Dial,
|
||||||
if !ok {
|
MaxIdleConns: 100,
|
||||||
glog.Fatal("http.DefaultTransport is not an *http.Transport")
|
MaxIdleConnsPerHost: 100, // necessary to not to deplete ports
|
||||||
}
|
}
|
||||||
// dereference it to get a copy of the struct that the pointer points to
|
|
||||||
defaultTransport := *defaultTransportPointer
|
|
||||||
defaultTransport.MaxIdleConns = 100
|
|
||||||
defaultTransport.MaxIdleConnsPerHost = 100
|
|
||||||
return &BitcoinRPC{
|
return &BitcoinRPC{
|
||||||
client: http.Client{Timeout: timeout, Transport: &defaultTransport},
|
client: http.Client{Timeout: timeout, Transport: transport},
|
||||||
URL: url,
|
URL: url,
|
||||||
User: user,
|
User: user,
|
||||||
Password: password,
|
Password: password,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user