Andreas Raab uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ar.79.mcz ==================== Summary ==================== Name: Network-ar.79 Author: ar Time: 22 August 2010, 1:33:40.796 pm UUID: 7c00e4ba-65e0-bb42-ad64-f6eb78527d22 Ancestors: Network-ar.78 Deal with ascii vs. binary in SocketStream #upTo: and #upToAll:. =============== Diff against Network-ar.78 =============== Item was changed: ----- Method: SocketStream>>upToAll:limit: (in category 'stream in') ----- upToAll: aStringOrByteArray limit: nBytes "Answer a subcollection from the current access position to the occurrence (if any, but not inclusive) of aStringOrByteArray. If aCollection is not in the stream, or not found within nBytes answer the available contents of the stream" + | index sz result searchedSoFar target | + "Deal with ascii vs. binary" + self isBinary + ifTrue:[target := aStringOrByteArray asByteArray] + ifFalse:[target := aStringOrByteArray asString]. + + sz := target size. - | index sz result searchedSoFar | - sz := aStringOrByteArray size. "Look in the current inBuffer first" + index := inBuffer indexOfSubCollection: target - index := inBuffer indexOfSubCollection: aStringOrByteArray startingAt: lastRead - sz + 2. (index > 0 and: [(index + sz) <= inNextToWrite]) ifTrue: ["found it" result := self nextInBuffer: index - lastRead - 1. self skip: sz. ^ result ]. [searchedSoFar := self inBufferSize. "Receive more data" self receiveData. recentlyRead > 0] whileTrue:[ "Data begins at lastRead + 1, we add searchedSoFar as offset and backs up sz - 1 so that we can catch any borderline hits." + index := inBuffer indexOfSubCollection: target - index := inBuffer indexOfSubCollection: aStringOrByteArray startingAt: (lastRead + searchedSoFar - sz + 2 max: 1). (index > 0 and: [(index + sz) <= inNextToWrite]) ifTrue: ["found it" result := self nextInBuffer: index - lastRead - 1. self skip: sz. ^ result ]. "Check if we've exceeded the max. amount" (nBytes notNil and:[inNextToWrite - lastRead > nBytes]) ifTrue:[^self nextAllInBuffer]. ]. "not found and (non-signaling) connection was closed" ^self nextAllInBuffer! Item was changed: ----- Method: SocketStream>>upTo:limit: (in category 'stream in') ----- upTo: aCharacterOrByte limit: nBytes "Return data up to, but not including given character or byte. If the character is not in the stream, or not found within nBytes answer the available contents of the stream" + | target index result searchedSoFar | + "Deal with ascii vs. binary" + self isBinary + ifTrue:[target := aCharacterOrByte asInteger] + ifFalse:[target := aCharacterOrByte asCharacter]. + - | index result searchedSoFar | "Look in the current inBuffer first" + index := inBuffer indexOf: target startingAt: lastRead + 1 ifAbsent:[0]. - index := inBuffer indexOf: aCharacterOrByte startingAt: lastRead + 1. (index > 0 and: [(index + 1) <= inNextToWrite]) ifTrue: ["found it" result := self nextInBuffer: index - lastRead - 1. self skip: 1. ^ result ]. [searchedSoFar := self inBufferSize. "Receive more data" self receiveData. "We only get recentlyRead = 0 in the case of a non-signaling socket close." recentlyRead > 0] whileTrue:[ "Data begins at lastRead + 1, we add searchedSoFar as offset." + index := inBuffer indexOf: target + startingAt: (lastRead + searchedSoFar + 1) + ifAbsent:[0]. - index := inBuffer indexOf: aCharacterOrByte - startingAt: (lastRead + searchedSoFar + 1). (index > 0 and: [(index + 1) <= inNextToWrite]) ifTrue: ["found it" result := self nextInBuffer: index - lastRead - 1. self skip: 1. ^ result ]. "Check if we've exceeded the max. amount" (nBytes notNil and:[inNextToWrite - lastRead > nBytes]) ifTrue:[^self nextAllInBuffer]. ]. "not found and (non-signaling) connection was closed" ^self nextAllInBuffer! |
Free forum by Nabble | Edit this page |