Handling socket timed out

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

Handling socket timed out

HilaireFernandes
Hi,

With this code, the ConnectionTimedOut exception is never handled:

| socket data |
socket := Socket newUDP.
socket setPort: 51284.
socket waitForDataFor: 5.
data := ByteArray new: 100.
[[socket receiveUDPDataInto: data]
     on: Error
     do: ['Catched error, closing socket' crLog. socket closeAndDestroy]]
     ensure: [ 'Closing socket' crLog. socket closeAndDestroy]

Any reason it does not work?

In Pharo I see several examples using ifCurtailed.

Hilaire

--
Dr. Geo
http://drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Handling socket timed out

Sven Van Caekenberghe-2


> On 24 May 2018, at 19:28, Hilaire <[hidden email]> wrote:
>
> Hi,
>
> With this code, the ConnectionTimedOut exception is never handled:
>
> | socket data |
> socket := Socket newUDP.
> socket setPort: 51284.
> socket waitForDataFor: 5.
> data := ByteArray new: 100.
> [[socket receiveUDPDataInto: data]
>     on: Error
>     do: ['Catched error, closing socket' crLog. socket closeAndDestroy]]
>     ensure: [ 'Closing socket' crLog. socket closeAndDestroy]
>
> Any reason it does not work?
>
> In Pharo I see several examples using ifCurtailed.
>
> Hilaire
>
> --
> Dr. Geo
> http://drgeo.eu

#receiveUDPDataInto: returns immediately, possibly with zero bytes read.
It is #waitForDataFor: that signals the ConnectionTimedOut.
Move that expression into the inner block.

Sven