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

Side by Side Diff: runtime/bin/socket_impl.dart

Issue 10173024: Change the error handling in dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket.dart ('k') | runtime/bin/socket_stream_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 5
6 class _SocketBase { 6 class _SocketBase {
7 // Bit flags used when communicating between the eventhandler and 7 // Bit flags used when communicating between the eventhandler and
8 // dart code. The EVENT flags are used to indicate events of 8 // dart code. The EVENT flags are used to indicate events of
9 // interest when sending a message from dart code to the 9 // interest when sending a message from dart code to the
10 // eventhandler. When receiving a message from the eventhandler the 10 // eventhandler. When receiving a message from the eventhandler the
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 _handler.close(); 92 _handler.close();
93 _handler = null; 93 _handler = null;
94 } else { 94 } else {
95 _activateHandlers(); 95 _activateHandlers();
96 } 96 }
97 } 97 }
98 98
99 OSError _getError() native "Socket_GetError"; 99 OSError _getError() native "Socket_GetError";
100 int _getPort() native "Socket_GetPort"; 100 int _getPort() native "Socket_GetPort";
101 101
102 void set onError(void callback(Exception e)) { 102 void set onError(void callback(e)) {
103 _setHandler(_ERROR_EVENT, callback); 103 _setHandler(_ERROR_EVENT, callback);
104 } 104 }
105 105
106 void _activateHandlers() { 106 void _activateHandlers() {
107 if (_canActivateHandlers && (_id >= 0)) { 107 if (_canActivateHandlers && (_id >= 0)) {
108 if (_handlerMask == 0) { 108 if (_handlerMask == 0) {
109 if (_handler != null) { 109 if (_handler != null) {
110 _handler.close(); 110 _handler.close();
111 _handler = null; 111 _handler = null;
112 } 112 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 if (_handler === null) { 181 if (_handler === null) {
182 _handler = new ReceivePort(); 182 _handler = new ReceivePort();
183 _handler.receive((var message, ignored) { _multiplex(message); }); 183 _handler.receive((var message, ignored) { _multiplex(message); });
184 } 184 }
185 assert(_id >= 0); 185 assert(_id >= 0);
186 _EventHandler._sendData(_id, _handler, data); 186 _EventHandler._sendData(_id, _handler, data);
187 } 187 }
188 188
189 bool _reportError(error, String message) { 189 bool _reportError(error, String message) {
190 void doReportError(Exception e) { 190 void doReportError(Exception e) {
191 // Invoke the error callback if any. 191 // Invoke the socket error callback if any.
192 bool reported = false;
192 if (_handlerMap[_ERROR_EVENT] != null) { 193 if (_handlerMap[_ERROR_EVENT] != null) {
193 _handlerMap[_ERROR_EVENT](e); 194 _handlerMap[_ERROR_EVENT](e);
195 reported = true;
194 } 196 }
195 // Propagate the error to any additional listeners. 197 // Propagate the error to any additional listeners.
196 _propagateError(e); 198 reported = reported || _propagateError(e);
199 if (!reported) throw e;
197 } 200 }
198 201
199 // For all errors we close the socket, call the error handler and 202 // For all errors we close the socket, call the error handler and
200 // disable further calls of the error handler. 203 // disable further calls of the error handler.
201 close(); 204 close();
202 if (error is OSError) { 205 if (error is OSError) {
203 doReportError(new SocketIOException(message, error)); 206 doReportError(new SocketIOException(message, error));
204 } else if (error is List) { 207 } else if (error is List) {
205 assert(_isErrorResponse(error)); 208 assert(_isErrorResponse(error));
206 switch (error[0]) { 209 switch (error[0]) {
207 case _FileUtils.kIllegalArgumentResponse: 210 case _FileUtils.kIllegalArgumentResponse:
208 doReportError(new IllegalArgumentException()); 211 doReportError(new IllegalArgumentException());
209 break; 212 break;
210 case _FileUtils.kOSErrorResponse: 213 case _FileUtils.kOSErrorResponse:
211 doReportError(new SocketIOException( 214 doReportError(new SocketIOException(
212 message, new OSError(error[2], error[1]))); 215 message, new OSError(error[2], error[1])));
213 break; 216 break;
214 default: 217 default:
215 doReportError(new Exception("Unknown error")); 218 doReportError(new Exception("Unknown error"));
216 break; 219 break;
217 } 220 }
218 } else { 221 } else {
219 doReportError(new SocketIOException(message)); 222 doReportError(new SocketIOException(message));
220 } 223 }
221 } 224 }
222 225
223 int hashCode() => _hashCode; 226 int hashCode() => _hashCode;
224 227
225 void _propagateError(Exception e) => null; 228 bool _propagateError(Exception e) => null;
226 229
227 abstract bool _isListenSocket(); 230 abstract bool _isListenSocket();
228 abstract bool _isPipe(); 231 abstract bool _isPipe();
229 232
230 // Socket id is set from native. -1 indicates that the socket was closed. 233 // Socket id is set from native. -1 indicates that the socket was closed.
231 int _id; 234 int _id;
232 235
233 // Dedicated ReceivePort for socket events. 236 // Dedicated ReceivePort for socket events.
234 ReceivePort _handler; 237 ReceivePort _handler;
235 238
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 512 }
510 513
511 void set _onData(void callback()) { 514 void set _onData(void callback()) {
512 _setHandler(_SocketBase._IN_EVENT, callback); 515 _setHandler(_SocketBase._IN_EVENT, callback);
513 } 516 }
514 517
515 void set _onClosed(void callback()) { 518 void set _onClosed(void callback()) {
516 _setHandler(_SocketBase._CLOSE_EVENT, callback); 519 _setHandler(_SocketBase._CLOSE_EVENT, callback);
517 } 520 }
518 521
519 void _propagateError(Exception e) { 522 bool _propagateError(Exception e) {
523 bool reported = false;
520 if (_inputStream != null) { 524 if (_inputStream != null) {
521 _inputStream._onError(e); 525 reported = reported || _inputStream._onSocketError(e);
522 } 526 }
523 if (_outputStream != null) { 527 if (_outputStream != null) {
524 _outputStream._onError(e); 528 reported = reported || _outputStream._onSocketError(e);
525 } 529 }
530 return reported;
526 } 531 }
527 532
528 void _updateOutHandler() { 533 void _updateOutHandler() {
529 void firstWriteHandler() { 534 void firstWriteHandler() {
530 assert(!_seenFirstOutEvent); 535 assert(!_seenFirstOutEvent);
531 _seenFirstOutEvent = true; 536 _seenFirstOutEvent = true;
532 537
533 // From now on the write handler is only the client write 538 // From now on the write handler is only the client write
534 // handler (connect handler cannot be called again). Change this 539 // handler (connect handler cannot be called again). Change this
535 // before calling any handlers as handlers can change the 540 // before calling any handlers as handlers can change the
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 bool _seenFirstOutEvent = false; 589 bool _seenFirstOutEvent = false;
585 bool _pipe = false; 590 bool _pipe = false;
586 Function _clientConnectHandler; 591 Function _clientConnectHandler;
587 Function _clientWriteHandler; 592 Function _clientWriteHandler;
588 SocketInputStream _inputStream; 593 SocketInputStream _inputStream;
589 SocketOutputStream _outputStream; 594 SocketOutputStream _outputStream;
590 String _remoteHost; 595 String _remoteHost;
591 int _remotePort; 596 int _remotePort;
592 static SendPort _socketService; 597 static SendPort _socketService;
593 } 598 }
OLDNEW
« no previous file with comments | « runtime/bin/socket.dart ('k') | runtime/bin/socket_stream_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698