March 07, 2012
My english is bugged, I mean "handle reconnections transparently". Sorry.

Pedro Lacerda



2012/3/7 Pedro Lacerda <pslacerda@gmail.com>

> Hi all,
>
> I'm trying to handle disconnections transparently on SocketStream. I thought something like this:
>
> void send(ubyte[] buffer) in { assert(buffer.length > 0); }
> body {
>     if (!stream.isAlive) connect();
>     auto sent = stream.write(buffer);
>     if (sent == 0)
>         throw new Exception("Error while writing");
> }
>
> But that's impossible because isAlive doesn't exists for SocketStream and I can't get the underlying socket object. Is that something missing or should I handle it differently?
>
> Pedro Lacerda
>
>


March 07, 2012
On Wed, 07 Mar 2012 17:29:25 -0000, Pedro Lacerda <pslacerda@gmail.com> wrote:
> 2012/3/7 Pedro Lacerda <pslacerda@gmail.com>
>
>> Hi all,
>>
>> I'm trying to handle disconnections transparently on SocketStream. I
>> thought something like this:
>>
>> void send(ubyte[] buffer) in { assert(buffer.length > 0); }
>> body {
>>     if (!stream.isAlive) connect();
>>     auto sent = stream.write(buffer);
>>     if (sent == 0)
>>         throw new Exception("Error while writing");
>> }
>>
>> But that's impossible because isAlive doesn't exists for SocketStream and
>> I can't get the underlying socket object. Is that something missing or
>> should I handle it differently?

The underlying problem is that you cannot detect if a socket is still connected without trying to read (recv) or write (send) to it, it is only once you attempt an operation that it will report that it has been closed.  This is why isAlive wont/can't exist in any really useful way.  The underlying socket routines indicate closure by returning 0 bytes read/written.  So, the real Q here is how does socketstream (is it built on std.socket?) reflect this information to you?

Regan

-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/