Skip to content

Commit

Permalink
Better implementation of compatibility shims.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Dec 27, 2023
1 parent 4eb0f08 commit 24d0281
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
10 changes: 0 additions & 10 deletions lib/io/endpoint/shared_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

require 'openssl'

class OpenSSL::SSL::SSLServer
def close_on_exec=(value)
to_io.close_on_exec = value
end

def local_address
to_io.local_address
end
end

module IO::Endpoint
# Pre-connect and pre-bind sockets so that it can be used between processes.
class SharedEndpoint < Generic
Expand Down
32 changes: 32 additions & 0 deletions lib/io/endpoint/ssl_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@

require 'openssl'

module OpenSSL::SSL::SocketForwarder
unless method_defined?(:close_on_exec=)
def close_on_exec=(value)
to_io.close_on_exec = value
end
end

unless method_defined?(:close_on_exec)
def local_address
to_io.local_address
end
end

unless method_defined?(:wait)
def wait(*arguments)
to_io.wait(*arguments)
end
end

unless method_defined?(:wait_readable)
def wait_readable(*arguments)
to_io.wait_readable(*arguments)
end
end

unless method_defined?(:wait_writable)
def wait_writable(*arguments)
to_io.wait_writable(*arguments)
end
end
end

module IO::Endpoint
class SSLEndpoint < Generic
def initialize(endpoint, **options)
Expand Down
2 changes: 1 addition & 1 deletion test/io/endpoint/ssl_endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def client_endpoint(address)
expect(client).to be_a(::OpenSSL::SSL::SSLSocket)

# Wait for the connection to be closed.
client.to_io.wait_readable
client.wait_readable

client.close
end
Expand Down

0 comments on commit 24d0281

Please sign in to comment.