Pharo-dev
By thread
pharo-dev@lists.pharo.org
By month
Messages by month
- ----- 2026 -----
- July
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
November 2010
- 115 participants
- 1614 messages
Re: [Pharo-project] Cannot assign a parameter
by laurent laffont
Sorry
foo: n
^[:i| n := n+i. ]
vs
foo: n
|s|
s := n.
^[:i| s := s+i. ]
Laurent
On Sun, Nov 28, 2010 at 10:51 AM, Max Leske <maxleske(a)gmail.com> wrote:
> In the first example you didn't declare 's':
>
> foo:n
> ^ [ :i || s | s:= s+i ]
>
> Or did I misunderstand the question?
>
> Cheers,
> Max
>
>
> On 28.11.2010, at 10:30, laurent laffont wrote:
>
> Hi,
>
> I can't write
>
> foo: n
> ^[:i| s := s+i. ]
>
> but
>
> foo: n
> |s|
> s := n.
> ^[:i| s := s+i. ]
>
>
> Why ?
>
>
> Cheers,
>
> Laurent Laffont
>
> Pharo Smalltalk Screencasts: http://www.pharocasts.com/
> Blog: http://magaloma.blogspot.com/
>
>
>
Nov. 28, 2010
Re: [Pharo-project] Cannot assign a parameter
by Max Leske
In the first example you didn't declare 's':
foo:n
^ [ :i || s | s:= s+i ]
Or did I misunderstand the question?
Cheers,
Max
On 28.11.2010, at 10:30, laurent laffont wrote:
> Hi,
>
> I can't write
>
> foo: n
> ^[:i| s := s+i. ]
>
> but
>
> foo: n
> |s|
> s := n.
> ^[:i| s := s+i. ]
>
>
> Why ?
>
>
> Cheers,
>
> Laurent Laffont
>
> Pharo Smalltalk Screencasts: http://www.pharocasts.com/
> Blog: http://magaloma.blogspot.com/
Nov. 28, 2010
[Pharo-project] Cannot assign a parameter
by laurent laffont
Hi,
I can't write
foo: n
^[:i| s := s+i. ]
but
foo: n
|s|
s := n.
^[:i| s := s+i. ]
Why ?
Cheers,
Laurent Laffont
Pharo Smalltalk Screencasts: http://www.pharocasts.com/
Blog: http://magaloma.blogspot.com/
Nov. 28, 2010
[Pharo-project] Professor Position at the University of Chile
by Alexandre Bergel
Dear Colleagues,
We have an open position at the University of Chile. Candidates need to hold a PhD in Computer Science. The wished areas are
- Computer Networks
- Large scale Data Mining, Machine Learning, Information Retrieval
- Computer Graphics and Scientific Computing
- Computer Theory: algoritms and parallelism
Some of you may be interested in it. The official call may be found below.
Mail me directly for additional information.
Cheers,
Alexandre
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Department of Computer Science
Faculty of Physics and Mathematics
University of Chile
FACULTY POSITION
www.dcc.uchile.cl
The Department of Computer Science at the University of Chile invites
applications for a full-time position in Computer Science. We are seeking
applicants with strong commitment to undergraduate and graduate teaching
and research in one of the following areas at international standards:
- Computer Networks
- Large scale Data Mining, Machine Learning, Information Retrieval
- Computer Graphics and Scientific Computing
- Computer Theory: algoritms and paralelism
A PhD in Computer Science is required. Candidates should have proven
research abilities, backed by top-level publications in their area of
expertise, and be fluent in English.
Teaching will be conducted in Spanish, so candidates are expected to be
fluent or willing to become fluent in Spanish within a year. Teaching
experience is desirable as well.
Applications should include: a cover letter containing a research, teaching,
and service statement; curriculum vitae; PhD diploma or certificate;
copies of the 5 most relevant publications ranked by importance; and two
confidential letters of recommendation. They should be sent directly to the
address below.
Applications can be submitted any time before January 15, 2011.
Rank and salary (in Chilean pesos) will depend on academic background and
experience, and will follow the academic standards of the University of
Chile.
For further information please contact: concurso(a)dcc.uchile.cl, phone
(+56-2) 9780652
Send applications and accompanying information to the next e-mail and
following address:
DirecciÃn AcadÃmica y de InvestigaciÃn
Facultad de Ciencias FÃsicas y Matem·ticas
Universidad de Chile
Beauchef 850, Torre Central, 7mo piso
Casilla 2777
Santiago
Chile
sediraca(a)ing.uchile.cl
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Nov. 27, 2010
Re: [Pharo-project] Issue 3350 in pharo: Network Tests
by pharo@googlecode.com
Comment #1 on issue 3350 by stephane.ducasse: Network Tests
http://code.google.com/p/pharo/issues/detail?id=3350
Two more SocketTests.
=============== Diff against NetworkTests-ar.21 ===============
Item was added:
+ ----- Method: SocketTest>>testDataReceive (in category 'tests') -----
+ testDataReceive
+ "Test data transfer and related methods"
+
+ self testDataSending.
+ "It can take a tad for the status change to be visible"
+ (Delay forMilliseconds: 200) wait.
+ self assert: serverSocket dataAvailable.
+ self assert: (serverSocket receiveData = 'Hello World').
+ self deny: (serverSocket dataAvailable).
+ !
Item was added:
+ ----- Method: SocketTest>>testDataSending (in category 'tests') -----
+ testDataSending
+ "Test data transfer and related methods"
+
+ self testServerAccept.
+ clientSocket sendData: 'Hello World'.
+ clientSocket waitForSendDoneFor: 2.
+ self assert: clientSocket sendDone.
+
Nov. 27, 2010
[Pharo-project] Issue 3350 in pharo: Network Tests
by pharo@googlecode.com
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]
!
Nov. 27, 2010
Re: [Pharo-project] PipeableOSProcess #close
by David T. Lewis
On Sat, Nov 27, 2010 at 12:33:55PM -0500, Schwab,Wilhelm K wrote:
> Dave,
>
> I'm starting to see the dilemma. One thing that might help is a super-sending #close in PipeableOSProcess that is mostly comment on how to choose wisely?
Good idea, I think that will help. Thanks!
Dave
Nov. 27, 2010
Re: [Pharo-project] Issue 3349 in pharo: Some network fixes
by pharo@googlecode.com
Comment #1 on issue 3349 by stephane.ducasse: Some network fixes
http://code.google.com/p/pharo/issues/detail?id=3349
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]
!
Nov. 27, 2010
[Pharo-project] Issue 3349 in pharo: Some network fixes
by pharo@googlecode.com
Status: FixedWaitingToBePharoed
Owner: stephane.ducasse
Labels: Milestone-1.3 Type-Squeak
New issue 3349 by stephane.ducasse: Some network fixes
http://code.google.com/p/pharo/issues/detail?id=3349
Levente Uzonyi uploaded a new version of Network to project The Trunk:
http://source.squeak.org/trunk/Network-ul.99.mcz
==================== Summary ====================
Name: Network-ul.99
Author: ul
Time: 25 November 2010, 11:25:58.723 pm
UUID: 26c053e2-d198-0144-a3c9-c8181481e3da
Ancestors: Network-ar.98
- fixed clock rollover issues (http://bugs.squeak.org/view.php?id=7343
http://bugs.squeak.org/view.php?id=6857 )
- replaced #waitForConnectionUntil: sends to #waitForConnectionFor: sends
in SocksSocket
- simplified a few methods (some are from Pharo)
=============== Diff against Network-ar.98 ===============
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 := [socket waitForAcceptFor: 10]
- on: ConnectionTimedOut
- do: [nil].
(newConnection notNil and: [newConnection isConnected])
ifTrue: [
accessSema critical: [connections addLast:
newConnection.].
newConnection := nil.
self changed].
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 waitForConnectionFor: 10]
- on: ConnectionTimedOut
- do: [:ex |
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].
!
Item was changed:
----- Method: Socket class>>deadlineSecs: (in category 'utilities') -----
deadlineSecs: secs
"Return a deadline time the given number of seconds from now."
+ self deprecated: 'Using this method may result in clock rollover
related bug. Don''t use it.'.
^ Time millisecondClockValue + (secs * 1000) truncated
!
Item was changed:
----- Method: Socket class>>ping: (in category 'utilities') -----
ping: hostName
"Ping the given host. Useful for checking network connectivity. The
host must be running a TCP echo server."
"Socket ping: 'squeak.cs.uiuc.edu'"
| tcpPort sock serverAddr startTime echoTime |
tcpPort := 7. "7 = echo port, 13 = time port, 19 = character
generator port"
serverAddr := NetNameResolver addressForName: hostName timeout: 10.
+ serverAddr ifNil: [ ^self inform: 'Could not find an address for ',
hostName ].
- serverAddr = nil ifTrue: [
- ^ self inform: 'Could not find an address for ', hostName].
sock := Socket new.
sock connectNonBlockingTo: serverAddr port: tcpPort.
[sock waitForConnectionFor: 10]
on: ConnectionTimedOut
do: [:ex |
(self confirm: 'Continue to wait for connection
to ', hostName, '?')
ifTrue: [ex retry]
ifFalse: [
sock destroy.
^ self]].
sock sendData: 'echo!!'.
startTime := Time millisecondClockValue.
[sock waitForDataFor: 15]
on: ConnectionTimedOut
do: [:ex | (self confirm: 'Packet sent but no echo yet; keep
waiting?')
ifTrue: [ex retry]].
echoTime := Time millisecondClockValue - startTime.
sock destroy.
self inform: hostName, ' responded in ', echoTime printString, '
milliseconds'.
!
Item was changed:
----- Method: Socket class>>pingPorts:on:timeOutSecs: (in
category 'utilities') -----
pingPorts: portList on: hostName timeOutSecs: timeOutSecs
"Attempt to connect to each of the given sockets on the given host.
Wait at most timeOutSecs for the connections to be established. Answer an
array of strings indicating the available ports."
- "Socket pingPorts: #(7 13 19 21 23 25 80 110 119)
on: 'squeak.cs.uiuc.edu' timeOutSecs: 15"
+ "Socket pingPorts: #(7 13 19 21 23 25 80 110 119) on: 'squeak.org'
timeOutSecs: 15"
- | serverAddr sockets deadline done result unconnectedCount
connectedCount waitingCount |
- serverAddr := NetNameResolver addressForName: hostName timeout: 10.
- serverAddr = nil ifTrue: [
- self inform: 'Could not find an address for ', hostName.
- ^ #()].
+ | serverAddr sockets startTime timeoutMsecs done result
unconnectedCount connectedCount waitingCount |
+ serverAddr := NetNameResolver addressForName: hostName timeout: 10.
+ serverAddr ifNil: [
+ self inform: 'Could not find an address for ' ,
hostName.
+ ^ #() ].
+ sockets := portList
+ collect: [ :portNum |
+ | sock |
+ sock := Socket new.
+ [ sock connectTo: serverAddr port: portNum ]
+ on: ConnectionTimedOut
+ do: [ ].
+ sock ].
+ startTime := Time millisecondClockValue.
+ timeoutMsecs := (1000 * timeOutSecs) truncated.
- sockets := portList collect: [:portNum | | sock |
- sock := Socket new.
- sock connectTo: serverAddr port: portNum].
-
- deadline := self deadlineSecs: timeOutSecs.
done := false.
+ [ done ]
+ whileFalse: [
+ unconnectedCount := 0.
+ connectedCount := 0.
+ waitingCount := 0.
+ sockets
+ do: [ :s |
+ s isUnconnectedOrInvalid
+ ifTrue: [
unconnectedCount := unconnectedCount + 1 ]
+ ifFalse: [
+ s isConnected
+ ifTrue: [
connectedCount := connectedCount + 1 ].
+ s
isWaitingForConnection
+ ifTrue: [
waitingCount := waitingCount + 1 ] ] ].
+ waitingCount = 0
+ ifTrue: [ done := true ].
+ connectedCount = sockets size
+ ifTrue: [ done := true ].
+ (Time millisecondsSince: startTime) >= timeoutMsecs
+ ifTrue: [ done := true ] ].
+ result := (sockets select: [ :s | s isConnected ]) collect: [ :s |
self nameForWellKnownTCPPort: s remotePort ].
+ sockets do: [ :s | s destroy ].
+ ^ result!
- [done] whileFalse: [
- unconnectedCount := 0.
- connectedCount := 0.
- waitingCount := 0.
- sockets do: [:s |
- s isUnconnectedOrInvalid
- ifTrue: [unconnectedCount :=
unconnectedCount + 1]
- ifFalse: [
- s isConnected ifTrue:
[connectedCount := connectedCount + 1].
- s isWaitingForConnection ifTrue:
[waitingCount := waitingCount + 1]]].
- waitingCount = 0 ifTrue: [done := true].
- connectedCount = sockets size ifTrue: [done := true].
- Time millisecondClockValue > deadline ifTrue: [done :=
true]].
-
- result := (sockets select: [:s | s isConnected])
- collect: [:s | self nameForWellKnownTCPPort: s remotePort].
- sockets do: [:s | s destroy].
- ^ result
- !
Item was changed:
----- Method: Socket>>acceptFrom: (in category 'initialize-destroy') -----
acceptFrom: aSocket
"Initialize a new socket handle from an accept call"
| semaIndex readSemaIndex writeSemaIndex |
primitiveOnlySupportsOneSemaphore := false.
semaphore := Semaphore new.
readSemaphore := Semaphore new.
writeSemaphore := Semaphore new.
semaIndex := Smalltalk registerExternalObject: semaphore.
readSemaIndex := Smalltalk registerExternalObject: readSemaphore.
writeSemaIndex := Smalltalk registerExternalObject: writeSemaphore.
socketHandle := self primAcceptFrom: aSocket socketHandle
receiveBufferSize: 8000
sendBufSize: 8000
semaIndex: semaIndex
readSemaIndex: readSemaIndex
writeSemaIndex:
writeSemaIndex.
+ socketHandle
+ ifNotNil: [ self register ]
+ ifNil: [ "socket creation failed"
+ Smalltalk unregisterExternalObject: semaphore.
+ Smalltalk unregisterExternalObject: readSemaphore.
+ Smalltalk unregisterExternalObject: writeSemaphore.
+ readSemaphore := writeSemaphore := semaphore := nil
]
- socketHandle = nil ifTrue: [ "socket creation failed"
- Smalltalk unregisterExternalObject: semaphore.
- Smalltalk unregisterExternalObject: readSemaphore.
- Smalltalk unregisterExternalObject: writeSemaphore.
- readSemaphore := writeSemaphore := semaphore := nil
- ] ifFalse:[self register].
!
Item was changed:
----- Method: Socket>>destroy (in category 'initialize-destroy') -----
destroy
"Destroy this socket. Its connection, if any, is aborted and its
resources are freed. Do nothing if the socket has already been destroyed
(i.e., if its socketHandle is nil)."
+ socketHandle ifNotNil: [
+ self isValid ifTrue: [ self primSocketDestroy: socketHandle
].
- socketHandle = nil ifFalse:
- [self isValid ifTrue: [self primSocketDestroy:
socketHandle].
Smalltalk unregisterExternalObject: semaphore.
Smalltalk unregisterExternalObject: readSemaphore.
Smalltalk unregisterExternalObject: writeSemaphore.
socketHandle := nil.
readSemaphore := writeSemaphore := semaphore := nil.
+ self unregister ]!
- self unregister].
- !
Item was changed:
----- Method: Socket>>initialize: (in category 'initialize-destroy') -----
initialize: socketType
"Initialize a new socket handle. If socket creation fails,
socketHandle will be set to nil."
| semaIndex readSemaIndex writeSemaIndex |
primitiveOnlySupportsOneSemaphore := false.
semaphore := Semaphore new.
readSemaphore := Semaphore new.
writeSemaphore := Semaphore new.
semaIndex := Smalltalk registerExternalObject: semaphore.
readSemaIndex := Smalltalk registerExternalObject: readSemaphore.
writeSemaIndex := Smalltalk registerExternalObject: writeSemaphore.
socketHandle :=
self primSocketCreateNetwork: 0
type: socketType
receiveBufferSize: 8000
sendBufSize: 8000
semaIndex: semaIndex
readSemaIndex: readSemaIndex
writeSemaIndex: writeSemaIndex.
+ socketHandle
+ ifNotNil: [ self register ]
+ ifNil: [ "socket creation failed"
+ Smalltalk unregisterExternalObject: semaphore.
+ Smalltalk unregisterExternalObject: readSemaphore.
+ Smalltalk unregisterExternalObject: writeSemaphore.
+ readSemaphore := writeSemaphore := semaphore := nil
]
- socketHandle = nil ifTrue: [ "socket creation failed"
- Smalltalk unregisterExternalObject: semaphore.
- Smalltalk unregisterExternalObject: readSemaphore.
- Smalltalk unregisterExternalObject: writeSemaphore.
- readSemaphore := writeSemaphore := semaphore := nil
- ] ifFalse:[self register].
!
Nov. 27, 2010
Re: [Pharo-project] PipeableOSProcess #close
by Schwab,Wilhelm K
Dave,
I'm starting to see the dilemma. One thing that might help is a super-sending #close in PipeableOSProcess that is mostly comment on how to choose wisely?
Thanks!
Bill
Nov. 27, 2010