| 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([String address = "127.0.0.1", | 6 /* patch */ static Future<RawServerSocket> bind([String address = "127.0.0.1", |
| 7 int port = 0, | 7 int port = 0, |
| 8 int backlog = 0]) { | 8 int backlog = 0]) { |
| 9 return _RawServerSocket.bind(address, port, backlog); | 9 return _RawServerSocket.bind(address, port, backlog); |
| 10 } | 10 } |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 _controller = new StreamController( | 434 _controller = new StreamController( |
| 435 onSubscriptionStateChange: _onSubscriptionStateChange, | 435 onSubscriptionStateChange: _onSubscriptionStateChange, |
| 436 onPauseStateChange: _onPauseStateChange); | 436 onPauseStateChange: _onPauseStateChange); |
| 437 _socket.closeFuture.then((_) => _controller.close()); | 437 _socket.closeFuture.then((_) => _controller.close()); |
| 438 _socket.setHandlers( | 438 _socket.setHandlers( |
| 439 read: () { | 439 read: () { |
| 440 var socket = _socket.accept(); | 440 var socket = _socket.accept(); |
| 441 if (socket != null) _controller.add(new _RawSocket(socket)); | 441 if (socket != null) _controller.add(new _RawSocket(socket)); |
| 442 }, | 442 }, |
| 443 error: (e) { | 443 error: (e) { |
| 444 _controller.addError(new AsyncError(e)); | 444 _controller.addError(e); |
| 445 _controller.close(); | 445 _controller.close(); |
| 446 } | 446 } |
| 447 ); | 447 ); |
| 448 } | 448 } |
| 449 | 449 |
| 450 StreamSubscription<RawSocket> listen(void onData(RawSocket event), | 450 StreamSubscription<RawSocket> listen(void onData(RawSocket event), |
| 451 {void onError(AsyncError error), | 451 {void onError(Object error), |
| 452 void onDone(), | 452 void onDone(), |
| 453 bool unsubscribeOnError}) { | 453 bool unsubscribeOnError}) { |
| 454 return _controller.stream.listen( | 454 return _controller.stream.listen( |
| 455 onData, | 455 onData, |
| 456 onError: onError, | 456 onError: onError, |
| 457 onDone: onDone, | 457 onDone: onDone, |
| 458 unsubscribeOnError: unsubscribeOnError); | 458 unsubscribeOnError: unsubscribeOnError); |
| 459 } | 459 } |
| 460 | 460 |
| 461 int get port => _socket.port; | 461 int get port => _socket.port; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 _socket.setHandlers( | 507 _socket.setHandlers( |
| 508 read: () => _controller.add(RawSocketEvent.READ), | 508 read: () => _controller.add(RawSocketEvent.READ), |
| 509 write: () { | 509 write: () { |
| 510 // The write event handler is automatically disabled by the | 510 // The write event handler is automatically disabled by the |
| 511 // event handler when it fires. | 511 // event handler when it fires. |
| 512 _writeEventsEnabled = false; | 512 _writeEventsEnabled = false; |
| 513 _controller.add(RawSocketEvent.WRITE); | 513 _controller.add(RawSocketEvent.WRITE); |
| 514 }, | 514 }, |
| 515 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), | 515 closed: () => _controller.add(RawSocketEvent.READ_CLOSED), |
| 516 error: (e) { | 516 error: (e) { |
| 517 _controller.addError(new AsyncError(e)); | 517 _controller.addError(e); |
| 518 close(); | 518 close(); |
| 519 } | 519 } |
| 520 ); | 520 ); |
| 521 } | 521 } |
| 522 | 522 |
| 523 factory _RawSocket._writePipe(int fd) { | 523 factory _RawSocket._writePipe(int fd) { |
| 524 var native = new _NativeSocket.pipe(); | 524 var native = new _NativeSocket.pipe(); |
| 525 native.isClosedRead = true; | 525 native.isClosedRead = true; |
| 526 if (fd != null) _getStdioHandle(native, fd); | 526 if (fd != null) _getStdioHandle(native, fd); |
| 527 return new _RawSocket(native); | 527 return new _RawSocket(native); |
| 528 } | 528 } |
| 529 | 529 |
| 530 factory _RawSocket._readPipe(int fd) { | 530 factory _RawSocket._readPipe(int fd) { |
| 531 var native = new _NativeSocket.pipe(); | 531 var native = new _NativeSocket.pipe(); |
| 532 native.isClosedWrite = true; | 532 native.isClosedWrite = true; |
| 533 if (fd != null) _getStdioHandle(native, fd); | 533 if (fd != null) _getStdioHandle(native, fd); |
| 534 return new _RawSocket(native); | 534 return new _RawSocket(native); |
| 535 } | 535 } |
| 536 | 536 |
| 537 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), | 537 StreamSubscription<RawSocketEvent> listen(void onData(RawSocketEvent event), |
| 538 {void onError(AsyncError error), | 538 {void onError(Object error), |
| 539 void onDone(), | 539 void onDone(), |
| 540 bool unsubscribeOnError}) { | 540 bool unsubscribeOnError}) { |
| 541 return _controller.stream.listen( | 541 return _controller.stream.listen( |
| 542 onData, | 542 onData, |
| 543 onError: onError, | 543 onError: onError, |
| 544 onDone: onDone, | 544 onDone: onDone, |
| 545 unsubscribeOnError: unsubscribeOnError); | 545 unsubscribeOnError: unsubscribeOnError); |
| 546 } | 546 } |
| 547 | 547 |
| 548 int available() => _socket.available(); | 548 int available() => _socket.available(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 static Future<_ServerSocket> bind(String address, | 622 static Future<_ServerSocket> bind(String address, |
| 623 int port, | 623 int port, |
| 624 int backlog) { | 624 int backlog) { |
| 625 return _RawServerSocket.bind(address, port, backlog) | 625 return _RawServerSocket.bind(address, port, backlog) |
| 626 .then((socket) => new _ServerSocket(socket)); | 626 .then((socket) => new _ServerSocket(socket)); |
| 627 } | 627 } |
| 628 | 628 |
| 629 _ServerSocket(this._socket); | 629 _ServerSocket(this._socket); |
| 630 | 630 |
| 631 StreamSubscription<Socket> listen(void onData(Socket event), | 631 StreamSubscription<Socket> listen(void onData(Socket event), |
| 632 {void onError(AsyncError error), | 632 {void onError(error), |
| 633 void onDone(), | 633 void onDone(), |
| 634 bool unsubscribeOnError}) { | 634 bool unsubscribeOnError}) { |
| 635 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( | 635 return _socket.map((rawSocket) => new _Socket(rawSocket)).listen( |
| 636 onData, | 636 onData, |
| 637 onError: onError, | 637 onError: onError, |
| 638 onDone: onDone, | 638 onDone: onDone, |
| 639 unsubscribeOnError: unsubscribeOnError); | 639 unsubscribeOnError: unsubscribeOnError); |
| 640 } | 640 } |
| 641 | 641 |
| 642 int get port => _socket.port; | 642 int get port => _socket.port; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 return new _Socket(new _RawSocket._writePipe(fd)); | 777 return new _Socket(new _RawSocket._writePipe(fd)); |
| 778 } | 778 } |
| 779 | 779 |
| 780 factory _Socket._readPipe([int fd]) { | 780 factory _Socket._readPipe([int fd]) { |
| 781 return new _Socket(new _RawSocket._readPipe(fd)); | 781 return new _Socket(new _RawSocket._readPipe(fd)); |
| 782 } | 782 } |
| 783 | 783 |
| 784 _NativeSocket get _nativeSocket => _raw._socket; | 784 _NativeSocket get _nativeSocket => _raw._socket; |
| 785 | 785 |
| 786 StreamSubscription<List<int>> listen(void onData(List<int> event), | 786 StreamSubscription<List<int>> listen(void onData(List<int> event), |
| 787 {void onError(AsyncError error), | 787 {void onError(error), |
| 788 void onDone(), | 788 void onDone(), |
| 789 bool unsubscribeOnError}) { | 789 bool unsubscribeOnError}) { |
| 790 return _controller.stream.listen( | 790 return _controller.stream.listen( |
| 791 onData, | 791 onData, |
| 792 onError: onError, | 792 onError: onError, |
| 793 onDone: onDone, | 793 onDone: onDone, |
| 794 unsubscribeOnError: unsubscribeOnError); | 794 unsubscribeOnError: unsubscribeOnError); |
| 795 } | 795 } |
| 796 | 796 |
| 797 Encoding get encoding => _sink.encoding; | 797 Encoding get encoding => _sink.encoding; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 _raw.onBadCertificate = callback; | 941 _raw.onBadCertificate = callback; |
| 942 } | 942 } |
| 943 | 943 |
| 944 X509Certificate get peerCertificate { | 944 X509Certificate get peerCertificate { |
| 945 if (_raw == null) { | 945 if (_raw == null) { |
| 946 throw new StateError("peerCertificate called on destroyed SecureSocket"); | 946 throw new StateError("peerCertificate called on destroyed SecureSocket"); |
| 947 } | 947 } |
| 948 return _raw.peerCertificate; | 948 return _raw.peerCertificate; |
| 949 } | 949 } |
| 950 } | 950 } |
| OLD | NEW |