Skip to content

Add more methods to SocketForwarder. #708

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

Merged
merged 2 commits into from
Jan 13, 2024
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
8 changes: 6 additions & 2 deletions lib/openssl/buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def read_nonblock(maxlen, buf=nil, exception: true)
#
# Unlike IO#gets the separator must be provided if a limit is provided.

def gets(eol=$/, limit=nil)
def gets(eol=$/, limit=nil, chomp: false)
idx = @rbuffer.index(eol)
until @eof
break if idx
Expand All @@ -244,7 +244,11 @@ def gets(eol=$/, limit=nil)
if size && limit && limit >= 0
size = [size, limit].min
end
consume_rbuff(size)
line = consume_rbuff(size)
if chomp && line
line.chomp!(eol)
end
line
end

##
Expand Down
28 changes: 28 additions & 0 deletions lib/openssl/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ def peeraddr
to_io.peeraddr
end

def local_address
to_io.local_address
end

def remote_address
to_io.remote_address
end

def setsockopt(level, optname, optval)
to_io.setsockopt(level, optname, optval)
end
Expand All @@ -271,6 +279,26 @@ def closed?
def do_not_reverse_lookup=(flag)
to_io.do_not_reverse_lookup = flag
end

def close_on_exec=(value)
to_io.close_on_exec = value
end

def close_on_exec?
to_io.close_on_exec?
end

def wait(*args)
to_io.wait(*args)
end

def wait_readable(*args)
to_io.wait_readable(*args)
end

def wait_writable(*args)
to_io.wait_writable(*args)
end
end

def verify_certificate_identity(cert, hostname)
Expand Down
11 changes: 11 additions & 0 deletions test/openssl/test_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def test_gets
}
end

def test_gets_chomp
ssl_pair {|s1, s2|
s1 << "line1\r\nline2\r\nline3\r\n"
s1.close

assert_equal("line1", s2.gets("\r\n", chomp: true))
assert_equal("line2\r\n", s2.gets("\r\n", chomp: false))
assert_equal("line3", s2.gets(chomp: true))
}
end

def test_gets_eof_limit
ssl_pair {|s1, s2|
s1.write("hello")
Expand Down