Skip to content

Commit 6cbb814

Browse files
committed
Extract message_queue accessor, documentation, cleanup
1 parent acd676e commit 6cbb814

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

lib/net/ldap/connection.rb

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,38 @@ def close
118118
#
119119
# Returns a Net::LDAP::PDU object or nil.
120120
def queued_read(message_id)
121-
if pdu = (@queue[message_id] || []).shift
121+
if pdu = message_queue[message_id].shift
122122
return pdu
123123
end
124124

125+
# read messages until we have a match for the given message_id
125126
while pdu = read
126127
if pdu.message_id == message_id
127128
return pdu
128129
else
129-
@queue[pdu.message_id].push pdu
130-
130+
message_queue[pdu.message_id].push pdu
131131
next
132132
end
133133
end
134134

135135
pdu
136136
end
137137

138+
# Internal: The internal queue of messages, read from the socket, grouped by
139+
# message ID.
140+
#
141+
# Used by `queued_read` to return messages sent by the server with the given
142+
# ID. If no messages are queued for that ID, `queued_read` will `read` from
143+
# the socket and queue messages that don't match the given ID for other
144+
# readers.
145+
#
146+
# Returns the message queue Hash.
147+
def message_queue
148+
@message_queue ||= Hash.new do |hash, key|
149+
hash[key] = []
150+
end
151+
end
152+
138153
# Internal: Reads and parses data from the configured connection.
139154
#
140155
# - syntax: the BER syntax to use to parse the read data with
@@ -380,9 +395,7 @@ def search(args = {})
380395
result_pdu = nil
381396
n_results = 0
382397

383-
@queue ||= {}
384398
message_id = next_msgid
385-
@queue[message_id] ||= []
386399

387400
instrument "search.net_ldap_connection",
388401
:message_id => message_id,

0 commit comments

Comments
 (0)