Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Unified Diff: runtime/bin/socket_stream_impl.dart

Issue 9812007: Add error handling to socket streams (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/stream_util.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/socket_stream_impl.dart
diff --git a/runtime/bin/socket_stream_impl.dart b/runtime/bin/socket_stream_impl.dart
index 678259db6f4e2d6bb6d237d1b096ac02a6a2ca7b..9789516a59ad98657a83bef9ce1f8182dbebdd1a 100644
--- a/runtime/bin/socket_stream_impl.dart
+++ b/runtime/bin/socket_stream_impl.dart
@@ -2,6 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+
class _SocketInputStream implements SocketInputStream {
_SocketInputStream(Socket socket) : _socket = socket {
if (_socket._id == -1) _closed = true;
@@ -66,10 +67,6 @@ class _SocketInputStream implements SocketInputStream {
_socket._onClosed = _onClosed;
}
- void set onError(void callback()) {
- _socket.onError = callback;
- }
-
void _onClosed() {
_closed = true;
if (_clientCloseHandler !== null) {
@@ -77,9 +74,19 @@ class _SocketInputStream implements SocketInputStream {
}
}
+ void set onError(void callback(Exception e)) {
+ _errorCallback = callback;
+ }
+
+ void _onError(Exception e) {
+ close();
+ if (_errorCallback != null) _errorCallback(e);
+ }
+
Socket _socket;
- Function _clientCloseHandler;
bool _closed = false;
+ Function _clientCloseHandler;
+ Function _errorCallback;
}
@@ -123,15 +130,6 @@ class _SocketOutputStream
}
}
- void set onError(void callback()) {
- _streamErrorHandler = callback;
- if (_streamErrorHandler != null) {
- _socket.onError = _onError;
- } else {
- _socket.onError = null;
- }
- }
-
bool _write(List<int> buffer, int offset, int len, bool copyBuffer) {
if (_closing || _closed) throw new StreamException("Stream closed");
int bytesWritten = 0;
@@ -180,15 +178,20 @@ class _SocketOutputStream
if (_onNoPendingWrites == null) _socket._onWrite = null;
}
- void _onError() {
+ void set onError(void callback(Exception e)) {
+ _errorCallback = callback;
+ }
+
+ void _onError(Exception e) {
close();
- if (_streamErrorHandler != null) _streamErrorHandler();
+ if (_errorCallback != null) _errorCallback(e);
}
Socket _socket;
_BufferList _pendingWrites;
var _onNoPendingWrites;
- var _streamErrorHandler;
+ Function _clientCloseHandler;
Mads Ager (google) 2012/03/21 13:18:20 Where is the _clientCloseHandler used? It doesn't
Søren Gjesse 2012/03/21 14:39:46 Thanks for spotting this copy/paste error. Removed
+ Function _errorCallback;
bool _closing = false;
bool _closed = false;
}
« no previous file with comments | « runtime/bin/socket_impl.dart ('k') | runtime/bin/stream_util.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698