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

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

Issue 10008072: Mark as closing, when we close the connection manually. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | no next file » | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 class _HttpRequestResponseBase { 5 class _HttpRequestResponseBase {
6 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection) 6 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection)
7 : _contentLength = -1, 7 : _contentLength = -1,
8 _keepAlive = false, 8 _keepAlive = false,
9 _headers = new Map(); 9 _headers = new Map();
10 10
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 486 }
487 } 487 }
488 488
489 bool _writeFrom(List<int> buffer, [int offset, int len]) { 489 bool _writeFrom(List<int> buffer, [int offset, int len]) {
490 if (!_error && !_closing) { 490 if (!_error && !_closing) {
491 return _socket.outputStream.writeFrom(buffer, offset, len); 491 return _socket.outputStream.writeFrom(buffer, offset, len);
492 } 492 }
493 } 493 }
494 494
495 bool _close() { 495 bool _close() {
496 _closing = true;
496 _socket.close(); 497 _socket.close();
497 } 498 }
498 499
499 void _onData() { 500 void _onData() {
500 int available = _socket.available(); 501 int available = _socket.available();
501 if (available == 0) { 502 if (available == 0) {
502 return; 503 return;
503 } 504 }
504 505
505 ByteArray buffer = new ByteArray(available); 506 ByteArray buffer = new ByteArray(available);
506 int bytesRead = _socket.readList(buffer, 0, available); 507 int bytesRead = _socket.readList(buffer, 0, available);
507 if (bytesRead > 0) { 508 if (bytesRead > 0) {
508 int parsed = _httpParser.writeList(buffer, 0, bytesRead); 509 int parsed = _httpParser.writeList(buffer, 0, bytesRead);
509 if (parsed != bytesRead) { 510 if (parsed != bytesRead) {
510 // TODO(sgjesse): Error handling. 511 // TODO(sgjesse): Error handling.
511 _socket.close(); 512 _close();
512 } 513 }
513 } 514 }
514 } 515 }
515 516
516 void _onClosed() { 517 void _onClosed() {
517 _closing = true; 518 _closing = true;
518 _onConnectionClosed(null); 519 _onConnectionClosed(null);
519 } 520 }
520 521
521 void _onError(Exception e) { 522 void _onError(Exception e) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 if (_request != null && _request._streamErrorHandler != null) { 572 if (_request != null && _request._streamErrorHandler != null) {
572 _request._streamErrorHandler(e); 573 _request._streamErrorHandler(e);
573 } 574 }
574 if (_response != null && _response._streamErrorHandler != null) { 575 if (_response != null && _response._streamErrorHandler != null) {
575 _response._streamErrorHandler(e); 576 _response._streamErrorHandler(e);
576 } 577 }
577 } 578 }
578 579
579 // If currently not processing any request just close the socket. 580 // If currently not processing any request just close the socket.
580 if (_httpParser.isIdle) { 581 if (_httpParser.isIdle) {
581 _socket.close(); 582 _close();
582 if (onClosed != null && e == null) { 583 if (onClosed != null && e == null) {
583 // Don't call onClosed if onError has been called. 584 // Don't call onClosed if onError has been called.
584 onClosed(); 585 onClosed();
585 } 586 }
586 return; 587 return;
587 } 588 }
588 589
589 // Processing a request. 590 // Processing a request.
590 if (e == null) { 591 if (e == null) {
591 // Indicate connection close to the HTTP parser. 592 // Indicate connection close to the HTTP parser.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 _server = serverSocket; 676 _server = serverSocket;
676 _closeServer = false; 677 _closeServer = false;
677 } 678 }
678 679
679 void close() { 680 void close() {
680 if (_server !== null && _closeServer) { 681 if (_server !== null && _closeServer) {
681 _server.close(); 682 _server.close();
682 } 683 }
683 _server = null; 684 _server = null;
684 for (_HttpConnection connection in _connections) { 685 for (_HttpConnection connection in _connections) {
685 connection._socket.close(); 686 connection._close();
686 } 687 }
687 _connections.clear(); 688 _connections.clear();
688 } 689 }
689 690
690 int get port() { 691 int get port() {
691 if (_server === null) { 692 if (_server === null) {
692 throw new HttpException("The HttpServer is not listening on a port."); 693 throw new HttpException("The HttpServer is not listening on a port.");
693 } 694 }
694 return _server.port; 695 return _server.port;
695 } 696 }
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 sockets.addFirst(socketConn); 1246 sockets.addFirst(socketConn);
1246 socketConn._markReturned(); 1247 socketConn._markReturned();
1247 } 1248 }
1248 1249
1249 Function _onOpen; 1250 Function _onOpen;
1250 Map<String, Queue<_SocketConnection>> _openSockets; 1251 Map<String, Queue<_SocketConnection>> _openSockets;
1251 Set<_SocketConnection> _activeSockets; 1252 Set<_SocketConnection> _activeSockets;
1252 Timer _evictionTimer; 1253 Timer _evictionTimer;
1253 bool _shutdown; // Has this HTTP client been shutdown? 1254 bool _shutdown; // Has this HTTP client been shutdown?
1254 } 1255 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698