Skip to content

Commit 7cc2e1c

Browse files
authored
Merge pull request #247 from ruby/ssl-fileno
Add `SSLSocket#fileno` and `SSLServer#fileno`. Fixes #198.
2 parents 18ec883 + 8ea628d commit 7cc2e1c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/openssl/ssl.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ def ssl_version=(meth)
231231
end
232232

233233
module SocketForwarder
234+
# The file descriptor for the socket.
235+
def fileno
236+
to_io.fileno
237+
end
238+
234239
def addr
235240
to_io.addr
236241
end

test/test_ssl.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,20 @@ def test_freeze_calls_setup
15441544
}
15451545
end
15461546

1547+
def test_fileno
1548+
ctx = OpenSSL::SSL::SSLContext.new
1549+
sock1, sock2 = socketpair
1550+
1551+
socket = OpenSSL::SSL::SSLSocket.new(sock1)
1552+
server = OpenSSL::SSL::SSLServer.new(sock2, ctx)
1553+
1554+
assert_equal socket.fileno, socket.to_io.fileno
1555+
assert_equal server.fileno, server.to_io.fileno
1556+
ensure
1557+
sock1.close
1558+
sock2.close
1559+
end
1560+
15471561
private
15481562

15491563
def start_server_version(version, ctx_proc = nil,

0 commit comments

Comments
 (0)