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

Side by Side Diff: sdk/lib/io/http_impl.dart

Issue 12610006: Renamed StreamSink to EventSink. Renamed signalError to addError. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changed inheritance back! Now create StreamSink instead of EventSink where we create them. Created 7 years, 9 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
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 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpIncoming extends Stream<List<int>> { 7 class _HttpIncoming extends Stream<List<int>> {
8 final int _transferLength; 8 final int _transferLength;
9 final Completer _dataCompleter = new Completer(); 9 final Completer _dataCompleter = new Completer();
10 Stream<List<int>> _stream; 10 Stream<List<int>> _stream;
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 writeCRLF(); 689 writeCRLF();
690 } 690 }
691 } 691 }
692 692
693 693
694 // Transformer that transforms data to HTTP Chunked Encoding. 694 // Transformer that transforms data to HTTP Chunked Encoding.
695 class _ChunkedTransformer extends StreamEventTransformer<List<int>, List<int>> { 695 class _ChunkedTransformer extends StreamEventTransformer<List<int>, List<int>> {
696 final bool writeEnd; 696 final bool writeEnd;
697 _ChunkedTransformer({this.writeEnd: true}); 697 _ChunkedTransformer({this.writeEnd: true});
698 698
699 void handleData(List<int> data, StreamSink<List<int>> sink) { 699 void handleData(List<int> data, EventSink<List<int>> sink) {
700 _addChunk(data, sink.add); 700 _addChunk(data, sink.add);
701 } 701 }
702 702
703 void handleDone(StreamSink<List<int>> sink) { 703 void handleDone(EventSink<List<int>> sink) {
704 if (writeEnd) { 704 if (writeEnd) {
705 _addChunk([], sink.add); 705 _addChunk([], sink.add);
706 } 706 }
707 sink.close(); 707 sink.close();
708 } 708 }
709 709
710 static void _addChunk(List<int> data, void add(List<int> data)) { 710 static void _addChunk(List<int> data, void add(List<int> data)) {
711 add(_chunkHeader(data.length)); 711 add(_chunkHeader(data.length));
712 if (data.length > 0) add(data); 712 if (data.length > 0) add(data);
713 add(_chunkFooter); 713 add(_chunkFooter);
(...skipping 25 matching lines...) Expand all
739 class _DoneTransformer implements StreamTransformer<List<int>, List<int>> { 739 class _DoneTransformer implements StreamTransformer<List<int>, List<int>> {
740 final StreamController<List<int>> _controller 740 final StreamController<List<int>> _controller
741 = new StreamController<List<int>>(); 741 = new StreamController<List<int>>();
742 final Function _onDone; 742 final Function _onDone;
743 743
744 _DoneTransformer(this._onDone); 744 _DoneTransformer(this._onDone);
745 745
746 Stream<List<int>> bind(Stream<List<int>> stream) { 746 Stream<List<int>> bind(Stream<List<int>> stream) {
747 var subscription = stream.listen( 747 var subscription = stream.listen(
748 _controller.add, 748 _controller.add,
749 onError: _controller.signalError, 749 onError: _controller.addError,
750 onDone: () { 750 onDone: () {
751 _onDone(); 751 _onDone();
752 _controller.close(); 752 _controller.close();
753 }); 753 });
754 return _controller.stream; 754 return _controller.stream;
755 } 755 }
756 } 756 }
757 757
758 // Transformer that validates the data written. 758 // Transformer that validates the data written.
759 class _DataValidatorTransformer 759 class _DataValidatorTransformer
760 implements StreamTransformer<List<int>, List<int>> { 760 implements StreamTransformer<List<int>, List<int>> {
761 final StreamController<List<int>> _controller = 761 final StreamController<List<int>> _controller =
762 new StreamController<List<int>>(); 762 new StreamController<List<int>>();
763 int _bytesWritten = 0; 763 int _bytesWritten = 0;
764 764
765 int expectedTransferLength; 765 int expectedTransferLength;
766 766
767 Stream<List<int>> bind(Stream<List<int>> stream) { 767 Stream<List<int>> bind(Stream<List<int>> stream) {
768 var subscription; 768 var subscription;
769 subscription = stream.listen( 769 subscription = stream.listen(
770 (data) { 770 (data) {
771 if (expectedTransferLength != null) { 771 if (expectedTransferLength != null) {
772 _bytesWritten += data.length; 772 _bytesWritten += data.length;
773 if (_bytesWritten > expectedTransferLength) { 773 if (_bytesWritten > expectedTransferLength) {
774 subscription.cancel(); 774 subscription.cancel();
775 _controller.signalError(new HttpException( 775 _controller.addError(new HttpException(
776 "Content size exceeds specified contentLength. " 776 "Content size exceeds specified contentLength. "
777 "$_bytesWritten bytes written while expected " 777 "$_bytesWritten bytes written while expected "
778 "$expectedTransferLength.")); 778 "$expectedTransferLength."));
779 _controller.close(); 779 _controller.close();
780 return; 780 return;
781 } 781 }
782 } 782 }
783 _controller.add(data); 783 _controller.add(data);
784 }, 784 },
785 onError: (error) { 785 onError: (error) {
786 _controller.signalError(error); 786 _controller.addError(error);
787 _controller.close(); 787 _controller.close();
788 }, 788 },
789 onDone: () { 789 onDone: () {
790 if (expectedTransferLength != null) { 790 if (expectedTransferLength != null) {
791 if (_bytesWritten < expectedTransferLength) { 791 if (_bytesWritten < expectedTransferLength) {
792 _controller.signalError(new HttpException( 792 _controller.addError(new HttpException(
793 "Content size below specified contentLength. " 793 "Content size below specified contentLength. "
794 " $_bytesWritten bytes written while expected " 794 " $_bytesWritten bytes written while expected "
795 "$expectedTransferLength.")); 795 "$expectedTransferLength."));
796 } 796 }
797 } 797 }
798 _controller.close(); 798 _controller.close();
799 }, 799 },
800 unsubscribeOnError: true); 800 unsubscribeOnError: true);
801 return _controller.stream; 801 return _controller.stream;
802 } 802 }
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event), 1323 StreamSubscription<HttpRequest> listen(void onData(HttpRequest event),
1324 {void onError(AsyncError error), 1324 {void onError(AsyncError error),
1325 void onDone(), 1325 void onDone(),
1326 bool unsubscribeOnError}) { 1326 bool unsubscribeOnError}) {
1327 _serverSocket.listen( 1327 _serverSocket.listen(
1328 (Socket socket) { 1328 (Socket socket) {
1329 // Accept the client connection. 1329 // Accept the client connection.
1330 _HttpConnection connection = new _HttpConnection(socket, this); 1330 _HttpConnection connection = new _HttpConnection(socket, this);
1331 _connections.add(connection); 1331 _connections.add(connection);
1332 }, 1332 },
1333 onError: _controller.signalError, 1333 onError: _controller.addError,
1334 onDone: _controller.close); 1334 onDone: _controller.close);
1335 return _controller.stream.listen(onData, 1335 return _controller.stream.listen(onData,
1336 onError: onError, 1336 onError: onError,
1337 onDone: onDone, 1337 onDone: onDone,
1338 unsubscribeOnError: unsubscribeOnError); 1338 unsubscribeOnError: unsubscribeOnError);
1339 } 1339 }
1340 1340
1341 void close() { 1341 void close() {
1342 closed = true; 1342 closed = true;
1343 if (_serverSocket != null && _closeServer) { 1343 if (_serverSocket != null && _closeServer) {
(...skipping 16 matching lines...) Expand all
1360 1360
1361 set sessionTimeout(int timeout) { 1361 set sessionTimeout(int timeout) {
1362 _sessionManager.sessionTimeout = timeout; 1362 _sessionManager.sessionTimeout = timeout;
1363 } 1363 }
1364 1364
1365 void _handleRequest(HttpRequest request) { 1365 void _handleRequest(HttpRequest request) {
1366 _controller.add(request); 1366 _controller.add(request);
1367 } 1367 }
1368 1368
1369 void _handleError(AsyncError error) { 1369 void _handleError(AsyncError error) {
1370 if (!closed) _controller.signalError(error); 1370 if (!closed) _controller.addError(error);
1371 } 1371 }
1372 1372
1373 void _connectionClosed(_HttpConnection connection) { 1373 void _connectionClosed(_HttpConnection connection) {
1374 _connections.remove(connection); 1374 _connections.remove(connection);
1375 } 1375 }
1376 1376
1377 _HttpSessionManager get _sessionManager { 1377 _HttpSessionManager get _sessionManager {
1378 // Lazy init. 1378 // Lazy init.
1379 if (_sessionManagerInstance == null) { 1379 if (_sessionManagerInstance == null) {
1380 _sessionManagerInstance = new _HttpSessionManager(); 1380 _sessionManagerInstance = new _HttpSessionManager();
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 1636
1637 1637
1638 class _RedirectInfo implements RedirectInfo { 1638 class _RedirectInfo implements RedirectInfo {
1639 const _RedirectInfo(int this.statusCode, 1639 const _RedirectInfo(int this.statusCode,
1640 String this.method, 1640 String this.method,
1641 Uri this.location); 1641 Uri this.location);
1642 final int statusCode; 1642 final int statusCode;
1643 final String method; 1643 final String method;
1644 final Uri location; 1644 final Uri location;
1645 } 1645 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698