[Pharo-project] Issue 3350 in pharo: Network Tests

pharo at googlecode.com pharo at googlecode.com
Sat Nov 27 18:42:49 CET 2010


Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3

New issue 3350 by stephane.ducasse: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350

Item was changed:
  ----- Method: Socket>>localAddress (in category 'accessing') -----
  localAddress
+
+       self isWaitingForConnection ifFalse: [
+               self
+                       waitForConnectionFor: Socket standardTimeout
+                       ifTimedOut: [ ^ByteArray new: 4 ] ].
+       ^self primSocketLocalAddress: socketHandle!
-       self isWaitingForConnection
-               ifFalse: [[self waitForConnectionFor: Socket  
standardTimeout]
-                               on: ConnectionTimedOut
-                               do: [:ex | ^ ByteArray new: 4]].
-       ^ self primSocketLocalAddress: socketHandle!

Item was changed:
  ----- Method: Socket>>localPort (in category 'accessing') -----
  localPort
+
+       self isWaitingForConnection ifFalse: [
+               self
+                       waitForConnectionFor: Socket standardTimeout
+                       ifTimedOut: [ ^0] ].
-       self isWaitingForConnection
-               ifFalse: [[self waitForConnectionFor: Socket  
standardTimeout]
-                               on: ConnectionTimedOut
-                               do: [:ex | ^ 0]].
        ^ self primSocketLocalPort: socketHandle!

Item was changed:
  ----- Method: Socket>>waitForAcceptFor: (in category 'waiting') -----
  waitForAcceptFor: timeout
        "Wait and accept an incoming connection. Return nil if it falis"
+       self waitForConnectionFor: timeout ifTimedOut: [^ nil].
+       ^ self isConnected
-       [self waitForConnectionFor: timeout] on: ConnectionTimedOut do:  
[:ex | ^nil].
-       ^self isConnected
                ifTrue:[self accept]
                !

Item was changed:
  ----- Method: Socket>>waitForConnectionFor:ifTimedOut: (in  
category 'waiting') -----
  waitForConnectionFor: timeout ifTimedOut: timeoutBlock
        "Wait up until the given deadline for a connection to be  
established. Return true if it is established by the deadline, false if  
not."

+       | startTime msecsDelta msecsEllapsed status |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
-       | status deadline |
-       deadline := Socket deadlineSecs: timeout.
        status := self primSocketConnectionStatus: socketHandle.
+       [(status = WaitingForConnection) and: [(msecsEllapsed := Time  
millisecondsSince: startTime) < msecsDelta]]
-       [(status = WaitingForConnection) and: [Time millisecondClockValue <  
deadline]]
                whileTrue: [
+                       semaphore waitTimeoutMSecs: msecsDelta -  
msecsEllapsed.
-                       semaphore waitTimeoutMSecs: (deadline - Time  
millisecondClockValue).
                        status := self primSocketConnectionStatus:  
socketHandle].

+       status = Connected ifFalse: [^timeoutBlock value].
+       ^ true!
-       status = Connected ifFalse: [^timeoutBlock value]
- !

Item was changed:
  ----- Method: Socket>>waitForDataFor:ifClosed:ifTimedOut: (in  
category 'waiting') -----
  waitForDataFor: timeout ifClosed: closedBlock ifTimedOut: timedOutBlock
        "Wait for the given nr of seconds for data to arrive."
+
+       | startTime msecsDelta |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
+       [(Time millisecondsSince: startTime) < msecsDelta] whileTrue: [
+               (self primSocketReceiveDataAvailable: socketHandle)
+                       ifTrue: [^self].
+               self isConnected
+                       ifFalse: [^closedBlock value].
+               self readSemaphore waitTimeoutMSecs:
+                       (msecsDelta - (Time millisecondsSince: startTime)  
max: 0).
+       ].

-       | deadline |
-       deadline := Socket deadlineSecs: timeout.
-
-       [Time millisecondClockValue < deadline]
-               whileTrue: [
-                       (self primSocketReceiveDataAvailable: socketHandle)
-                               ifTrue: [^self].
-                       self isConnected
-                               ifFalse: [^closedBlock value].
-                       self readSemaphore waitTimeoutMSecs: (deadline -  
Time millisecondClockValue)].
-
        (self primSocketReceiveDataAvailable: socketHandle)
                ifFalse: [
                        self isConnected
                                ifTrue: [^timedOutBlock value]
+                               ifFalse: [^closedBlock value]].!
-                               ifFalse: [^closedBlock value]]!

Item was changed:
  ----- Method: Socket>>waitForDisconnectionFor: (in category 'waiting')  
-----
  waitForDisconnectionFor: timeout
        "Wait for the given nr of seconds for the connection to be broken.
        Return true if it is broken by the deadline, false if not.
        The client should know the connection is really going to be closed
        (e.g., because he has called 'close' to send a close request to the  
other end)
        before calling this method."

+       | startTime msecsDelta status |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
-       | status deadline |
        status := self primSocketConnectionStatus: socketHandle.
-       deadline := Socket deadlineSecs: timeout.
        [((status == Connected) or: [(status == ThisEndClosed)]) and:
+        [(Time millisecondsSince: startTime) < msecsDelta]] whileTrue: [
-        [Time millisecondClockValue < deadline]] whileTrue: [
                self discardReceivedData.
+               self readSemaphore waitTimeoutMSecs:
+                       (msecsDelta - (Time millisecondsSince: startTime)  
max: 0).
-               self readSemaphore waitTimeoutMSecs: (deadline - Time  
millisecondClockValue).
                status := self primSocketConnectionStatus: socketHandle].
+       ^ status ~= Connected!
-
-       ^ status ~= Connected
- !
Item was changed:
  ----- Method: Socket>>waitForSendDoneFor: (in category 'waiting') -----
  waitForSendDoneFor: timeout
        "Wait up until the given deadline for the current send operation to  
complete. Return true if it completes by the deadline, false if not."

+       | startTime msecsDelta msecsEllapsed sendDone |
+       startTime := Time millisecondClockValue.
+       msecsDelta := (timeout * 1000) truncated.
+       [(sendDone := self primSocketSendDone: socketHandle) not and: [  
self isConnected
-       | sendDone deadline |
-       deadline := Socket deadlineSecs: timeout.
-       [self isConnected & (sendDone := self primSocketSendDone:  
socketHandle) not
                        "Connection end and final data can happen fast, so  
test in this order"
+               and: [(msecsEllapsed := Time millisecondsSince: startTime)  
< msecsDelta]]] whileTrue: [
+                       self writeSemaphore waitTimeoutMSecs: msecsDelta -  
msecsEllapsed].
-               and: [Time millisecondClockValue < deadline]] whileTrue: [
-                       self writeSemaphore waitTimeoutMSecs: (deadline -  
Time millisecondClockValue)].

        ^ sendDone!

Item was changed:
  ----- Method: SocksSocket>>connectTo:port: (in category 'connection  
open/close') -----
  connectTo: hostAddress port: port
        self initializeNetwork.
        self shouldUseSocks
                ifFalse: [^super connectTo: hostAddress port: port].
        super connectTo: socksIP port: socksPort.
+       self waitForConnectionFor: Socket standardTimeout.
-       self waitForConnectionUntil: Socket standardDeadline.
        dstIP := hostAddress.
        dstPort := port.
        vers = 4
                ifTrue: [self connectSocks4]
                ifFalse: [self connectSocks5]
        !

Item was changed:
  ----- Method: SocksSocket>>connectToHostNamed:port: (in  
category 'connection open/close') -----
  connectToHostNamed: hostName port: port
        super connectTo: socksIP port: socksPort.
+       self waitForConnectionFor: Socket standardTimeout.
-       self waitForConnectionUntil: Socket standardDeadline.
        dstName := hostName.
        dstPort := port.
        vers = 4
                ifTrue: [self connectSocks4]
                ifFalse: [self connectSocks5]
        !





More information about the Pharo-project mailing list