We need to potentially decode the length after every read. The original
code did that due to eventuall getting out of the loop, the "fixed" code failed to do it if we failed to fill our buffer up on the first read. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2695 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: FramedInputStream.java,v 1.5 2003/07/07 22:35:38 eric Exp $
|
||||
// $Id: FramedInputStream.java,v 1.6 2003/07/09 05:13:34 mdb Exp $
|
||||
|
||||
package com.threerings.io;
|
||||
|
||||
@@ -91,6 +91,12 @@ public class FramedInputStream extends InputStream
|
||||
}
|
||||
_have += got;
|
||||
|
||||
if (_length == -1) {
|
||||
// if we didn't already have our length, see if we now
|
||||
// have enough data to obtain it
|
||||
_length = decodeLength();
|
||||
}
|
||||
|
||||
// if there's room remaining in the buffer, that means we've
|
||||
// read all there is to read, so we can move on to inspecting
|
||||
// what we've got
|
||||
@@ -98,6 +104,14 @@ public class FramedInputStream extends InputStream
|
||||
break;
|
||||
}
|
||||
|
||||
// additionally, if the buffer happened to be exactly as long
|
||||
// as we needed, we need to break as well
|
||||
if ((_length > 0) && (_have >= _length)) {
|
||||
System.err.println("Phew, we would have been screwed in " +
|
||||
"the previous release (" + _length + ").");
|
||||
break;
|
||||
}
|
||||
|
||||
// otherwise, we've filled up our buffer as a result of this
|
||||
// read, expand it and try reading some more
|
||||
ByteBuffer newbuf = ByteBuffer.allocate(_buffer.capacity() << 1);
|
||||
@@ -107,12 +121,6 @@ public class FramedInputStream extends InputStream
|
||||
// don't let things grow without bounds
|
||||
} while (_buffer.capacity() < MAX_BUFFER_CAPACITY);
|
||||
|
||||
// if we didn't already have our length, see if we now have enough
|
||||
// data to obtain it
|
||||
if (_length == -1) {
|
||||
_length = decodeLength();
|
||||
}
|
||||
|
||||
// finally check to see if there's a complete frame in the buffer
|
||||
// and prepare to serve it up if there is
|
||||
return checkForCompleteFrame();
|
||||
|
||||
Reference in New Issue
Block a user