Fixed some bugs related to reading partial frames.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@165 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: FramedInputStream.java,v 1.4 2001/05/30 23:58:31 mdb Exp $
|
||||
// $Id: FramedInputStream.java,v 1.5 2001/08/03 03:10:15 mdb Exp $
|
||||
|
||||
package com.threerings.cocktail.cher.io;
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.io.InputStream;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.cocktail.cher.Log;
|
||||
|
||||
/**
|
||||
* The framed input stream reads input that was framed by a framing output
|
||||
* stream. Framing in this case simply means writing the length of the
|
||||
@@ -66,16 +68,13 @@ public class FramedInputStream extends InputStream
|
||||
// we're not halfway through reading a frame and that we can start
|
||||
// anew.
|
||||
if (_count == _length) {
|
||||
// clear out any prior data
|
||||
_pos = 0;
|
||||
_count = 0;
|
||||
|
||||
// read in the frame length
|
||||
int got = source.read(_header, 0, HEADER_SIZE);
|
||||
if (got < 0) {
|
||||
throw new EOFException();
|
||||
|
||||
} else if (got == 0) {
|
||||
Log.info("Woke up to read data, but there ain't none. Sigh.");
|
||||
return false;
|
||||
|
||||
} else if (got < HEADER_SIZE) {
|
||||
@@ -85,6 +84,11 @@ public class FramedInputStream extends InputStream
|
||||
throw new RuntimeException(errmsg);
|
||||
}
|
||||
|
||||
// now that we've read our new frame length, we can clear out
|
||||
// any prior data
|
||||
_pos = 0;
|
||||
_count = 0;
|
||||
|
||||
// decode the frame length
|
||||
_length = (_header[0] << 24) & 0xFF;
|
||||
_length += (_header[1] << 16) & 0xFF;
|
||||
@@ -99,7 +103,7 @@ public class FramedInputStream extends InputStream
|
||||
}
|
||||
|
||||
// read the data into the buffer
|
||||
int got = source.read(_buffer, _count, _length);
|
||||
int got = source.read(_buffer, _count, _length-_count);
|
||||
if (got < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user