www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - SocketStream exceptions and disconnect handling

--001517590042a9808f04baaa77b6
Content-Type: text/plain; charset=UTF-8

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

--001517590042a9808f04baaa77b6
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hi all,<div><br></div><div>I&#39;m trying to handle disconnections transpar=
ently on SocketStream. I thought something like this:</div><div><br></div><=
div>void send(ubyte[] buffer)=C2=A0in { assert(buffer.length &gt; 0); }</di=
v>

<div>body {</div><div>=C2=A0 =C2=A0 if (!stream.isAlive) connect();</div><d=
iv>=C2=A0 =C2=A0 auto sent =3D stream.write(buffer);</div><div>=C2=A0 =C2=
=A0 if (sent =3D=3D 0)</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 throw new Exce=
ption(&quot;Error while writing&quot;);</div><div>}<br clear=3D"all">

<div><br></div><div>But that&#39;s impossible because isAlive doesn&#39;t e=
xists for SocketStream and I can&#39;t get the underlying socket object. Is=
 that something missing or should I handle it differently?</div><div><br>

</div>Pedro Lacerda<br><br>
</div>

--001517590042a9808f04baaa77b6--
Mar 07 2012