The Trunk: Network-nice.40.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-nice.40.mcz

commits-2
Nicolas Cellier uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-nice.40.mcz

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

Name: Network-nice.40
Author: nice
Time: 7 November 2009, 9:30:57 am
UUID: 41f7cb4d-5d90-47f2-b9cf-fb68878f5012
Ancestors: Network-nice.39

Borrow excellent fix from http://code.google.com/p/pharo/issues/detail?id=1152 and let these instVarAt:put:  out of our sight

=============== Diff against Network-nice.39 ===============

Item was changed:
  ----- Method: HTTPSocket>>getResponseUpTo:ignoring: (in category 'as yet unclassified') -----
  getResponseUpTo: markerString ignoring: ignoreString
  "Keep reading, until the marker is seen, skipping characters in ignoreString when
        comparing to the marker.  Return three parts: header, marker, beginningOfData.
       Fails if no marker in first 2000 chars."
 
+ | buf position bytesRead tester mm skipped |
- | buf response bytesRead tester mm skipped |
  buf := String new: 2000.
+ position := 0.
- response := WriteStream on: buf.
  tester := 1. mm := 1.
  skipped := 0.
  [tester := tester - markerString size + 1 max: 1.  "rewind a little, in case the marker crosses a read boundary"
+ tester to: position do: [:tt |
- tester to: response position do: [:tt |
  (buf at: tt) = (markerString at: mm) ifFalse:
  [[ignoreString includes: (markerString at: mm)] whileTrue:
  [mm := mm + 1. skipped := skipped + 1]].
  (buf at: tt) = (markerString at: mm)
  ifTrue: [mm := mm + 1]
  ifFalse: [mm := 1. skipped := 0].
  "Not totally correct for markers like xx0xx"
  mm > markerString size ifTrue: ["got it"
  ^ Array with: (buf copyFrom: 1 to: tt+1-mm+skipped)
  with: markerString
+ with: (buf copyFrom: tt+1 to: position)]].
+ tester := 1 max: position. "OK if mm in the middle"
+ (position < buf size) & (self isConnected | self dataAvailable)] whileTrue: [
- with: (buf copyFrom: tt+1 to: response position)]].
- tester := 1 max: response position. "OK if mm in the middle"
- (response position < buf size) & (self isConnected | self dataAvailable)] whileTrue: [
  (self waitForDataUntil: (Socket deadlineSecs: 5)) ifFalse: [
  Transcript show: 'data was late'; cr].
  bytesRead := self primSocket: socketHandle receiveDataInto: buf
+ startingAt: position + 1 count: buf size - position..
+ position := position + bytesRead].
- startingAt: response position + 1 count: buf size - response position.
- "response position+1 to: response position+bytesRead do: [:ii |
- response nextPut: (buf at: ii)]. totally redundant, but needed to advance position!!"
- response instVarAt: 2 "position" put:
- (response position + bytesRead)]. "horrible, but fast"
 
+ ^ Array with: (buf copyFrom: 1 to: position)
- ^ Array with: response contents
  with: ''
  with: '' "Marker not found and connection closed"
  !

Item was changed:
  ----- Method: HTTPSocket>>getResponseUpTo: (in category 'as yet unclassified') -----
  getResponseUpTo: markerString
  "Keep reading until the marker is seen.  Return three parts: header, marker, beginningOfData.  Fails if no marker in first 2000 chars."
 
+ | buf position bytesRead tester mm tries |
- | buf response bytesRead tester mm tries |
  buf := String new: 2000.
+ position := 0.
- response := WriteStream on: buf.
  tester := 1. mm := 1.
  tries := 3.
  [tester := tester - markerString size + 1 max: 1.  "rewind a little, in case the marker crosses a read boundary"
+ tester to: position do: [:tt |
- tester to: response position do: [:tt |
  (buf at: tt) = (markerString at: mm) ifTrue: [mm := mm + 1] ifFalse: [mm := 1].
  "Not totally correct for markers like xx0xx"
  mm > markerString size ifTrue: ["got it"
  ^ Array with: (buf copyFrom: 1 to: tt+1-mm)
  with: markerString
+ with: (buf copyFrom: tt+1 to: position)]].
+ tester := 1 max: position. "OK if mm in the middle"
+ (position < buf size) & (self isConnected | self dataAvailable)
- with: (buf copyFrom: tt+1 to: response position)]].
- tester := 1 max: response position. "OK if mm in the middle"
- (response position < buf size) & (self isConnected | self dataAvailable)
  & ((tries := tries - 1) >= 0)] whileTrue: [
  (self waitForDataUntil: (Socket deadlineSecs: 5)) ifFalse: [
  Transcript show: ' <response was late> '].
  bytesRead := self primSocket: socketHandle receiveDataInto: buf
+ startingAt: position + 1 count: buf size - position.
+ position := position + bytesRead].
- startingAt: response position + 1 count: buf size - response position.
- "response position+1 to: response position+bytesRead do: [:ii |
- response nextPut: (buf at: ii)]. totally redundant, but needed to advance position!!"
- response instVarAt: 2 "position" put:
- (response position + bytesRead)]. "horrible, but fast"
 
+ ^ Array with: (buf copyFrom: 1 to position)
- ^ Array with: response contents
  with: ''
  with: '' "Marker not found and connection closed"
  !