Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Replace deprecated getdtablesize with sysconf" #191

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/ethon.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require 'logger'
require 'ffi'
require 'ffi/tools/const_generator'
require 'thread'
begin
require 'mime/types/columnar'
Expand Down
2 changes: 1 addition & 1 deletion lib/ethon/curls/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 1 addition & 15 deletions lib/ethon/libc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/ethon/libc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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