diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2019-03-31 15:06:25 +1300 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2019-03-31 15:06:25 +1300 |
commit | 95aa0ce9e9c1b95f8c92bb7963485ab2b0329ef0 (patch) | |
tree | 674aebccf9885879dd0b1a216bcb2e45e3a216a5 | |
parent | 18ec883d6daaedbf32c66ca4ae6e41b66d0eeca4 (diff) | |
download | ruby-openssl-95aa0ce9e9c1b95f8c92bb7963485ab2b0329ef0.tar.gz |
Add `SSLSocket#fileno` and `SSLServer#fileno`. Fixes #198.
-rw-r--r-- | lib/openssl/ssl.rb | 10 | ||||
-rw-r--r-- | test/test_ssl.rb | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb index 355eb2eb..ce826cbe 100644 --- a/lib/openssl/ssl.rb +++ b/lib/openssl/ssl.rb @@ -354,6 +354,11 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3 attr_reader :io alias :to_io :io + # The file descriptor for the socket. + def fileno + @io.fileno + end + # The SSLContext object used in this connection. attr_reader :context @@ -464,6 +469,11 @@ YoaOffgTf5qxiwkjnlVZQc3whgnEt9FpVMvQ9eknyeGB5KHfayAc3+hUAvI3/Cr3 @svr end + # The file descriptor for the server socket. + def fileno + @svr.fileno + end + # See TCPServer#listen for details. def listen(backlog=5) @svr.listen(backlog) diff --git a/test/test_ssl.rb b/test/test_ssl.rb index b8016677..02841ce0 100644 --- a/test/test_ssl.rb +++ b/test/test_ssl.rb @@ -1544,6 +1544,20 @@ end } end + def test_fileno + ctx = OpenSSL::SSL::SSLContext.new + sock1, sock2 = socketpair + + socket = OpenSSL::SSL::SSLSocket.new(sock1) + server = OpenSSL::SSL::SSLServer.new(sock2, ctx) + + assert_equal socket.fileno, socket.to_io.fileno + assert_equal server.fileno, server.to_io.fileno + ensure + sock1.close + sock2.close + end + private def start_server_version(version, ctx_proc = nil, |