Fix problem with socket input stream on MacOS when reading from tty.

This could cause an empty buffer to be added to an internal BufferList
which violates our assumptions.

R=sgjesse@google.com
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com//9348050

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4027 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
ager@google.com
2012-02-08 10:51:58 +00:00
parent 0a0ac113cc
commit 4bb47cafcd
+7 -1
View File
@@ -19,7 +19,13 @@ class _SocketInputStream implements SocketInputStream {
}
ByteArray buffer = new ByteArray(bytesToRead);
int bytesRead = _socket.readList(buffer, 0, bytesToRead);
if (bytesRead < bytesToRead) {
if (bytesRead == 0) {
// On MacOS when reading from a tty Ctrl-D will result in one
// byte reported as available. Attempting to read it out will
// result in zero bytes read. When that happens there is no data
// which is indicated by a null return value.
return null;
} else if (bytesRead < bytesToRead) {
ByteArray newBuffer = new ByteArray(bytesRead);
newBuffer.setRange(0, bytesRead, buffer);
return newBuffer;