/* this method now throws exception if we don't get full read */
protected int readSock(BufferedTcpClient s, byte[] b)
{
int got = 0;
int len = b.Length;
int i;
Stream st = null;
lock (this)
{
if (s == null)
{
throw new IOException("expected " + len + " bytes, socket was closed");
}
st = s.GetInputStream();
}
while (got < len)
{
try
{
i = st.Read(b, got, len - got);
}
catch (IOException e)
{
throw new IOException(e.Message);
}
catch (ObjectDisposedException e)
{
throw new IOException(e.Message);
}
if (i < 0)
{
throw new IOException("expected " + len + " bytes, got EOF after " + got + " bytes");
}
else if (i == 0 && len != 0)
{
/*
* This is a corner case. According to
* http://java.sun.com/j2se/1.4.2/docs/api/ class InputStream
* is.read(,,l) can only return 0 if l==0. In other words it
* should not happen, but apparently did.
*/
throw new IOException("Remote connection closed");
}
else
{
got += i;
}
}
return got;
}