Sven, Thanks for the code!
The fact that I have to decide what constitutes an "infinite" delay seems wrong to me. It should just do what I tell it and either calmly wait for an event to let the code move forward (assuming that only the calling thread is blocked). One example: if I know I typed an incorrect address, then any time is wasted. If it's correct and the connection is slow (I downloaded a pdf of a paper earlier this week, and it was miserably slow but worked fine), I probably want the code to keep running without trying to think for itself. "This looping improves liveliness and responsiveness to other events." Why does looping on things that should be blocking until events arrive improve response to other events? This seems like a bailing wire solution to the problem. Bill ________________________________________ From: [email protected] [[email protected]] On Behalf Of Sven Van Caekenberghe [[email protected]] Sent: Friday, January 14, 2011 9:36 AM To: [email protected] Subject: Re: [Pharo-project] Socket question (Was Re: Xtreams up to date) On 14 Jan 2011, at 12:54, Schwab,Wilhelm K wrote: I don't understand why this would bother you: it is the 'client/user' that decides about the timeout (you could use some very large number for an 'infinite' timeout). You need of course a loop around it. Here is the code from ZnSingleThreadedServer (which started from the Blackfoot example): listenLoop "We create a listening Socket, then wait for a connection. After each connection we also check that the listening Socket is still valid - if not we just make a recursive call to this method to start over." self initializeServerSocket. [ [ serverSocket isValid ifFalse: [ "will trigger #ifCurtailed: block and destroy socket" ^ self listenLoop ]. self serveConnectionOn: serverSocket ] repeat ] ifCurtailed: [ self releaseServerSocket ] serveConnectionOn: listeningSocket "We wait up to acceptWaitTimeout seconds for an incoming connection. If we get one we wrap it in a SocketStream and #executeOneRequestResponseOn: on it" | stream socket | socket := (listeningSocket waitForAcceptFor: self acceptWaitTimeout) ifNil: [ ^ self log: 'Wait for accept timed out' ]. stream := ZnNetworkingUtils socketStreamOn: socket. [ [ [ self executeOneRequestResponseOn: stream ] ensure: [ self log: 'Closing stream'. stream close ] ] ifCurtailed: [ self log: 'Destroying socket'. socket destroy ] ] forkAt: Processor highIOPriority named: 'Zinc HTTP Server Worker' Each #acceptWaitTimeout seconds, 'Wait for accept timed out' is printed on the log and another accept/wait starts. This looping improves liveliness and responsiveness to other events. Sven
