Polling sockets

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Polling sockets

Santiago Bragagnolo
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.

Maybe i need to spawn a process per socket?


Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Polling sockets

Sven Van Caekenberghe-2
On 05 Oct 2012, at 12:47, Santiago Bragagnolo <[hidden email]> 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.

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


Reply | Threaded
Open this post in threaded view
|

Re: Polling sockets

David T. Lewis
In reply to this post by Santiago Bragagnolo
On Fri, Oct 05, 2012 at 12:47:55PM +0200, Santiago Bragagnolo 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.
>
> Maybe i need to spawn a process per socket?
>

See AioEventHandlerExample and AioEventHandlerTestCase in OSProcess. The
primitives are in AioPlugin (http://www.squeaksource.com/AioPlugin/), which
connects to the low level select() implementation that Ian Piumarta developed
for the unix VMs. I think that this works on Mac and on Cog VMs also if
the plugin is provided (but it will not work on Windows).

Note that the socket that you use in the image may already be using select()
to respond to incoming data.

HTH,
Dave


Reply | Threaded
Open this post in threaded view
|

Re: Polling sockets

Mariano Martinez Peck
In reply to this post by Sven Van Caekenberghe-2


On Fri, Oct 5, 2012 at 12:59 PM, Sven Van Caekenberghe <[hidden email]> wrote:
On 05 Oct 2012, at 12:47, Santiago Bragagnolo <[hidden email]> 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