common/fdlimit: Rename fdlimit functions

This commit is contained in:
Ricardo Domingos 2018-01-11 20:58:50 +01:00
parent f8c02cad2f
commit eb3b13ad2a
5 changed files with 17 additions and 17 deletions

View file

@ -725,7 +725,7 @@ func makeDatabaseHandles() int {
if err := fdlimit.Raise(2048); err != nil { if err := fdlimit.Raise(2048); err != nil {
Fatalf("Failed to raise file descriptor allowance: %v", err) Fatalf("Failed to raise file descriptor allowance: %v", err)
} }
limit, err := fdlimit.Get() limit, err := fdlimit.Current()
if err != nil { if err != nil {
Fatalf("Failed to retrieve file descriptor allowance: %v", err) Fatalf("Failed to retrieve file descriptor allowance: %v", err)
} }

View file

@ -43,9 +43,9 @@ func Raise(max uint64) error {
return nil return nil
} }
// Get retrieves the number of file descriptors allowed to be opened by this // Current retrieves the number of file descriptors allowed to be opened by this
// process. // process.
func Get() (int, error) { func Current() (int, error) {
var limit syscall.Rlimit var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err return 0, err
@ -53,9 +53,9 @@ func Get() (int, error) {
return int(limit.Cur), nil return int(limit.Cur), nil
} }
// GetMax retrieves the maximum number of file descriptors this process is // Maximum retrieves the maximum number of file descriptors this process is
// allowed to request for itself. // allowed to request for itself.
func GetMax() (int, error) { func Maximum() (int, error) {
var limit syscall.Rlimit var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err return 0, err

View file

@ -25,7 +25,7 @@ import (
// per this process can be retrieved. // per this process can be retrieved.
func TestFileDescriptorLimits(t *testing.T) { func TestFileDescriptorLimits(t *testing.T) {
target := 4096 target := 4096
hardlimit, err := GetMax() hardlimit, err := Maximum()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -33,13 +33,13 @@ func TestFileDescriptorLimits(t *testing.T) {
t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target)) t.Skip(fmt.Sprintf("system limit is less than desired test target: %d < %d", hardlimit, target))
} }
if limit, err := Get(); err != nil || limit <= 0 { if limit, err := Current(); err != nil || limit <= 0 {
t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err) t.Fatalf("failed to retrieve file descriptor limit (%d): %v", limit, err)
} }
if err := Raise(uint64(target)); err != nil { if err := Raise(uint64(target)); err != nil {
t.Fatalf("failed to raise file allowance") t.Fatalf("failed to raise file allowance")
} }
if limit, err := Get(); err != nil || limit < target { if limit, err := Current(); err != nil || limit < target {
t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err) t.Fatalf("failed to retrieve raised descriptor limit (have %v, want %v): %v", limit, target, err)
} }
} }

View file

@ -39,9 +39,9 @@ func Raise(max uint64) error {
return nil return nil
} }
// Get retrieves the number of file descriptors allowed to be opened by this // Current retrieves the number of file descriptors allowed to be opened by this
// process. // process.
func Get() (int, error) { func Current() (int, error) {
var limit syscall.Rlimit var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err return 0, err
@ -49,9 +49,9 @@ func Get() (int, error) {
return int(limit.Cur), nil return int(limit.Cur), nil
} }
// GetMax retrieves the maximum number of file descriptors this process is // Maximum retrieves the maximum number of file descriptors this process is
// allowed to request for itself. // allowed to request for itself.
func GetMax() (int, error) { func Maximum() (int, error) {
var limit syscall.Rlimit var limit syscall.Rlimit
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
return 0, err return 0, err

View file

@ -33,15 +33,15 @@ func Raise(max uint64) error {
return nil return nil
} }
// Get retrieves the number of file descriptors allowed to be opened by this // Current retrieves the number of file descriptors allowed to be opened by this
// process. // process.
func Get() (int, error) { func Current() (int, error) {
// Please see Raise for the reason why we use hard coded 16K as the limit // Please see Raise for the reason why we use hard coded 16K as the limit
return 16384, nil return 16384, nil
} }
// GetMax retrieves the maximum number of file descriptors this process is // Maximum retrieves the maximum number of file descriptors this process is
// allowed to request for itself. // allowed to request for itself.
func GetMax() (int, error) { func Maximum() (int, error) {
return Get() return Current()
} }