On Fri, Oct 5, 2012 at 12:59 PM, Sven Van Caekenberghe <[email protected]> wrote:
> On 05 Oct 2012, at 12:47, Santiago Bragagnolo < > [email protected]> wrote: > > > Hi guys, theres something like the select or poll C functions in order > to wait for incoming-data from a set of sockets? I searched at the list and > in the pharo by example book without any success and i didn't find a method > named poll / select ( select in terms of sockets ) in the image. > > As far as I know there is no such primitive. It would be very nice to have > though, it is one of the building blocks to do asynchroneous IO. But this > is just one way to do polling. > > > Maybe i need to spawn a process per socket? > > > Indeed, this would be the classic way to do it: just do a blocking read > until ConnectionTimedOut and loop. > Yes, in DBXTalk we do more or less the same: processNextResultSet: aConnection querySettings: aQuerySettings "Gets the next resultSet of the query. Depending on the type of query, it will return a DBXResult or DBXResultSet. If there is a timeout, it will cicle till this is finished." | returnCode | [self nextResultSet: aConnection querySettings: aQuerySettings onReturn: [:handle :code | returnCode := code. code = OpenDBX resultWithRows ifTrue: [ ^ self processResultWithRows: aConnection resultHandle: handle querySettings: aQuerySettings]. code = OpenDBX resultWithoutRows ifTrue: [ ^ self processResultWithoutRows: aConnection resultHandle: handle querySettings: aQuerySettings]. code = OpenDBX resultDone ifTrue: [^ nil]. (code = OpenDBX resultTimeout) ifTrue: [ (Delay forMilliseconds: (aQuerySettings timeout asMiliseconds)) wait ]. ]] doWhileTrue: [returnCode = OpenDBX resultTimeout]. OpenDBXDriverError signal: 'Uknown problem with executeStatement'. > > You could experiment with #isDataAvailable and/or very short timeouts to > service more connections with one thread, but that won't be easy (you would > be at the mercy of the primitives with their subtle platform differences). > > -- > Sven Van Caekenberghe > http://stfx.eu > Smalltalk is the Red Pill > > > -- Mariano http://marianopeck.wordpress.com
