File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,9 @@ module Net::BER::BERParser
25
25
BuiltinSyntax = Net ::BER . compile_syntax ( :universal => universal ,
26
26
:context_specific => context )
27
27
28
+ # Public: specify the BER socket read timeouts, nil by default (no timeout).
29
+ attr_accessor :read_ber_timeout
30
+
28
31
##
29
32
# This is an extract of our BER object parsing to simplify our
30
33
# understanding of how we parse basic BER object types.
@@ -182,6 +185,17 @@ def read_ber(syntax = nil)
182
185
183
186
# Internal: Returns the BER message ID or nil.
184
187
def read_ber_id
185
- getbyte
188
+ begin
189
+ read_nonblock ( 1 ) . ord
190
+ rescue IO ::WaitReadable
191
+ if IO . select ( [ self ] , nil , nil , read_ber_timeout )
192
+ read_nonblock ( 1 ) . ord
193
+ else
194
+ raise Net ::LDAP ::LdapError , "Timed out reading from the socket"
195
+ end
196
+ end
197
+ rescue EOFError
198
+ # nothing to read on the socket (StringIO)
199
+ nil
186
200
end
187
201
end
You can’t perform that action at this time.
0 commit comments