diff --git a/njs-ioutils/fileDescriptor_ko.go b/njs-ioutils/fileDescriptor_ko.go index 088334b..143d39c 100644 --- a/njs-ioutils/fileDescriptor_ko.go +++ b/njs-ioutils/fileDescriptor_ko.go @@ -27,8 +27,36 @@ package njs_ioutils -import "fmt" +import ( + "github.com/nabbar/golib/njs-ioutils/maxstdio" +) + +/* + * install package gcc-multilib gcc-mingw-w64 + * - i686-w64-mingw32 for 32-bit Windows; + * - x86_64-w64-mingw32 for 64-bit Windows. + * call go build with env var : + * - CC=i686-w64-mingw32-gcc for win32 + * - CC=x86_64-w64-mingw32-gcc for win64 + * build : + * all : cd /vendor/github/nabbar/golib/njs-ioutils/maxstdio && CC=x86_64-w64-mingw32 gcc -c maxstdio.c + * win64 : cd && CC=/usr/bin/x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -a -v . + * win32 : cd && CC=/usr/bin/i686-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -a -v . + */ func systemFileDescriptor(newValue int) (current int, max int, err error) { - return 0, 0, fmt.Errorf("rLimit is nor implemented in current system") + rLimit := maxstdio.GetMaxStdio() + + if rLimit < 0 { + // default windows value + rLimit = 512 + } + + if newValue > rLimit { + rLimit = int(maxstdio.SetMaxStdio(newValue)) + return SystemFileDescriptor(0) + } + + return rLimit, rLimit, nil + // return 0, 0, fmt.Errorf("rLimit is nor implemented in current system") } diff --git a/njs-ioutils/maxstdio/maxstdio.c b/njs-ioutils/maxstdio/maxstdio.c new file mode 100644 index 0000000..c723c1a --- /dev/null +++ b/njs-ioutils/maxstdio/maxstdio.c @@ -0,0 +1,10 @@ +#include "maxstdio.h" +#include + +int CGetMaxSTDIO() { + return _getmaxstdio(); +} + +int CSetMaxSTDIO(int new_max) { + return _setmaxstdio(new_max); +} diff --git a/njs-ioutils/maxstdio/maxstdio.go b/njs-ioutils/maxstdio/maxstdio.go new file mode 100644 index 0000000..bdc82bf --- /dev/null +++ b/njs-ioutils/maxstdio/maxstdio.go @@ -0,0 +1,16 @@ +// +build windows cgo + +package maxstdio + +// #cgo CFLAGS: -g -Wall +// #include +// #include "maxstdio.h" +import "C" + +func GetMaxStdio() int { + return int(C.CGetMaxSTDIO()) +} + +func SetMaxStdio(newMax int) int { + return int(C.CSetMaxSTDIO(C.int(newMax))) +} diff --git a/njs-ioutils/maxstdio/maxstdio.h b/njs-ioutils/maxstdio/maxstdio.h new file mode 100644 index 0000000..9b85e42 --- /dev/null +++ b/njs-ioutils/maxstdio/maxstdio.h @@ -0,0 +1,5 @@ +#ifndef _MAXSTDIO_H +#define _MAXSTDIO_H +int CGetMaxSTDIO(); +int CSetMaxSTDIO(int new_max); +#endif \ No newline at end of file diff --git a/njs-ioutils/maxstdio/maxstdio.o b/njs-ioutils/maxstdio/maxstdio.o new file mode 100644 index 0000000..86f1d11 Binary files /dev/null and b/njs-ioutils/maxstdio/maxstdio.o differ diff --git a/test/test-win-max-nofile/main.go b/test/test-win-max-nofile/main.go new file mode 100644 index 0000000..e3ff568 --- /dev/null +++ b/test/test-win-max-nofile/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "os" + + njs_ioutils "github.com/nabbar/golib/njs-ioutils" +) + +func main() { + println("test to print Max STDIO NOFILE capabilities !!") + c, _, e := njs_ioutils.SystemFileDescriptor(0) + println(fmt.Sprintf("Actual limit is : %v | err : %v", c, e)) + + if e != nil { + os.Exit(1) + } + + println("test to Change Max STDIO NOFILE capabilities !!") + c, _, e = njs_ioutils.SystemFileDescriptor(c + 512) + println(fmt.Sprintf("New limit is : %v | err : %v", c, e)) + + if e != nil { + os.Exit(1) + } +}