[Bug][Fix]? HttpSocket >> #getRestOfBuffer:totalLength:

Gerardo Richarte core.lists.squeak at core-sdi.com
Fri Apr 14 16:13:28 UTC 2000


    Ok, I'm not sure if this a bug or not, but, I know that I needed to fix/change this in order to get out of an infinite loop when updating my image from a remote server (I'm actually using a swiki as updates server, but I don't think this makes a big difference), and it happened every time I tried to update.

    What I changed is size for position in:

    bytesRead _ self primSocket: socketHandle receiveDataInto: buf startingAt: 1
        count: (length - response size).

    for:

    bytesRead _ self primSocket: socketHandle receiveDataInto: buf startingAt: 1
        count: (length - response position).

    as response is initialized with a String new: length, response size is always = length, so length - response size is 0, and then nothing is read.
    What I don't understand is why this works sometimes... can somebody help me on this?

    Ok, I checked #size implementation in 'response class', and it says 'readLimit max: position', so I think #size is not what's needed... Why was it working? was it working when all the response came before entering this method (in beginning?) no way, becouse it still worked when some 'data was late' were printer on the Transcript.
    Conclusion: I don't know if this fix is right or wrong, but I'm sure I needed it.

    Confused Bye!
    Richie++

--
A390 1BBA 2C58 D679 5A71 - 86F9 404F 4B53 3944 C2D0
Investigacion y Desarrollo - CoreLabs - Core SDI
http://www.core-sdi.com

-------------- next part --------------
'From Squeak2.8alpha of 21 March 2000 [latest update: #1974] on 13 April 2000 at 12:56:49 pm'!

!HTTPSocket methodsFor: 'as yet unclassified' stamp: 'r++ 4/13/2000 12:55'!
getRestOfBuffer: beginning totalLength: length
	"Reel in a string of a fixed length.  Part of it has already been received.  Close the connection after all chars are received.  We do not strip out linefeed chars.  tk 6/16/97 22:32" 
	"if length is nil, read until connection close.  Response is of type text, not binary."

	| buf response bytesRead |
	length ifNil: [^ self getRestOfBuffer: beginning].
	buf _ String new: length.
	response _ RWBinaryOrTextStream on: buf.
	response nextPutAll: beginning.
	buf _ String new: length.

	[(response position < length) & (self isConnected | self dataAvailable)] 
	whileTrue: [
		(self waitForDataUntil: (Socket deadlineSecs: 5)) ifFalse: [
	 		Transcript show: 'data was slow'; cr].
		bytesRead _ self primSocket: socketHandle receiveDataInto: buf startingAt: 1 
				count: (length - response position). 
		bytesRead > 0 ifTrue: [  
			response nextPutAll: (buf copyFrom: 1 to: bytesRead)] ].
	"Transcript cr; show: 'data byte count: ', response position printString."
	"Transcript cr; show: ((self isConnected) ifTrue: ['Over length by: ', bytesRead printString] 
		ifFalse: ['Socket closed'])."
	response position < length ifTrue: [^ 'server aborted early'].
	response reset.	"position: 0."
	^ response
! !




More information about the Squeak-dev mailing list