github.com/neatio-net/neatio@v1.7.3-0.20231114194659-f4d7a2226baa/utilities/common/fdlimit/fdlimit_freebsd.go (about) 1 package fdlimit 2 3 import "syscall" 4 5 func Raise(max uint64) error { 6 7 var limit syscall.Rlimit 8 if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { 9 return err 10 } 11 12 limit.Cur = limit.Max 13 if limit.Cur > int64(max) { 14 limit.Cur = int64(max) 15 } 16 if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { 17 return err 18 } 19 return nil 20 } 21 22 func Current() (int, error) { 23 var limit syscall.Rlimit 24 if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { 25 return 0, err 26 } 27 return int(limit.Cur), nil 28 } 29 30 func Maximum() (int, error) { 31 var limit syscall.Rlimit 32 if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil { 33 return 0, err 34 } 35 return int(limit.Max), nil 36 }