forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a08b04
commit 60760a3
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This file was taken from: | ||
// https://github.com/OpenBazaar/openbazaar-go/blob/master/core/ulimit_non_unix.go | ||
|
||
// +build darwin linux netbsd openbsd | ||
|
||
package ulimit | ||
|
||
const ( | ||
// DefaultFDLimit is the default recommended number of FDs to allocate. | ||
DefaultFDLimit uint64 = 1 << 15 // 32k | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// This file was taken from: | ||
// https://github.com/OpenBazaar/openbazaar-go/blob/master/core/ulimit_non_unix.go | ||
|
||
// +build !darwin | ||
// +build !linux | ||
// +build !netbsd | ||
// +build !openbsd | ||
|
||
package ulimit | ||
|
||
// Set is a no-op on non-unix systems | ||
func Set(uint64) error { return nil } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// This file was taken from: | ||
// https://github.com/OpenBazaar/openbazaar-go/blob/master/core/ulimit_non_unix.go | ||
|
||
// +build darwin linux netbsd openbsd | ||
|
||
package ulimit | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"syscall" | ||
) | ||
|
||
// Set the file descriptor limit | ||
func Set(limit uint64) error { | ||
var rLimit syscall.Rlimit | ||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) | ||
if err != nil { | ||
return fmt.Errorf("error getting rlimit: %s", err) | ||
} | ||
|
||
oldMax := rLimit.Max | ||
if rLimit.Cur < limit { | ||
if rLimit.Max < limit { | ||
rLimit.Max = limit | ||
} | ||
rLimit.Cur = limit | ||
} | ||
|
||
// If we're on darwin, work around the fact that Getrlimit reports the wrong | ||
// value. See https://github.com/golang/go/issues/30401 | ||
if runtime.GOOS == "darwin" && rLimit.Cur > 10240 { | ||
// The max file limit is 10240, even though the max returned by | ||
// Getrlimit is 1<<63-1. This is OPEN_MAX in sys/syslimits.h. | ||
rLimit.Max = 10240 | ||
rLimit.Cur = 10240 | ||
} | ||
|
||
// Try updating the limit. If it fails, try using the previous maximum | ||
// instead of our new maximum. Not all users have permissions to increase | ||
// the maximum. | ||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { | ||
rLimit.Max = oldMax | ||
rLimit.Cur = oldMax | ||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { | ||
return fmt.Errorf("error setting ulimit: %s", err) | ||
} | ||
} | ||
|
||
return nil | ||
} |