www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SocketStream exceptions and disconnect handling

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
Mar 07 2012