The Trunk: Network-ar.61.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Network-ar.61.mcz

commits-2
Andreas Raab uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ar.61.mcz

==================== Summary ====================

Name: Network-ar.61
Author: ar
Time: 23 February 2010, 1:09:56.624 pm
UUID: c839f8ef-8b3f-a247-bf16-48aba1e56435
Ancestors: Network-cmm.60

Provide implementations of SocketStream #nextInto:, #next:into: #nextInto:startingAt: and #next:into:startingAt:. These methods are useful to avoid excessive allocations when streaming because the buffer can be passed to SocketStream without requiring a full buffer allocation per call (as would be the case in next: or nextAvailable:).


=============== Diff against Network-cmm.60 ===============

Item was added:
+ ----- Method: SocketStream>>next:into: (in category 'stream in') -----
+ next: n into: aCollection
+ "Read n objects into the given collection.
+ Return aCollection or a partial copy if less than
+ n elements have been read."
+ ^self next: n into: aCollection startingAt: 1!

Item was added:
+ ----- Method: SocketStream>>nextInto:startingAt: (in category 'stream in') -----
+ nextInto: aCollection startingAt: startIndex
+ "Read the next elements of the receiver into aCollection.
+ Return aCollection or a partial copy if less than aCollection
+ size elements have been read."
+ ^self next: (aCollection size - startIndex+1) into: aCollection startingAt: startIndex.!

Item was added:
+ ----- Method: SocketStream>>next:into:startingAt: (in category 'stream in') -----
+ next: anInteger into: aCollection startingAt: startIndex
+ "Read n objects into the given collection.
+ Return aCollection or a partial copy if less than
+ n elements have been read."
+
+ "Implementation note: This method DOES signal timeout if not
+ enough elements are received. It does NOT signal
+ ConnectionClosed as closing the connection is the only way by
+ which partial data can be read."
+
+ | start amount |
+
+ [self receiveData: anInteger] on: ConnectionClosed do:[:ex| ex return].
+
+ "Inlined version of nextInBuffer: to avoid copying the contents"
+ amount := anInteger min: (inNextToWrite - lastRead - 1).
+ start := lastRead + 1.
+ lastRead := lastRead + amount.
+ aCollection
+ replaceFrom: startIndex
+ to: startIndex + amount-1
+ with: inBuffer
+ startingAt: start.
+ ^amount < anInteger
+ ifTrue:[aCollection copyFrom: 1 to:  startIndex + amount-1]
+ ifFalse:[aCollection]!

Item was added:
+ ----- Method: SocketStream>>nextInto: (in category 'stream in') -----
+ nextInto: aCollection
+ "Read the next elements of the receiver into aCollection.
+ Return aCollection or a partial copy if less than aCollection
+ size elements have been read."
+ ^self next: aCollection size into: aCollection startingAt: 1.!