[BUG] Socket accept handling
Stephen Pair
stephen at pairhome.net
Sun Jul 27 04:48:59 UTC 2003
One more time with the changeset. ;)
Stephen Pair wrote:
> It appears that Socket>>waitForAcceptFor: and friends are not working
> in the latest 3.6 image. Attached is a change set that fixes it and
> also adds a couple of related convenience methods.
>
> Also, in 3.6 there appear to be a number of changes relating to method
> contexts and such...I keep encountering "Block cannot return" errors
> during process unwinding (on termination)...these errors are happening
> in code that worked fine in previous releases (specifically it's
> happening when stopping a Service in KomServices). Has anyone
> experienced this?
>
> - Stephen
>
-------------- next part --------------
'From Squeak3.6beta of ''4 July 2003'' [latest update: #5373] on 27 July 2003 at 12:48:27 am'!
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:12'!
waitForAcceptFor: timeout
"Wait and accept an incoming connection"
self waitForConnectionFor: timeout.
^self accept! !
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:23'!
waitForAcceptFor: timeout ifTimedOut: timeoutBlock
"Wait and accept an incoming connection"
self waitForConnectionFor: timeout ifTimedOut: [^timeoutBlock value].
^self accept! !
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:18'!
waitForConnectionFor: timeout
"Wait up until the given deadline for a connection to be established. Return true if it is established by the deadline, false if not."
^self
waitForConnectionFor: timeout
ifTimedOut: [ConnectionTimedOut signal: (NetNameResolver stringFromAddress: self remoteAddress)]
! !
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:01'!
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."
| status deadline |
deadline := Socket deadlineSecs: timeout.
status _ self primSocketConnectionStatus: socketHandle.
[(status = WaitingForConnection) and: [Time millisecondClockValue < deadline]]
whileTrue: [
semaphore waitTimeoutMSecs: (deadline - Time millisecondClockValue).
status _ self primSocketConnectionStatus: socketHandle].
status = Connected ifFalse: [^timeoutBlock value]
! !
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:18'!
waitForDataFor: timeout
"Wait for the given nr of seconds for data to arrive.
Signal a time out or connection close exception if either happens before data becomes available."
^self
waitForDataFor: timeout
ifClosed: [ConnectionClosed signal: 'Connection closed while waiting for data.']
ifTimedOut: [ConnectionTimedOut signal: 'Data receive timed out.']
! !
!Socket methodsFor: 'waiting' stamp: 'svp 7/27/2003 00:16'!
waitForDataFor: timeout ifClosed: closedBlock ifTimedOut: timedOutBlock
"Wait for the given nr of seconds for data to arrive."
| 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]]! !
More information about the Squeak-dev
mailing list
|