Skip to content

Commit

Permalink
Merge pull request #2 from projectdiscovery/bugfix-refactor
Browse files Browse the repository at this point in the history
small refactor
  • Loading branch information
Mzack9999 authored Sep 19, 2020
2 parents 74f18a1 + 4e6caf5 commit 786081d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
1 change: 0 additions & 1 deletion autofdmax/init_all.go

This file was deleted.

2 changes: 1 addition & 1 deletion autofdmax/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

func init() {
fdmax.Set(fdmax.Max)
fdmax.Set(fdmax.UnixMax)
}
11 changes: 11 additions & 0 deletions autofdmax/init_osx.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// +build darwin

package autofdmax

import (
"github.com/projectdiscovery/fdmax"
)

func init() {
fdmax.Set(fdmax.OSXMax)
}
7 changes: 7 additions & 0 deletions autofdmax/init_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build windows

package autofdmax

func init() {
// not implemented
}
11 changes: 6 additions & 5 deletions fdmax.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
)

const (
Max uint64 = 999999
UnixMax uint64 = 999999
OSXMax uint64 = 24576
)

type Limits struct {
Expand All @@ -28,10 +29,10 @@ func Set(maxLimit uint64) error {
var rLimit syscall.Rlimit
rLimit.Max = maxLimit

if runtime.GOOS == "darwin" && rLimit.Cur > 24576 {
rLimit.Cur = 24576
} else {
rLimit.Cur = maxLimit
rLimit.Cur = maxLimit
// https://github.com/golang/go/issues/30401
if runtime.GOOS == "darwin" && rLimit.Cur > OSXMax {
rLimit.Cur = OSXMax
}

return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
Expand Down

0 comments on commit 786081d

Please sign in to comment.