Index: sdk/lib/io/socket_stream_impl.dart |
diff --git a/sdk/lib/io/socket_stream_impl.dart b/sdk/lib/io/socket_stream_impl.dart |
index ffa0cbf0579361201a36e6caa42ca845b76210de..d3ea1409c20b4dbbb7e0fc5f2daa9a502e36afba 100644 |
--- a/sdk/lib/io/socket_stream_impl.dart |
+++ b/sdk/lib/io/socket_stream_impl.dart |
@@ -58,6 +58,7 @@ class _SocketInputStream implements InputStream { |
bool _onSocketError(e) { |
close(); |
+ if (_error) return true; |
if (_onError != null) { |
_onError(e); |
return true; |
@@ -129,13 +130,34 @@ class _SocketOutputStream |
} |
bool _write(List<int> buffer, int offset, int len, bool copyBuffer) { |
- if (_closing || _closed) throw new StreamException("Stream closed"); |
+ if (_closing || _closed) { |
+ if (_error) return false; |
+ _error = true; |
+ var e = new StreamException.streamClosed(); |
+ if (_onError != null) { |
+ _onError(e); |
+ return false; |
+ } else { |
+ throw e; |
+ } |
+ } |
int bytesWritten = 0; |
if (_pendingWrites.isEmpty) { |
// If nothing is buffered write as much as possible and buffer |
// the rest. |
- bytesWritten = _socket.writeList(buffer, offset, len); |
- if (bytesWritten == len) return true; |
+ try { |
+ bytesWritten = _socket.writeList(buffer, offset, len); |
+ if (bytesWritten == len) return true; |
+ } catch (e) { |
+ if (_error) return false; |
+ _error = true; |
+ if (_onError != null) { |
+ _onError(e); |
+ return false; |
+ } else { |
+ throw e; |
+ } |
+ } |
} |
// Place remaining data on the pending writes queue. |
@@ -163,7 +185,7 @@ class _SocketOutputStream |
bytesWritten = _socket.writeList(buffer, offset, bytesToWrite); |
} catch (e) { |
_pendingWrites.clear(); |
- _onSocketError(e); |
+ if (_onError != null) _onError(e); |
return; |
} |
_pendingWrites.removeBytes(bytesWritten); |
@@ -206,4 +228,5 @@ class _SocketOutputStream |
Function _onClosed; |
bool _closing = false; |
bool _closed = false; |
+ bool _error = false; |
} |