The Trunk: Network-ul.163.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-ul.163.mcz

commits-2
Levente Uzonyi uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ul.163.mcz

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

Name: Network-ul.163
Author: ul
Time: 9 October 2015, 10:28:22.138 pm
UUID: 31998b51-bd36-4363-a48f-f9ba31617935
Ancestors: Network-mt.162

NetNameResolver changes:
- do not raise an error from within the critical section of #addressForName:timeout:, because a debugger in the image would block NetNameResolver
- define the deadline using an absolute clock in all name lookup operations instead of Time >> #millisecondClockValue, because the latter will lock up NetNameResolver when its value would roll over before the lookup deadline ends and the resolver is busy
- added #nameForAddress: with the same default timeout value as #addressForName:

=============== Diff against Network-mt.162 ===============

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.
  self useOldNetwork
  ifFalse: [^self addressForName: hostName].
  "check if this is a valid numeric host address (e.g. 1.2.3.4)"
+ (self addressFromString: hostName) ifNotNil: [ :numericHostAddress |
+ ^numericHostAddress ].
- result := self addressFromString: hostName.
- 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 primUTCMicrosecondClock + (secs * 1000000).
- 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)
+ ifFalse: [ 'Could not resolve the server named: ', hostName ]
+ ifTrue: [
+ self primStartLookupOfName: hostName.
+ (self waitForCompletionUntil: deadline)
+ ifFalse: [ 'Could not resolve the server named: ', hostName ]
+ ifTrue: [
+ result := self primNameLookupResult.
+ nil "No error" ] ] ])
+ ifNotNil: [ :message | (NameLookupFailure hostName: hostName) signal: message ].
- 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!

Item was added:
+ ----- Method: NetNameResolver class>>nameForAddress: (in category 'lookups') -----
+ nameForAddress: hostAddress
+
+ ^self nameForAddress: hostAddress timeout: 60!

Item was changed:
  ----- Method: NetNameResolver class>>nameForAddress:timeout: (in category 'lookups') -----
  nameForAddress: hostAddress timeout: secs
  "Look up the given host address and return its name. Return nil if the lookup fails or is not completed in the given number of seconds. Depends on the given host address being known to the gateway, which may not be the case for dynamically allocated addresses."
  "NetNameResolver
  nameForAddress: (NetNameResolver addressFromString: '128.111.92.2')
  timeout: 30"
 
  | deadline |
  self initializeNetwork.
+ deadline := DateAndTime now + secs seconds.
- 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 primStartLookupOfAddress: hostAddress.
  (self waitForCompletionUntil: deadline)
  ifTrue: [self primAddressLookupResult]
  ifFalse: [nil]]
  ifFalse: [nil]].!

Item was changed:
  ----- Method: NetNameResolver class>>waitForCompletionUntil: (in category 'private') -----
  waitForCompletionUntil: deadline
+ "Wait until deadlien for the resolver to be ready to accept a new request. Return true if the resolver is ready, false if the network is not initialized or the resolver has not become free within the given time period."
- "Wait up to the given number of seconds for the resolver to be ready to accept a new request. Return true if the resolver is ready, false if the network is not initialized or the resolver does not become free within the given time period."
 
+ | status millisecondsLeft |
- | status |
  status := self resolverStatus.
+ [ status = ResolverBusy and: [
+ millisecondsLeft := deadline isLarge
+ ifTrue: [ (deadline - Time primUTCMicrosecondClock) // 1000 ]
+ ifFalse: [ deadline - Time millisecondClockValue ].
+ millisecondsLeft > 0  ] ]
- [(status = ResolverBusy) and:
- [Time millisecondClockValue < deadline]]
  whileTrue: [
  "wait for resolver to be available"
+ ResolverSemaphore waitTimeoutMSecs: millisecondsLeft.
+ status := self resolverStatus ].
+ status = ResolverReady ifTrue: [ ^true ].
+ status = ResolverBusy ifTrue: [ self primAbortLookup ].
+ ^false
- ResolverSemaphore waitTimeoutMSecs: (deadline - Time millisecondClockValue).
- status := self resolverStatus].
-
- status = ResolverReady
- ifTrue: [^ true]
- ifFalse: [
- status = ResolverBusy ifTrue: [self primAbortLookup].
- ^ false].
  !

Item was changed:
  ----- Method: NetNameResolver class>>waitForResolverReadyUntil: (in category 'private') -----
  waitForResolverReadyUntil: deadline
+ "Wait until deadline for the resolver to be ready to accept a new request. Return true if the resolver is not busy, false if the network is not initialized or the resolver has not become free within the given time period."
- "Wait up to the given number of seconds for the resolver to be ready to accept a new request. Return true if the resolver is not busy, false if the network is not initialized or the resolver does not become free within the given time period."
 
+ | status millisecondsLeft |
+ (status := self resolverStatus) = ResolverUninitialized ifTrue: [ ^false ].
+ [ status = ResolverBusy and: [
+ millisecondsLeft := deadline isLarge
+ ifTrue: [ (deadline - Time primUTCMicrosecondClock) // 1000 ]
+ ifFalse: [ deadline - Time millisecondClockValue ].
+ millisecondsLeft > 0 ] ]
- | status |
- status := self resolverStatus.
- status = ResolverUninitialized ifTrue: [^ false].
-
- [(status = ResolverBusy) and:
- [Time millisecondClockValue < deadline]]
  whileTrue: [
  "wait for resolver to be available"
+ ResolverSemaphore waitTimeoutMSecs: millisecondsLeft.
+ status := self resolverStatus ].
+ ^status ~= ResolverBusy!
- ResolverSemaphore waitTimeoutMSecs: (deadline - Time millisecondClockValue).
- status := self resolverStatus].
-
- ^ status ~= ResolverBusy
- !