From a19d2e987ee77137487ccfec055987028097a4ce Mon Sep 17 00:00:00 2001 From: Holger Arndt Date: Mon, 26 Apr 2021 13:12:51 +0200 Subject: [PATCH] Revert "Replace deprecated getdtablesize with sysconf" This reverts commit 67edc7850c8bde9a983dd5595e9db548c7f5c55c. --- lib/ethon.rb | 1 - lib/ethon/curls/classes.rb | 2 +- lib/ethon/libc.rb | 16 +--------------- spec/ethon/libc_spec.rb | 6 +++--- 4 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/ethon.rb b/lib/ethon.rb index 06b850c..461b4c3 100644 --- a/lib/ethon.rb +++ b/lib/ethon.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true require 'logger' require 'ffi' -require 'ffi/tools/const_generator' require 'thread' begin require 'mime/types/columnar' diff --git a/lib/ethon/curls/classes.rb b/lib/ethon/curls/classes.rb index b89b7f9..d1702e1 100644 --- a/lib/ethon/curls/classes.rb +++ b/lib/ethon/curls/classes.rb @@ -33,7 +33,7 @@ class FDSet < ::FFI::Struct def clear; self[:fd_count] = 0; end else # FD Set size. - FD_SETSIZE = ::Ethon::Libc.sysconf(:open_max) + FD_SETSIZE = ::Ethon::Libc.getdtablesize layout :fds_bits, [:long, FD_SETSIZE / ::FFI::Type::LONG.size] # :nodoc: diff --git a/lib/ethon/libc.rb b/lib/ethon/libc.rb index 3e264e9..1fddb8a 100644 --- a/lib/ethon/libc.rb +++ b/lib/ethon/libc.rb @@ -14,21 +14,7 @@ def self.windows? end unless windows? - fcg = FFI::ConstGenerator.new do |gen| - gen.include 'unistd.h' - %w[ - _SC_OPEN_MAX - ].each do |const| - ruby_name = const.sub(/^_SC_/, '').downcase.to_sym - gen.const(const, "%d", nil, ruby_name, &:to_i) - end - end - - CONF = enum(*fcg.constants.map{|_, const| - [const.ruby_name, const.converted_value] - }.flatten) - - attach_function :sysconf, [CONF], :long + attach_function :getdtablesize, [], :int attach_function :free, [:pointer], :void end end diff --git a/spec/ethon/libc_spec.rb b/spec/ethon/libc_spec.rb index 48882ee..a323151 100644 --- a/spec/ethon/libc_spec.rb +++ b/spec/ethon/libc_spec.rb @@ -2,13 +2,13 @@ require 'spec_helper' describe Ethon::Libc do - describe "#sysconf(:open_max)", :if => !Ethon::Curl.windows? do + describe "#getdtablesize", :if => !Ethon::Curl.windows? do it "returns an integer" do - expect(Ethon::Libc.sysconf(:open_max)).to be_a(Integer) + expect(Ethon::Libc.getdtablesize).to be_a(Integer) end it "returns bigger zero", :if => !Ethon::Curl.windows? do - expect(Ethon::Libc.sysconf(:open_max)).to_not be_zero + expect(Ethon::Libc.getdtablesize).to_not be_zero end end end