[Pkg] The Trunk: Network-ar.75.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Jul 24 22:09:28 UTC 2010


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

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

Name: Network-ar.75
Author: ar
Time: 24 July 2010, 3:08:56.964 pm
UUID: 41c4e3ec-04fd-4949-b38e-7fa37e9a4874
Ancestors: Network-ar.74

Some SocketStream simplifications: Avoid duplication between #receiveData; #receiveDataIfAvailable; and #receiveAvailableData; they are just minor variants of each other. Also bottleneck all socket reads and writes in two SocketStream methods #receiveDataInto:startingAt: and #sendData:count: so that subclasses can do additional operations on them (encryption, statistics etc).

=============== Diff against Network-ar.74 ===============

Item was added:
+ ----- Method: SocketStream>>receiveDataInto:startingAt: (in category 'private-socket') -----
+ receiveDataInto: buffer startingAt: index.
+ 	"Read data from the underlying socket. This method may be overridden by subclasses wanting to control incoming traffic for other purposes like encryption or statistics."
+ 
+ 	^socket  receiveAvailableDataInto: buffer startingAt: index.!

Item was added:
+ ----- Method: SocketStream>>sendData:count: (in category 'private-socket') -----
+ sendData: buffer count: n
+ 	"Sends outgoing data directly on the underlying socket."
+ 
+ 	^socket sendData: buffer count: n!

Item was changed:
  ----- Method: SocketStream>>receiveDataIfAvailable (in category 'private-socket') -----
  receiveDataIfAvailable
+ 	"Deprecated. Use #receiveAvailableData instead"
- 	"Only used to check that there really is data to read
- 	from the socket after it signals dataAvailable.
- 	It has been known to signal true and then still
- 	not have anything to read. See also isDataAvailable.
- 	Return the position in the buffer where the
- 	new data starts, regardless if anything
- 	was read, see #adjustInBuffer."
  
+ 	^self receiveAvailableData!
- 	recentlyRead := socket receiveSomeDataInto: inBuffer startingAt: inNextToWrite.
- 	^self adjustInBuffer: recentlyRead!

Item was changed:
  ----- Method: SocketStream>>receiveData (in category 'private-socket') -----
  receiveData
+ 	"Receive data. Signal exceptions and timeouts depending on #shouldSignal and #shouldTimeout. Return the position in the buffer where the new data starts, regardless if anything was read."
+ 
+ 	socket
+ 		waitForDataFor: self timeout
+ 		ifClosed: [self shouldSignal 
+ 			ifTrue:[ConnectionClosed signal: 'Connection closed while waiting for data.']]
+ 		ifTimedOut: [self shouldTimeout
+ 			ifTrue:[ConnectionTimedOut signal: 'Data receive timed out.']].
+ 	^self receiveAvailableData!
- 	"Receive data with timeout if it has been set.
- 	If shouldSignal is false we use the Socket methods
- 	that swallow those Exceptions, if it is true the
- 	caller will have to handle those Exceptions.
- 	Return the position in the buffer where the
- 	new data starts, regardless if anything
- 	was read, see #adjustInBuffer."
- 	
- 	recentlyRead := shouldSignal ifTrue: [
- 		self shouldTimeout ifTrue: [
- 				socket receiveDataSignallingTimeout: timeout
- 					into: inBuffer startingAt: inNextToWrite]
- 			ifFalse: [
- 				socket receiveDataSignallingClosedInto: inBuffer
- 					startingAt: inNextToWrite]]
- 				ifFalse: [
- 		self shouldTimeout ifTrue: [
- 			"This case is tricky, if it times out and is swallowed
- 			how does other methods calling this method repeatedly
- 			get to know that? And what should they do?"
- 				socket receiveDataTimeout: timeout
- 					into: inBuffer startingAt: inNextToWrite]
- 			ifFalse: [
- 				socket receiveDataInto: inBuffer
- 					startingAt: inNextToWrite]].
- 	^self adjustInBuffer: recentlyRead!

Item was changed:
  ----- Method: SocketStream>>nextPutAllFlush: (in category 'stream out') -----
  nextPutAllFlush: aCollection
  	"Put a String or a ByteArray onto the stream.
  	You can use this if you have very large data - it avoids
  	copying into the buffer (and avoids buffer growing)
  	and also flushes any other pending data first."
  
  	| toPut |
  	toPut := binary ifTrue: [aCollection asByteArray] ifFalse: [aCollection asString].
  	self flush. "first flush pending stuff, then directly send"
  	socket isOtherEndClosed ifFalse: [
+ 		[self sendData: toPut count: toPut size]
- 		[socket sendData: toPut count: toPut size]
  			on: ConnectionTimedOut
  			do: [:ex | shouldSignal ifFalse: ["swallow"]]]!

Item was changed:
  ----- Method: SocketStream>>flush (in category 'control') -----
  flush
  	"If the other end is connected and we have something
  	to send, then we send it and reset the outBuffer."
  
  	((outNextToWrite > 1) and: [socket isOtherEndClosed not])
  		ifTrue: [
+ 			[self sendData: outBuffer count: outNextToWrite - 1]
- 			[socket sendData: outBuffer count: outNextToWrite - 1]
  				on: ConnectionTimedOut
  				do: [:ex | shouldSignal ifFalse: ["swallow"]].
  			outNextToWrite := 1]!

Item was changed:
  ----- Method: SocketStream>>isDataAvailable (in category 'testing') -----
  isDataAvailable
+ 	"Answer if more data can be read. It the inbuffer is empty, we check the socket for data. If it claims to have data available to read, we try to read some once and recursively call this method again. If something really was available it is now in the inBuffer. This is because there has been spurious dataAvailable when there really is no data to get.
+ 
+ 	Note: Some subclasses (such as SecureSocketStream) rely on the behavior here since even though data may be available in the underlying socket, it may not result in any output (yet)."
- 	"It the inbuffer is empty, we check the socket for data.
- 	If it claims to have data available to read, we try to read
- 	some once and recursively call this method again.
- 	If something really was available it is now in the inBuffer.
- 	This is because there has been spurious
- 	dataAvailable when there really is no data to get."
   
  	self isInBufferEmpty ifFalse: [^true].
  	^socket dataAvailable
  		ifFalse: [false]
+ 		ifTrue: [self receiveAvailableData; isDataAvailable]!
- 		ifTrue: [self receiveDataIfAvailable; isDataAvailable]!

Item was changed:
  ----- Method: SocketStream>>receiveAvailableData (in category 'private-socket') -----
  receiveAvailableData
+ 	"Receive available data (as much as fits in the inBuffer) but not waiting for more to arrive. Return the position in the buffer where the new data starts, regardless if anything was read, see #adjustInBuffer."
- 	"Receive available data (as much as fits in the inBuffer)
- 	but not waiting for more to arrive.
- 	Return the position in the buffer where the
- 	new data starts, regardless if anything
- 	was read, see #adjustInBuffer."
  	
+ 	recentlyRead := self receiveDataInto: inBuffer startingAt: inNextToWrite.
- 	recentlyRead := socket receiveAvailableDataInto: inBuffer startingAt: inNextToWrite.
  	^self adjustInBuffer: recentlyRead!



More information about the Packages mailing list