[Pkg] The Trunk: Network-nice.150.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Dec 25 22:23:02 UTC 2013
Nicolas Cellier uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-nice.150.mcz
==================== Summary ====================
Name: Network-nice.150
Author: nice
Time: 25 December 2013, 11:22:19.983 pm
UUID: c844e5ea-c919-44fc-905e-69487b035947
Ancestors: Network-nice.149
Change a few print:(aFloat roundTo: 0.01) into nextPutAll:(aFloat printShowingMaxDecimalPlaces: 2)
=============== Diff against Network-nice.149 ===============
Item was changed:
----- Method: Socket class>>loopbackTest (in category 'tests') -----
loopbackTest
"Send data from one socket to another on the local machine.
Tests most of the socket primitives."
"100 timesRepeat: [Socket loopbackTest]"
| sock1 sock2 bytesToSend sendBuf receiveBuf done bytesSent bytesReceived t extraBytes packetsSent packetsRead |
Transcript
cr;
show: 'starting loopback test';
cr.
Transcript
show: '---------- Connecting ----------';
cr.
self initializeNetwork.
sock1 := self new.
sock2 := self new.
sock1 listenOn: 54321.
sock2 connectTo: NetNameResolver localHostAddress port: 54321.
sock1 waitForConnectionFor: self standardTimeout.
sock2 waitForConnectionFor: self standardTimeout.
sock1 isConnected ifFalse: [self error: 'sock1 not connected'].
sock2 isConnected ifFalse: [self error: 'sock2 not connected'].
Transcript
show: 'connection established';
cr.
bytesToSend := 5000000.
sendBuf := String new: 5000 withAll: $x.
receiveBuf := String new: 50000.
done := false.
packetsSent := packetsRead := bytesSent := bytesReceived := 0.
t := Time millisecondsToRun:
[[done] whileFalse:
[(sock1 sendDone and: [bytesSent < bytesToSend])
ifTrue:
[packetsSent := packetsSent + 1.
bytesSent := bytesSent + (sock1 sendSomeData: sendBuf)].
sock2 dataAvailable
ifTrue:
[packetsRead := packetsRead + 1.
bytesReceived := bytesReceived + (sock2 receiveDataInto: receiveBuf)].
done := bytesSent >= bytesToSend and: [bytesReceived = bytesSent]]].
Transcript
show: 'closing connection';
cr.
sock1 waitForSendDoneFor: self standardTimeout.
sock1 close.
sock2 waitForDisconnectionFor: self standardTimeout.
extraBytes := sock2 discardReceivedData.
extraBytes > 0
ifTrue:
[Transcript
show: ' *** received ' , extraBytes size printString , ' extra bytes ***';
cr].
sock2 close.
sock1 waitForDisconnectionFor: self standardTimeout.
sock1 isUnconnectedOrInvalid ifFalse: [self error: 'sock1 not closed'].
sock2 isUnconnectedOrInvalid ifFalse: [self error: 'sock2 not closed'].
Transcript
show: '---------- Connection Closed ----------';
cr.
sock1 destroy.
sock2 destroy.
Transcript
show: 'loopback test done; time = ' , t printString;
cr.
Transcript
+ show: (bytesToSend asFloat / t printShowingMaxDecimalPlaces: 2), '* 1000 bytes/sec';
- show: (bytesToSend asFloat / t roundTo: 0.01) printString
- , '* 1000 bytes/sec';
cr.
Transcript endEntry!
Item was changed:
----- Method: Socket class>>sendTest (in category 'tests') -----
sendTest
"Send data to the 'discard' socket of the given host.
Tests the speed of one-way data transfers across the
network to the given host. Note that most hosts
do not run a discard server."
"Socket sendTest"
| sock bytesToSend sendBuf bytesSent t serverName serverAddr |
Transcript cr; show: 'starting send test'; cr.
self initializeNetwork.
serverName := UIManager default request: 'What is the destination server?' initialAnswer: 'create.ucsb.edu'.
serverAddr := NetNameResolver addressForName: serverName timeout: 10.
serverAddr = nil
ifTrue: [^self inform: 'Could not find an address for ' , serverName].
sock := self new.
Transcript show: '---------- Connecting ----------';cr.
sock connectTo: serverAddr port: 9.
sock isConnected ifFalse: [
sock destroy.
^self inform: 'could not connect'].
Transcript show: 'connection established; sending data'; cr.
bytesToSend := 1000000.
sendBuf := String new: 64 * 1024 withAll: $x.
bytesSent := 0.
t := Time millisecondsToRun:
[[bytesSent < bytesToSend] whileTrue:
[sock sendDone
ifTrue: [bytesSent := bytesSent + (sock sendSomeData: sendBuf)]]].
sock waitForSendDoneFor: self standardTimeout.
sock destroy.
Transcript show: '---------- Connection Closed ----------'; cr;
show: 'send test done; time = ' , t printString; cr;
+ show: (bytesToSend asFloat / t printShowingMaxDecimalPlaces: 2), ' * 1000 bytes/sec';cr;endEntry!
- show: (bytesToSend asFloat / t roundTo: 0.01) printString, ' * 1000 bytes/sec';cr;endEntry!
More information about the Packages
mailing list