Skip to content

Commit

Permalink
making module compatible with all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Dec 2, 2020
1 parent 5240e79 commit b719de0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
4 changes: 1 addition & 3 deletions autofdmax/init_osx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

package autofdmax

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

func init() {
fdmax.Set(fdmax.OSXMax)
Expand Down
2 changes: 1 addition & 1 deletion autofdmax/init_windows.go → autofdmax/init_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build windows
// +build windows freebsd dragonfly plan9

package autofdmax

Expand Down
2 changes: 1 addition & 1 deletion autofdmax/init_linux.go → autofdmax/init_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux
// +build linux openbsd netbsd

package autofdmax

Expand Down
15 changes: 9 additions & 6 deletions fdmax.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// +build !windows

package fdmax

import (
"runtime"
"syscall"

"golang.org/x/sys/unix"
)

const (
Expand All @@ -16,17 +19,17 @@ type Limits struct {
}

func Get() (*Limits, error) {
var rLimit syscall.Rlimit
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
var rLimit unix.Rlimit
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit)
if err != nil {
return nil, err
}

return &Limits{Current: rLimit.Cur, Max: rLimit.Max}, nil
return &Limits{Current: uint64(rLimit.Cur), Max: uint64(rLimit.Max)}, nil
}

func Set(maxLimit uint64) error {
var rLimit syscall.Rlimit
var rLimit unix.Rlimit
rLimit.Max = maxLimit

rLimit.Cur = maxLimit
Expand All @@ -35,5 +38,5 @@ func Set(maxLimit uint64) error {
rLimit.Cur = OSXMax
}

return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
return unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit)
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/projectdiscovery/fdmax

go 1.14

require golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3 h1:kzM6+9dur93BcC2kVlYl34cHU+TYZLanmpSJHVMmL64=
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

0 comments on commit b719de0

Please sign in to comment.