File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,30 @@ def close
111
111
@conn = nil
112
112
end
113
113
114
+ # Internal: Reads messages by ID from a queue, falling back to reading from
115
+ # the connected socket until a message matching the ID is read. Any messages
116
+ # with mismatched IDs gets queued for subsequent reads by the origin of that
117
+ # message ID.
118
+ #
119
+ # Returns a Net::LDAP::PDU object or nil.
120
+ def queued_read ( message_id )
121
+ if pdu = ( @queue [ message_id ] || [ ] ) . shift
122
+ return pdu
123
+ end
124
+
125
+ while pdu = read
126
+ if pdu . message_id == message_id
127
+ return pdu
128
+ else
129
+ @queue [ pdu . message_id ] . push pdu
130
+
131
+ next
132
+ end
133
+ end
134
+
135
+ pdu
136
+ end
137
+
114
138
# Internal: Reads and parses data from the configured connection.
115
139
#
116
140
# - syntax: the BER syntax to use to parse the read data with
@@ -413,12 +437,7 @@ def search(args = {})
413
437
result_pdu = nil
414
438
controls = [ ]
415
439
416
- while pdu = ( @queue [ message_id ] . shift || read )
417
- if pdu . message_id != message_id
418
- @queue [ pdu . message_id ] . push pdu
419
- next
420
- end
421
-
440
+ while pdu = queued_read ( message_id )
422
441
case pdu . app_tag
423
442
when Net ::LDAP ::PDU ::SearchReturnedData
424
443
n_results += 1
You can’t perform that action at this time.
0 commit comments