> I tried using this to read into an array of length 0, but this just returns
0
> right away, so it is no good for us. The only thing left I can think of is
> to use a PushBackInputStream and read one byte and then bush it back when
it
> get's read. But, em, could it get any more annoying?
Can't do that. From Javadoc (jdk 1.2.2 on Win32):
If b is null, a NullPointerException is thrown. If the length of b is zero,
then no bytes are read and 0 is returned; otherwise, there is an attempt
to read at least one byte. If no byte is available because the stream is
at end of file, the value -1 is returned; otherwise, at least one byte is
read and stored into b.
> Could someone smarter then me please fix this (ConnectionHandler.java -
L56,
> we need some way to if the connection has been lost for some reason since
the
> stupid available() continues returning 0).
I've talked to some people, and it seems that available(), while fine for
other InputStreams, is wacky and fairly useless when called on a Socket's
InputStream.
Note, I have -not- looked at the section of code you mentioned.
try
{
incomingAvail = incoming.read(buf);
if (incomingAvail > 0)
{
// do something
}
}
catch (InterruptedIOException ioe)
{
// read failed on timeout
}
if (incomingAvail == -1)
{
throw new IOException("Connection closed.");
}
Set a fairly low timeout using setSoTimeout(), like 50ms, and this works
okay. Kludgey, maybe... but...
-cm
_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev