Up some limits on !windows.
This is needed on OSX and possibly others. ok davec
This commit is contained in:
parent
995d8da491
commit
8e7d900201
3 changed files with 66 additions and 1 deletions
8
btcd.go
8
btcd.go
|
@ -157,8 +157,14 @@ func main() {
|
|||
// Use all processor cores.
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
||||
// Up some limits.
|
||||
err := setLimits()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Work around defer not working after os.Exit()
|
||||
err := btcdMain()
|
||||
err = btcdMain()
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
|
50
limits_unix.go
Normal file
50
limits_unix.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Copyright (c) 2013 Conformal Systems LLC.
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const (
|
||||
fileLimitWant = 2048
|
||||
fileLimitMin = 1024
|
||||
)
|
||||
|
||||
func setLimits() error {
|
||||
var rLimit syscall.Rlimit
|
||||
|
||||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if rLimit.Cur > fileLimitWant {
|
||||
return nil
|
||||
}
|
||||
if rLimit.Max < fileLimitMin {
|
||||
err = fmt.Errorf("need at least %v file descriptors",
|
||||
fileLimitMin)
|
||||
return err
|
||||
}
|
||||
if rLimit.Max < fileLimitWant {
|
||||
rLimit.Cur = rLimit.Max
|
||||
} else {
|
||||
rLimit.Cur = fileLimitWant
|
||||
}
|
||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||
if err != nil {
|
||||
// try min value
|
||||
rLimit.Cur = fileLimitMin
|
||||
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
9
limits_windows.go
Normal file
9
limits_windows.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Copyright (c) 2013 Conformal Systems LLC.
|
||||
// Use of this source code is governed by an ISC
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
func setLimits() error {
|
||||
return nil
|
||||
}
|
Loading…
Reference in a new issue