| OLD | NEW |
| 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 bool shared: false}) { | 10 bool shared: false}) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 bool writeEventIssued = false; | 313 bool writeEventIssued = false; |
| 314 bool writeAvailable = false; | 314 bool writeAvailable = false; |
| 315 | 315 |
| 316 static bool connectedResourceHandler = false; | 316 static bool connectedResourceHandler = false; |
| 317 _ReadWriteResourceInfo resourceInfo; | 317 _ReadWriteResourceInfo resourceInfo; |
| 318 | 318 |
| 319 // The owner object is the object that the Socket is being used by, e.g. | 319 // The owner object is the object that the Socket is being used by, e.g. |
| 320 // a HttpServer, a WebSocket connection, a process pipe, etc. | 320 // a HttpServer, a WebSocket connection, a process pipe, etc. |
| 321 Object owner; | 321 Object owner; |
| 322 | 322 |
| 323 static double get timestamp => sw.elapsedMicroseconds / 1000000.0; | |
| 324 | |
| 325 static Future<List<InternetAddress>> lookup( | 323 static Future<List<InternetAddress>> lookup( |
| 326 String host, {InternetAddressType type: InternetAddressType.ANY}) { | 324 String host, {InternetAddressType type: InternetAddressType.ANY}) { |
| 327 return _IOService._dispatch(_SOCKET_LOOKUP, [host, type._value]) | 325 return _IOService._dispatch(_SOCKET_LOOKUP, [host, type._value]) |
| 328 .then((response) { | 326 .then((response) { |
| 329 if (isErrorResponse(response)) { | 327 if (isErrorResponse(response)) { |
| 330 throw createError(response, "Failed host lookup: '$host'"); | 328 throw createError(response, "Failed host lookup: '$host'"); |
| 331 } else { | 329 } else { |
| 332 return response.skip(1).map((result) { | 330 return response.skip(1).map((result) { |
| 333 var type = new InternetAddressType._from(result[0]); | 331 var type = new InternetAddressType._from(result[0]); |
| 334 return new _InternetAddress(result[1], host, result[2]); | 332 return new _InternetAddress(result[1], host, result[2]); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 if (sourceAddress is String) { | 378 if (sourceAddress is String) { |
| 381 sourceAddress = new InternetAddress(sourceAddress); | 379 sourceAddress = new InternetAddress(sourceAddress); |
| 382 } | 380 } |
| 383 } | 381 } |
| 384 return new Future.value(host) | 382 return new Future.value(host) |
| 385 .then((host) { | 383 .then((host) { |
| 386 if (host is _InternetAddress) return [host]; | 384 if (host is _InternetAddress) return [host]; |
| 387 return lookup(host) | 385 return lookup(host) |
| 388 .then((addresses) { | 386 .then((addresses) { |
| 389 if (addresses.isEmpty) { | 387 if (addresses.isEmpty) { |
| 390 throw createError(response, "Failed host lookup: '$host'"); | 388 throw createError(null, "Failed host lookup: '$host'"); |
| 391 } | 389 } |
| 392 return addresses; | 390 return addresses; |
| 393 }); | 391 }); |
| 394 }) | 392 }) |
| 395 .then((addresses) { | 393 .then((addresses) { |
| 396 assert(addresses is List); | 394 assert(addresses is List); |
| 397 var completer = new Completer(); | 395 var completer = new Completer(); |
| 398 var it = addresses.iterator; | 396 var it = addresses.iterator; |
| 399 var error = null; | 397 var error = null; |
| 400 var connecting = new HashMap(); | 398 var connecting = new HashMap(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 int port, | 468 int port, |
| 471 int backlog, | 469 int backlog, |
| 472 bool v6Only, | 470 bool v6Only, |
| 473 bool shared) { | 471 bool shared) { |
| 474 return new Future.value(host) | 472 return new Future.value(host) |
| 475 .then((host) { | 473 .then((host) { |
| 476 if (host is _InternetAddress) return host; | 474 if (host is _InternetAddress) return host; |
| 477 return lookup(host) | 475 return lookup(host) |
| 478 .then((list) { | 476 .then((list) { |
| 479 if (list.length == 0) { | 477 if (list.length == 0) { |
| 480 throw createError(response, "Failed host lookup: '$host'"); | 478 throw createError(null, "Failed host lookup: '$host'"); |
| 481 } | 479 } |
| 482 return list[0]; | 480 return list[0]; |
| 483 }); | 481 }); |
| 484 }) | 482 }) |
| 485 .then((address) { | 483 .then((address) { |
| 486 var socket = new _NativeSocket.listen(); | 484 var socket = new _NativeSocket.listen(); |
| 487 socket.localAddress = address; | 485 socket.localAddress = address; |
| 488 var result = socket.nativeCreateBindListen(address._in_addr, | 486 var result = socket.nativeCreateBindListen(address._in_addr, |
| 489 port, | 487 port, |
| 490 backlog, | 488 backlog, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 508 } | 506 } |
| 509 | 507 |
| 510 static Future<_NativeSocket> bindDatagram( | 508 static Future<_NativeSocket> bindDatagram( |
| 511 host, int port, bool reuseAddress) { | 509 host, int port, bool reuseAddress) { |
| 512 return new Future.value(host) | 510 return new Future.value(host) |
| 513 .then((host) { | 511 .then((host) { |
| 514 if (host is _InternetAddress) return host; | 512 if (host is _InternetAddress) return host; |
| 515 return lookup(host) | 513 return lookup(host) |
| 516 .then((list) { | 514 .then((list) { |
| 517 if (list.length == 0) { | 515 if (list.length == 0) { |
| 518 throw createError(response, "Failed host lookup: '$host'"); | 516 throw createError(null, "Failed host lookup: '$host'"); |
| 519 } | 517 } |
| 520 return list[0]; | 518 return list[0]; |
| 521 }); | 519 }); |
| 522 }) | 520 }) |
| 523 .then((address) { | 521 .then((address) { |
| 524 var socket = new _NativeSocket.datagram(address); | 522 var socket = new _NativeSocket.datagram(address); |
| 525 var result = socket.nativeCreateBindDatagram( | 523 var result = socket.nativeCreateBindDatagram( |
| 526 address._in_addr, port, reuseAddress); | 524 address._in_addr, port, reuseAddress); |
| 527 if (result is OSError) { | 525 if (result is OSError) { |
| 528 throw new SocketException("Failed to create datagram socket", | 526 throw new SocketException("Failed to create datagram socket", |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 } | 1700 } |
| 1703 | 1701 |
| 1704 | 1702 |
| 1705 patch class RawDatagramSocket { | 1703 patch class RawDatagramSocket { |
| 1706 /* patch */ static Future<RawDatagramSocket> bind( | 1704 /* patch */ static Future<RawDatagramSocket> bind( |
| 1707 host, int port, {bool reuseAddress: true}) { | 1705 host, int port, {bool reuseAddress: true}) { |
| 1708 return _RawDatagramSocket.bind(host, port, reuseAddress); | 1706 return _RawDatagramSocket.bind(host, port, reuseAddress); |
| 1709 } | 1707 } |
| 1710 } | 1708 } |
| 1711 | 1709 |
| 1712 class _RawDatagramSocket extends Stream implements RawDatagramSocket { | 1710 class _RawDatagramSocket extends Stream<RawSocketEvent> |
| 1711 implements RawDatagramSocket { |
| 1713 _NativeSocket _socket; | 1712 _NativeSocket _socket; |
| 1714 StreamController<RawSocketEvent> _controller; | 1713 StreamController<RawSocketEvent> _controller; |
| 1715 bool _readEventsEnabled = true; | 1714 bool _readEventsEnabled = true; |
| 1716 bool _writeEventsEnabled = true; | 1715 bool _writeEventsEnabled = true; |
| 1717 | 1716 |
| 1718 _RawDatagramSocket(this._socket) { | 1717 _RawDatagramSocket(this._socket) { |
| 1719 var zone = Zone.current; | 1718 var zone = Zone.current; |
| 1720 _controller = new StreamController(sync: true, | 1719 _controller = new StreamController(sync: true, |
| 1721 onListen: _onSubscriptionStateChange, | 1720 onListen: _onSubscriptionStateChange, |
| 1722 onCancel: _onSubscriptionStateChange, | 1721 onCancel: _onSubscriptionStateChange, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1846 Datagram _makeDatagram(List<int> data, | 1845 Datagram _makeDatagram(List<int> data, |
| 1847 String address, | 1846 String address, |
| 1848 List<int> in_addr, | 1847 List<int> in_addr, |
| 1849 int port) { | 1848 int port) { |
| 1850 return new Datagram( | 1849 return new Datagram( |
| 1851 data, | 1850 data, |
| 1852 new _InternetAddress(address, null, in_addr), | 1851 new _InternetAddress(address, null, in_addr), |
| 1853 port); | 1852 port); |
| 1854 } | 1853 } |
| 1855 | 1854 |
| OLD | NEW |