From 81fe886451e384908a5426de055bb02773b6b87d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Thu, 1 Apr 2021 10:39:48 +0200 Subject: [PATCH 01/11] Add LibC.setrlimit/LibC.getrlimit to all linux/bsd platforms --- src/lib_c/aarch64-darwin/c/sys/resource.cr | 4 +++- src/lib_c/aarch64-linux-gnu/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/aarch64-linux-musl/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/i386-linux-gnu/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/i386-linux-musl/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-darwin/c/sys/resource.cr | 4 +++- src/lib_c/x86_64-dragonfly/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-freebsd/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-linux-gnu/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-linux-musl/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-netbsd/c/sys/resource.cr | 13 +++++++++++++ src/lib_c/x86_64-openbsd/c/sys/resource.cr | 13 +++++++++++++ 13 files changed, 149 insertions(+), 2 deletions(-) diff --git a/src/lib_c/aarch64-darwin/c/sys/resource.cr b/src/lib_c/aarch64-darwin/c/sys/resource.cr index daa583ac5895..0ba05f34dc2a 100644 --- a/src/lib_c/aarch64-darwin/c/sys/resource.cr +++ b/src/lib_c/aarch64-darwin/c/sys/resource.cr @@ -7,8 +7,10 @@ lib LibC end fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int - RLIMIT_STACK = 3 + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 struct RUsage ru_utime : Timeval diff --git a/src/lib_c/aarch64-linux-gnu/c/sys/resource.cr b/src/lib_c/aarch64-linux-gnu/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/aarch64-linux-gnu/c/sys/resource.cr +++ b/src/lib_c/aarch64-linux-gnu/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/aarch64-linux-musl/c/sys/resource.cr b/src/lib_c/aarch64-linux-musl/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/aarch64-linux-musl/c/sys/resource.cr +++ b/src/lib_c/aarch64-linux-musl/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr b/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr +++ b/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/i386-linux-gnu/c/sys/resource.cr b/src/lib_c/i386-linux-gnu/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/i386-linux-gnu/c/sys/resource.cr +++ b/src/lib_c/i386-linux-gnu/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/i386-linux-musl/c/sys/resource.cr b/src/lib_c/i386-linux-musl/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/i386-linux-musl/c/sys/resource.cr +++ b/src/lib_c/i386-linux-musl/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-darwin/c/sys/resource.cr b/src/lib_c/x86_64-darwin/c/sys/resource.cr index daa583ac5895..0ba05f34dc2a 100644 --- a/src/lib_c/x86_64-darwin/c/sys/resource.cr +++ b/src/lib_c/x86_64-darwin/c/sys/resource.cr @@ -7,8 +7,10 @@ lib LibC end fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int - RLIMIT_STACK = 3 + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 struct RUsage ru_utime : Timeval diff --git a/src/lib_c/x86_64-dragonfly/c/sys/resource.cr b/src/lib_c/x86_64-dragonfly/c/sys/resource.cr index d52182f69bce..1f652fd9164d 100644 --- a/src/lib_c/x86_64-dragonfly/c/sys/resource.cr +++ b/src/lib_c/x86_64-dragonfly/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 8 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-freebsd/c/sys/resource.cr b/src/lib_c/x86_64-freebsd/c/sys/resource.cr index 7f550c37a622..d87fa0a4ef69 100644 --- a/src/lib_c/x86_64-freebsd/c/sys/resource.cr +++ b/src/lib_c/x86_64-freebsd/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 8 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-linux-gnu/c/sys/resource.cr b/src/lib_c/x86_64-linux-gnu/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/x86_64-linux-gnu/c/sys/resource.cr +++ b/src/lib_c/x86_64-linux-gnu/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-linux-musl/c/sys/resource.cr b/src/lib_c/x86_64-linux-musl/c/sys/resource.cr index 7f550c37a622..0ba05f34dc2a 100644 --- a/src/lib_c/x86_64-linux-musl/c/sys/resource.cr +++ b/src/lib_c/x86_64-linux-musl/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 7 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-netbsd/c/sys/resource.cr b/src/lib_c/x86_64-netbsd/c/sys/resource.cr index d52182f69bce..1f652fd9164d 100644 --- a/src/lib_c/x86_64-netbsd/c/sys/resource.cr +++ b/src/lib_c/x86_64-netbsd/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 8 + struct RUsage ru_utime : Timeval ru_stime : Timeval diff --git a/src/lib_c/x86_64-openbsd/c/sys/resource.cr b/src/lib_c/x86_64-openbsd/c/sys/resource.cr index 7f550c37a622..d87fa0a4ef69 100644 --- a/src/lib_c/x86_64-openbsd/c/sys/resource.cr +++ b/src/lib_c/x86_64-openbsd/c/sys/resource.cr @@ -1,4 +1,17 @@ lib LibC + alias RlimT = ULongLong + + struct Rlimit + rlim_cur : RlimT + rlim_max : RlimT + end + + fun getrlimit(Int, Rlimit*) : Int + fun setrlimit(Int, Rlimit*) : Int + + RLIMIT_STACK = 3 + RLIMIT_NOFILE = 8 + struct RUsage ru_utime : Timeval ru_stime : Timeval From 5dd7c6dc363432888f42ac7bf53ea0838bd816ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sat, 5 Jun 2021 23:59:45 +0200 Subject: [PATCH 02/11] System.file_descriptor_limit --- src/crystal/system.cr | 1 + .../system/unix/file_descriptor_limit.cr | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/crystal/system/unix/file_descriptor_limit.cr diff --git a/src/crystal/system.cr b/src/crystal/system.cr index 88827a3f6552..ca3b178765b5 100644 --- a/src/crystal/system.cr +++ b/src/crystal/system.cr @@ -10,6 +10,7 @@ end {% if flag?(:unix) %} require "./system/unix/hostname" + require "./system/unix/file_descriptor_limit" {% if flag?(:bsd) %} require "./system/unix/sysctl_cpucount" diff --git a/src/crystal/system/unix/file_descriptor_limit.cr b/src/crystal/system/unix/file_descriptor_limit.cr new file mode 100644 index 000000000000..ca02f7516b80 --- /dev/null +++ b/src/crystal/system/unix/file_descriptor_limit.cr @@ -0,0 +1,18 @@ +module Crystal::System + def self.file_descriptor_limit + rlimit = uninitialized LibC::Rlimit + if LibC.getrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 + raise Error.from_errno("getrlimit") + end + { rlimit.rlim_cur, rlimit.rlim_max } + end + + def self.file_descriptor_limit=(limit) : Nil + rlimit = LibC::Rlimit.new + rlimit.rlim_cur = limit + rlimit.rlim_max = limit + if LibC.setrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 + raise Error.from_errno("setrlimit") + end + end +end From 5960ccb093839421a4c72bf01c246d096828d904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:07:09 +0200 Subject: [PATCH 03/11] Spec for System.file_descriptor_limit --- spec/std/system_spec.cr | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/std/system_spec.cr b/spec/std/system_spec.cr index f0969bb60944..8f3aad14d1d1 100644 --- a/spec/std/system_spec.cr +++ b/spec/std/system_spec.cr @@ -23,4 +23,25 @@ describe System do cpu_count.should eq(shell_cpus) end end + + describe "file_descriptor_limit" do + it "returns the current file descriptor limit" do + soft_fd_limit = `ulimit -Sn`.strip + $?.success?.should be_true + hard_fd_limit = `ulimit -Hn`.strip + $?.success?.should be_true + + hard_limit, soft_limit = System.file_descriptor_limit + hard_limit.should eq hard_fd_limit + soft_limit.should eq soft_fd_limit + end + + it "can set the limit" do + System.file_descriptor_limit = 512 + + soft_fd_limit = `ulimit -Sn`.strip + $?.success?.should be_true + soft_fd_limit.should eq 512 + end + end end From afb1bfd65aef6b5e8f7725cfad9ed3349ec71ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:08:37 +0200 Subject: [PATCH 04/11] format change --- src/crystal/system/unix/file_descriptor_limit.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crystal/system/unix/file_descriptor_limit.cr b/src/crystal/system/unix/file_descriptor_limit.cr index ca02f7516b80..3293e0998dc5 100644 --- a/src/crystal/system/unix/file_descriptor_limit.cr +++ b/src/crystal/system/unix/file_descriptor_limit.cr @@ -4,7 +4,7 @@ module Crystal::System if LibC.getrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 raise Error.from_errno("getrlimit") end - { rlimit.rlim_cur, rlimit.rlim_max } + {rlimit.rlim_cur, rlimit.rlim_max} end def self.file_descriptor_limit=(limit) : Nil From 6ba38c919d7f04ae321e44eb01f493d2ca6dc5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:18:05 +0200 Subject: [PATCH 05/11] Better specs --- spec/std/system_spec.cr | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/std/system_spec.cr b/spec/std/system_spec.cr index 8f3aad14d1d1..0cb69a9debb8 100644 --- a/spec/std/system_spec.cr +++ b/spec/std/system_spec.cr @@ -26,14 +26,14 @@ describe System do describe "file_descriptor_limit" do it "returns the current file descriptor limit" do - soft_fd_limit = `ulimit -Sn`.strip - $?.success?.should be_true hard_fd_limit = `ulimit -Hn`.strip $?.success?.should be_true + soft_fd_limit = `ulimit -Sn`.strip + $?.success?.should be_true - hard_limit, soft_limit = System.file_descriptor_limit - hard_limit.should eq hard_fd_limit - soft_limit.should eq soft_fd_limit + soft_limit, hard_limit = System.file_descriptor_limit + hard_limit.to_s.should eq hard_fd_limit + soft_limit.to_s.should eq soft_fd_limit end it "can set the limit" do @@ -41,7 +41,7 @@ describe System do soft_fd_limit = `ulimit -Sn`.strip $?.success?.should be_true - soft_fd_limit.should eq 512 + soft_fd_limit.should eq "512" end end end From 03dc3e5ab2ebd58185804eaf9bd57dcd3212518c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:18:14 +0200 Subject: [PATCH 06/11] raise RuntimError on errno --- src/crystal/system/unix/file_descriptor_limit.cr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crystal/system/unix/file_descriptor_limit.cr b/src/crystal/system/unix/file_descriptor_limit.cr index 3293e0998dc5..a0a491a13911 100644 --- a/src/crystal/system/unix/file_descriptor_limit.cr +++ b/src/crystal/system/unix/file_descriptor_limit.cr @@ -2,7 +2,7 @@ module Crystal::System def self.file_descriptor_limit rlimit = uninitialized LibC::Rlimit if LibC.getrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 - raise Error.from_errno("getrlimit") + raise RuntimeError.from_errno("Could not get rlimit") end {rlimit.rlim_cur, rlimit.rlim_max} end @@ -12,7 +12,7 @@ module Crystal::System rlimit.rlim_cur = limit rlimit.rlim_max = limit if LibC.setrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 - raise Error.from_errno("setrlimit") + raise RuntimeError.from_errno("Could not set rlimit") end end end From c4da1b54021a5ccad04f9c57139068f402472b85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:20:52 +0200 Subject: [PATCH 07/11] Add file_descriptor_limit to System --- src/system.cr | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/system.cr b/src/system.cr index 6746651caeb0..b056d557d72a 100644 --- a/src/system.cr +++ b/src/system.cr @@ -22,4 +22,22 @@ module System def self.cpu_count Crystal::System.cpu_count end + + # Returns the soft and hard file descriptor limits for the current process + # + # ``` + # System.file_descriptor_limit # => { 1024, 524288 } + # ``` + def self.file_descriptor_limit + Crystal::System.file_descriptor_limit + end + + # Sets the soft file descriptor limits for the current process + # + # ``` + # System.file_descriptor_limit = 4096 + # ``` + def self.file_descriptor_limit=(limit) + Crystal::System.file_descriptor_limit = limit + end end From fa4060587a870d65e861cd87ca695fd5bdc1996d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 00:48:52 +0200 Subject: [PATCH 08/11] Rlim is only a ULong in 32 bit linux --- src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr | 2 +- src/lib_c/i386-linux-gnu/c/sys/resource.cr | 2 +- src/lib_c/i386-linux-musl/c/sys/resource.cr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr b/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr index 0ba05f34dc2a..4e1dbf18ff27 100644 --- a/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr +++ b/src/lib_c/arm-linux-gnueabihf/c/sys/resource.cr @@ -1,5 +1,5 @@ lib LibC - alias RlimT = ULongLong + alias RlimT = ULong struct Rlimit rlim_cur : RlimT diff --git a/src/lib_c/i386-linux-gnu/c/sys/resource.cr b/src/lib_c/i386-linux-gnu/c/sys/resource.cr index 0ba05f34dc2a..4e1dbf18ff27 100644 --- a/src/lib_c/i386-linux-gnu/c/sys/resource.cr +++ b/src/lib_c/i386-linux-gnu/c/sys/resource.cr @@ -1,5 +1,5 @@ lib LibC - alias RlimT = ULongLong + alias RlimT = ULong struct Rlimit rlim_cur : RlimT diff --git a/src/lib_c/i386-linux-musl/c/sys/resource.cr b/src/lib_c/i386-linux-musl/c/sys/resource.cr index 0ba05f34dc2a..4e1dbf18ff27 100644 --- a/src/lib_c/i386-linux-musl/c/sys/resource.cr +++ b/src/lib_c/i386-linux-musl/c/sys/resource.cr @@ -1,5 +1,5 @@ lib LibC - alias RlimT = ULongLong + alias RlimT = ULong struct Rlimit rlim_cur : RlimT From bc0f1ff254f26a44f70765b0072cef524301a12a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 01:44:48 +0200 Subject: [PATCH 09/11] Type restriction --- src/system.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system.cr b/src/system.cr index b056d557d72a..ce0d4a32fa7a 100644 --- a/src/system.cr +++ b/src/system.cr @@ -37,7 +37,7 @@ module System # ``` # System.file_descriptor_limit = 4096 # ``` - def self.file_descriptor_limit=(limit) + def self.file_descriptor_limit=(limit : UInt32) Crystal::System.file_descriptor_limit = limit end end From e7d19bf180994b6d9b89316289da7b9b1b3dd084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 22:10:04 +0200 Subject: [PATCH 10/11] file descriptor limit not implemement on win32 --- spec/std/system_spec.cr | 2 +- src/crystal/system/win32/file_descriptor_limit.cr | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 src/crystal/system/win32/file_descriptor_limit.cr diff --git a/spec/std/system_spec.cr b/spec/std/system_spec.cr index 0cb69a9debb8..a2672c3508ab 100644 --- a/spec/std/system_spec.cr +++ b/spec/std/system_spec.cr @@ -24,7 +24,7 @@ describe System do end end - describe "file_descriptor_limit" do + pending_win32 describe: "file_descriptor_limit" do it "returns the current file descriptor limit" do hard_fd_limit = `ulimit -Hn`.strip $?.success?.should be_true diff --git a/src/crystal/system/win32/file_descriptor_limit.cr b/src/crystal/system/win32/file_descriptor_limit.cr new file mode 100644 index 000000000000..8a979e9d7535 --- /dev/null +++ b/src/crystal/system/win32/file_descriptor_limit.cr @@ -0,0 +1,9 @@ +module Crystal::System + def self.file_descriptor_limit + raise NotImplementedError.new + end + + def self.file_descriptor_limit=(limit : UInt32) : Nil + raise NotImplementedError.new + end +end From a4ea3534eabda4c4b5bc98fc6816c77234a6d661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20H=C3=B6rberg?= Date: Sun, 6 Jun 2021 22:15:25 +0200 Subject: [PATCH 11/11] Types for file desc limit --- src/crystal/system/unix/file_descriptor_limit.cr | 6 +++--- src/crystal/system/win32/file_descriptor_limit.cr | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/crystal/system/unix/file_descriptor_limit.cr b/src/crystal/system/unix/file_descriptor_limit.cr index a0a491a13911..a2c697be8316 100644 --- a/src/crystal/system/unix/file_descriptor_limit.cr +++ b/src/crystal/system/unix/file_descriptor_limit.cr @@ -1,13 +1,13 @@ module Crystal::System - def self.file_descriptor_limit + def self.file_descriptor_limit : Tuple(Int32, Int32) rlimit = uninitialized LibC::Rlimit if LibC.getrlimit(LibC::RLIMIT_NOFILE, pointerof(rlimit)) != 0 raise RuntimeError.from_errno("Could not get rlimit") end - {rlimit.rlim_cur, rlimit.rlim_max} + {rlimit.rlim_cur.to_i32, rlimit.rlim_max.to_i32} end - def self.file_descriptor_limit=(limit) : Nil + def self.file_descriptor_limit=(limit : Int) : Nil rlimit = LibC::Rlimit.new rlimit.rlim_cur = limit rlimit.rlim_max = limit diff --git a/src/crystal/system/win32/file_descriptor_limit.cr b/src/crystal/system/win32/file_descriptor_limit.cr index 8a979e9d7535..9177732d9108 100644 --- a/src/crystal/system/win32/file_descriptor_limit.cr +++ b/src/crystal/system/win32/file_descriptor_limit.cr @@ -1,9 +1,9 @@ module Crystal::System - def self.file_descriptor_limit + def self.file_descriptor_limit : Tuple(Int32, Int32) raise NotImplementedError.new end - def self.file_descriptor_limit=(limit : UInt32) : Nil + def self.file_descriptor_limit=(limit : Int) : Nil raise NotImplementedError.new end end