Skip to content

Commit 5073c6b

Browse files
mtoddJohn Wedoff
authored andcommitted
Read length nonblocking
1 parent df3b4b5 commit 5073c6b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

lib/net/ber/ber_parser.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,20 @@ def read_ber_length
146146
raise Net::BER::BerError, "Invalid BER length 0xFF detected."
147147
else
148148
v = 0
149-
read(n & 0x7f).each_byte do |b|
149+
len = n & 0x7f
150+
151+
buffer =
152+
begin
153+
read_nonblock(len)
154+
rescue IO::WaitReadable
155+
if IO.select([self], nil, nil, read_ber_timeout)
156+
read_nonblock(len)
157+
else
158+
raise Net::LDAP::LdapError, "Timed out reading from the socket"
159+
end
160+
end
161+
162+
buffer.each_byte do |b|
150163
v = (v << 8) + b
151164
end
152165

0 commit comments

Comments
 (0)