Make limits into a pkg.

This is so that we can use the in other utils.

debated with davec
This commit is contained in:
Marco Peereboom 2014-01-07 15:30:25 -06:00 committed by Dave Collins
parent dd7c910e86
commit d00ccc0d3c
5 changed files with 15 additions and 7 deletions

View file

@ -5,6 +5,7 @@
package main package main
import ( import (
"github.com/conformal/btcd/limits"
"fmt" "fmt"
"net" "net"
"net/http" "net/http"
@ -128,7 +129,7 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
// Up some limits. // Up some limits.
if err := setLimits(); err != nil { if err := limits.SetLimits(); err != nil {
os.Exit(1) os.Exit(1)
} }

View file

@ -2,9 +2,9 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package limits
// Plan 9 has no process accounting. no-op here // Plan 9 has no process accounting. no-op here
func setLimits() error { func SetLimits() error {
return nil return nil
} }

View file

@ -4,7 +4,7 @@
// +build !windows,!plan9 // +build !windows,!plan9
package main package limits
import ( import (
"fmt" "fmt"
@ -16,7 +16,7 @@ const (
fileLimitMin = 1024 fileLimitMin = 1024
) )
func setLimits() error { func SetLimits() error {
var rLimit syscall.Rlimit var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by an ISC // Use of this source code is governed by an ISC
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package main package limits
func setLimits() error { func SetLimits() error {
return nil return nil
} }

View file

@ -7,6 +7,7 @@ package main
import ( import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"github.com/conformal/btcd/limits"
"github.com/conformal/btcdb" "github.com/conformal/btcdb"
_ "github.com/conformal/btcdb/ldb" _ "github.com/conformal/btcdb/ldb"
"github.com/conformal/btclog" "github.com/conformal/btclog"
@ -66,8 +67,14 @@ func main() {
return return
} }
// Use all processor cores.
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
// Up some limits.
if err := limits.SetLimits(); err != nil {
os.Exit(1)
}
backendLogger := btclog.NewDefaultBackendLogger() backendLogger := btclog.NewDefaultBackendLogger()
defer backendLogger.Flush() defer backendLogger.Flush()
log = btclog.NewSubsystemLogger(backendLogger, "") log = btclog.NewSubsystemLogger(backendLogger, "")