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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 error: (e) { | 443 error: (e) { |
444 _controller.addError(new AsyncError(e)); | 444 _controller.addError(new AsyncError(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(AsyncError error), |
452 void onDone(), | 452 void onDone(), |
453 bool unsubscribeOnError}) { | 453 bool cancelOnError}) { |
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 cancelOnError: cancelOnError); |
459 } | 459 } |
460 | 460 |
461 int get port => _socket.port; | 461 int get port => _socket.port; |
462 | 462 |
463 void close() => _socket.close(); | 463 void close() => _socket.close(); |
464 | 464 |
465 void _pause() { | 465 void _pause() { |
466 _socket.setListening(read: false, write: false); | 466 _socket.setListening(read: false, write: false); |
467 } | 467 } |
468 | 468 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(AsyncError error), |
539 void onDone(), | 539 void onDone(), |
540 bool unsubscribeOnError}) { | 540 bool cancelOnError}) { |
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 cancelOnError: cancelOnError); |
546 } | 546 } |
547 | 547 |
548 int available() => _socket.available(); | 548 int available() => _socket.available(); |
549 | 549 |
550 List<int> read([int len]) => _socket.read(len); | 550 List<int> read([int len]) => _socket.read(len); |
551 | 551 |
552 int write(List<int> buffer, [int offset, int count]) => | 552 int write(List<int> buffer, [int offset, int count]) => |
553 _socket.write(buffer, offset, count); | 553 _socket.write(buffer, offset, count); |
554 | 554 |
555 void close() => _socket.close(); | 555 void close() => _socket.close(); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(AsyncError error), |
633 void onDone(), | 633 void onDone(), |
634 bool unsubscribeOnError}) { | 634 bool cancelOnError}) { |
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 cancelOnError: cancelOnError); |
640 } | 640 } |
641 | 641 |
642 int get port => _socket.port; | 642 int get port => _socket.port; |
643 | 643 |
644 void close() => _socket.close(); | 644 void close() => _socket.close(); |
645 } | 645 } |
646 | 646 |
647 | 647 |
648 patch class Socket { | 648 patch class Socket { |
649 /* patch */ static Future<Socket> connect(String host, int port) { | 649 /* patch */ static Future<Socket> connect(String host, int port) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 offset = 0; | 681 offset = 0; |
682 write(); | 682 write(); |
683 }, | 683 }, |
684 onError: (error) { | 684 onError: (error) { |
685 socket._consumerDone(); | 685 socket._consumerDone(); |
686 done(error); | 686 done(error); |
687 }, | 687 }, |
688 onDone: () { | 688 onDone: () { |
689 done(); | 689 done(); |
690 }, | 690 }, |
691 unsubscribeOnError: true); | 691 cancelOnError: true); |
692 } | 692 } |
693 return streamCompleter.future; | 693 return streamCompleter.future; |
694 } | 694 } |
695 | 695 |
696 Future<Socket> close() { | 696 Future<Socket> close() { |
697 socket._consumerDone(); | 697 socket._consumerDone(); |
698 return new Future.immediate(socket); | 698 return new Future.immediate(socket); |
699 } | 699 } |
700 | 700 |
701 void write() { | 701 void write() { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(AsyncError error), |
788 void onDone(), | 788 void onDone(), |
789 bool unsubscribeOnError}) { | 789 bool cancelOnError}) { |
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 cancelOnError: cancelOnError); |
795 } | 795 } |
796 | 796 |
797 Encoding get encoding => _sink.encoding; | 797 Encoding get encoding => _sink.encoding; |
798 | 798 |
799 void set encoding(Encoding value) { | 799 void set encoding(Encoding value) { |
800 _sink.encoding = value; | 800 _sink.encoding = value; |
801 } | 801 } |
802 | 802 |
803 void write(Object obj) => _sink.write(obj); | 803 void write(Object obj) => _sink.write(obj); |
804 | 804 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 int get remotePort => _raw.remotePort; | 837 int get remotePort => _raw.remotePort; |
838 | 838 |
839 // Ensure a subscription on the raw socket. Both the stream and the | 839 // Ensure a subscription on the raw socket. Both the stream and the |
840 // consumer needs a subscription as they share the error and done | 840 // consumer needs a subscription as they share the error and done |
841 // events from the raw socket. | 841 // events from the raw socket. |
842 void _ensureRawSocketSubscription() { | 842 void _ensureRawSocketSubscription() { |
843 if (_subscription == null && _raw != null) { | 843 if (_subscription == null && _raw != null) { |
844 _subscription = _raw.listen(_onData, | 844 _subscription = _raw.listen(_onData, |
845 onError: _onError, | 845 onError: _onError, |
846 onDone: _onDone, | 846 onDone: _onDone, |
847 unsubscribeOnError: true); | 847 cancelOnError: true); |
848 } | 848 } |
849 } | 849 } |
850 | 850 |
851 _closeRawSocket() { | 851 _closeRawSocket() { |
852 var tmp = _raw; | 852 var tmp = _raw; |
853 _raw = null; | 853 _raw = null; |
854 _closed = true; | 854 _closed = true; |
855 tmp.close(); | 855 tmp.close(); |
856 } | 856 } |
857 | 857 |
(...skipping 83 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 |