[Pkg] The Trunk: Network-nice.113.mcz

commits at source.squeak.org commits at source.squeak.org
Mon Apr 11 14:46:57 UTC 2011


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

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

Name: Network-nice.113
Author: nice
Time: 11 April 2011, 4:47:04.634 pm
UUID: 40d56d77-6610-fa4c-b9fa-317830ba784a
Ancestors: Network-mtf.112

Use #repeat instead of [true] whileTrue

=============== Diff against Network-mtf.112 ===============

Item was changed:
  ----- Method: ConnectionQueue>>listenLoop (in category 'private') -----
  listenLoop
  	"Private!! This loop is run in a separate process. It will establish up to maxQueueLength connections on the given port."
  	"Details: When out of sockets or queue is full, retry more frequently, since a socket may become available, space may open in the queue, or a previously queued connection may be aborted by the client, making it available for a fresh connection."
  	"Note: If the machine is disconnected from the network while the server is running, the currently waiting socket will go from 'isWaitingForConnection' to 'unconnected', and attempts to create new sockets will fail. When this happens, delete the broken socket and keep trying to create a socket in case the network connection is re-established. Connecting and disconnecting was tested under PPP on Mac system 8.1. It is not if this will work on other platforms."
  
  
  	| newConnection |
  
  	socket := Socket newTCP.
  	"We'll accept four simultanous connections at the same time"
  	socket listenOn: portNumber backlogSize: 4.
  	"If the listener is not valid then the we cannot use the
  	BSD style accept() mechanism."
  	socket isValid ifFalse: [^self oldStyleListenLoop].
+ 	[
- 	[true] whileTrue: [
  		socket isValid ifFalse: [
  			"socket has stopped listening for some reason"
  			socket destroy.
  			(Delay forMilliseconds: 10) wait.
  			^self listenLoop ].
  		newConnection := socket 
  			waitForAcceptFor: 10
  			ifTimedOut: [ nil ].
  		(newConnection notNil and: [newConnection isConnected]) ifTrue: [
  			accessSema critical: [connections addLast: newConnection.].
  			newConnection := nil.
  			self changed].
+ 		self pruneStaleConnections] repeat!
- 		self pruneStaleConnections]. !

Item was changed:
  ----- Method: ConnectionQueue>>oldStyleListenLoop (in category 'private') -----
  oldStyleListenLoop
  	"Private!! This loop is run in a separate process. It will establish up to maxQueueLength connections on the given port."
  	"Details: When out of sockets or queue is full, retry more frequently, since a socket may become available, space may open in the queue, or a previously queued connection may be aborted by the client, making it available for a fresh connection."
  	"Note: If the machine is disconnected from the network while the server is running, the currently waiting socket will go from 'isWaitingForConnection' to 'unconnected', and attempts to create new sockets will fail. When this happens, delete the broken socket and keep trying to create a socket in case the network connection is re-established. Connecting and disconnecting was tested under PPP on Mac system 8.1. It is not if this will work on other platforms."
  
+ 	[
- 	[true] whileTrue: [
  		((socket == nil) and: [connections size < maxQueueLength]) ifTrue: [
  			"try to create a new socket for listening"
  			socket := Socket createIfFail: [nil]].
  
  		socket == nil
  			ifTrue: [(Delay forMilliseconds: 100) wait]
  			ifFalse: [
  				socket isUnconnected ifTrue: [socket listenOn: portNumber].
  				socket 
  					waitForConnectionFor: 10
  					ifTimedOut: [
  						socket isConnected
  							ifTrue: [  "connection established"
  								accessSema critical: [connections addLast: socket].
  								socket := nil]
  							ifFalse: [
  								socket isWaitingForConnection
  									ifFalse: [socket destroy. socket := nil]]]].  "broken socket; start over"
+ 		self pruneStaleConnections] repeat!
- 		self pruneStaleConnections].
- !

Item was changed:
  ----- Method: NetNameResolver class>>addressForName:timeout: (in category 'lookups') -----
  addressForName: hostName timeout: secs
  	"Look up the given host name and return its address. Return nil if the address is not found in the given number of seconds."
  	"NetNameResolver addressForName: 'create.ucsb.edu' timeout: 30"
  	"NetNameResolver addressForName: '100000jobs.de' timeout: 30"
  	"NetNameResolver addressForName: '1.7.6.4' timeout: 30"
  	"NetNameResolver addressForName: '' timeout: 30 (This seems to return nil?)"
  
  	| deadline result |
  	self initializeNetwork.
  	"check if this is a valid numeric host address (e.g. 1.2.3.4)"
  	result := self addressFromString: hostName.
+ 	result ifNotNil: [^result].
- 	result isNil ifFalse: [^result].
  
  	"Look up a host name, including ones that start with a digit (e.g. 100000jobs.de or squeak.org)"
  	deadline := Time millisecondClockValue + (secs * 1000).
  	"Protect the execution of this block, as the ResolverSemaphore is used for both parts of the transaction."
  	self resolverMutex
  		critical: [
  			(self waitForResolverReadyUntil: deadline)
  				ifTrue: [
  					self primStartLookupOfName: hostName.
  					(self waitForCompletionUntil: deadline)
  						ifTrue: [result := self primNameLookupResult]
  						ifFalse: [(NameLookupFailure hostName: hostName) signal: 'Could not resolve the server named: ', hostName]]
  				ifFalse: [(NameLookupFailure hostName: hostName) signal: 'Could not resolve the server named: ', hostName]].
  	^result!



More information about the Packages mailing list