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

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

Issue 16123036: Clean up dart:io exceptions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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/secure_socket.h ('k') | runtime/bin/stdio_patch.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 patch class RawServerSocket { 5 patch class RawServerSocket {
6 /* patch */ static Future<RawServerSocket> bind(address, 6 /* patch */ static Future<RawServerSocket> bind(address,
7 int port, 7 int port,
8 {int backlog: 0, 8 {int backlog: 0,
9 bool v6Only: false}) { 9 bool v6Only: false}) {
10 return _RawServerSocket.bind(address, port, backlog, v6Only); 10 return _RawServerSocket.bind(address, port, backlog, v6Only);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 }); 230 });
231 }) 231 })
232 .then((address) { 232 .then((address) {
233 var socket = new _NativeSocket.listen(); 233 var socket = new _NativeSocket.listen();
234 socket.address = address; 234 socket.address = address;
235 var result = socket.nativeCreateBindListen(address._sockaddr_storage, 235 var result = socket.nativeCreateBindListen(address._sockaddr_storage,
236 port, 236 port,
237 backlog, 237 backlog,
238 v6Only); 238 v6Only);
239 if (result is OSError) { 239 if (result is OSError) {
240 throw new SocketIOException( 240 throw new SocketException(
241 "Failed to create server socket", result); 241 "Failed to create server socket", result);
242 } 242 }
243 if (port != 0) socket.localPort = port; 243 if (port != 0) socket.localPort = port;
244 return socket; 244 return socket;
245 }); 245 });
246 } 246 }
247 247
248 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET { 248 _NativeSocket.normal() : typeFlags = TYPE_NORMAL_SOCKET {
249 eventHandlers = new List(EVENT_COUNT + 1); 249 eventHandlers = new List(EVENT_COUNT + 1);
250 _EventHandler._start(); 250 _EventHandler._start();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 // Check whether this is an error response from a native port call. 484 // Check whether this is an error response from a native port call.
485 static bool isErrorResponse(response) { 485 static bool isErrorResponse(response) {
486 return response is List && response[0] != _SUCCESS_RESPONSE; 486 return response is List && response[0] != _SUCCESS_RESPONSE;
487 } 487 }
488 488
489 // Create the appropriate error/exception from different returned 489 // Create the appropriate error/exception from different returned
490 // error objects. 490 // error objects.
491 static createError(error, String message) { 491 static createError(error, String message) {
492 if (error is OSError) { 492 if (error is OSError) {
493 return new SocketIOException(message, error); 493 return new SocketException(message, error);
494 } else if (error is List) { 494 } else if (error is List) {
495 assert(isErrorResponse(error)); 495 assert(isErrorResponse(error));
496 switch (error[0]) { 496 switch (error[0]) {
497 case _ILLEGAL_ARGUMENT_RESPONSE: 497 case _ILLEGAL_ARGUMENT_RESPONSE:
498 return new ArgumentError(); 498 return new ArgumentError();
499 case _OSERROR_RESPONSE: 499 case _OSERROR_RESPONSE:
500 return new SocketIOException( 500 return new SocketException(
501 message, new OSError(error[2], error[1])); 501 message, new OSError(error[2], error[1]));
502 default: 502 default:
503 return new Exception("Unknown error"); 503 return new Exception("Unknown error");
504 } 504 }
505 } else { 505 } else {
506 return new SocketIOException(message); 506 return new SocketException(message);
507 } 507 }
508 } 508 }
509 509
510 void reportError(error, String message) { 510 void reportError(error, String message) {
511 var e = createError(error, message); 511 var e = createError(error, message);
512 // Invoke the error handler if any. 512 // Invoke the error handler if any.
513 if (eventHandlers[ERROR_EVENT] != null) { 513 if (eventHandlers[ERROR_EVENT] != null) {
514 eventHandlers[ERROR_EVENT](e); 514 eventHandlers[ERROR_EVENT](e);
515 } 515 }
516 // For all errors we close the socket 516 // For all errors we close the socket
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 if (_detachReady != null) { 1065 if (_detachReady != null) {
1066 _detachReady.complete(null); 1066 _detachReady.complete(null);
1067 } else { 1067 } else {
1068 if (_raw != null) { 1068 if (_raw != null) {
1069 _raw.shutdown(SocketDirection.SEND); 1069 _raw.shutdown(SocketDirection.SEND);
1070 _disableWriteEvent(); 1070 _disableWriteEvent();
1071 } 1071 }
1072 } 1072 }
1073 } 1073 }
1074 } 1074 }
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket.h ('k') | runtime/bin/stdio_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698