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

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

Issue 10356069: Correctly entirely close client connections, when closing http server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 _HttpHeaders implements HttpHeaders { 5 class _HttpHeaders implements HttpHeaders {
6 _HttpHeaders() : _headers = new Map<String, List<String>>(); 6 _HttpHeaders() : _headers = new Map<String, List<String>>();
7 7
8 List<String> operator[](String name) { 8 List<String> operator[](String name) {
9 name = name.toLowerCase(); 9 name = name.toLowerCase();
10 return _headers[name]; 10 return _headers[name];
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 void listen(String host, int port, [int backlog = 5]) { 963 void listen(String host, int port, [int backlog = 5]) {
964 listenOn(new ServerSocket(host, port, backlog)); 964 listenOn(new ServerSocket(host, port, backlog));
965 _closeServer = true; 965 _closeServer = true;
966 } 966 }
967 967
968 void listenOn(ServerSocket serverSocket) { 968 void listenOn(ServerSocket serverSocket) {
969 void onConnection(Socket socket) { 969 void onConnection(Socket socket) {
970 // Accept the client connection. 970 // Accept the client connection.
971 _HttpConnection connection = new _HttpConnection(this); 971 _HttpConnection connection = new _HttpConnection(this);
972 connection._connectionEstablished(socket); 972 connection._connectionEstablished(socket);
973 _connections.add(connection);
973 connection.onRequestReceived = _handleRequest; 974 connection.onRequestReceived = _handleRequest;
974 connection.onClosed = () => _connections.remove(connection); 975 connection.onClosed = () => _connections.remove(connection);
975 connection.onDetach = () => _connections.remove(connection); 976 connection.onDetach = () => _connections.remove(connection);
976 connection.onError = (e) { 977 connection.onError = (e) {
977 _connections.remove(connection); 978 _connections.remove(connection);
978 if (_onError != null) { 979 if (_onError != null) {
979 _onError(e); 980 _onError(e);
980 } else { 981 } else {
981 throw(e); 982 throw(e);
982 } 983 }
983 }; 984 };
984 connection._connectionEstablished(socket);
985 _connections.add(connection);
986 } 985 }
987 serverSocket.onConnection = onConnection; 986 serverSocket.onConnection = onConnection;
988 _server = serverSocket; 987 _server = serverSocket;
989 _closeServer = false; 988 _closeServer = false;
990 } 989 }
991 990
992 addRequestHandler(bool matcher(HttpRequest request), 991 addRequestHandler(bool matcher(HttpRequest request),
993 void handler(HttpRequest request, HttpResponse response)) { 992 void handler(HttpRequest request, HttpResponse response)) {
994 _handlers.add(new _RequestHandlerRegistration(matcher, handler)); 993 _handlers.add(new _RequestHandlerRegistration(matcher, handler));
995 } 994 }
996 995
997 void set defaultRequestHandler( 996 void set defaultRequestHandler(
998 void handler(HttpRequest request, HttpResponse response)) { 997 void handler(HttpRequest request, HttpResponse response)) {
999 _defaultHandler = handler; 998 _defaultHandler = handler;
1000 } 999 }
1001 1000
1002 void close() { 1001 void close() {
1003 if (_server !== null && _closeServer) { 1002 if (_server !== null && _closeServer) {
1004 _server.close(); 1003 _server.close();
1005 } 1004 }
1006 _server = null; 1005 _server = null;
1007 for (_HttpConnection connection in _connections) { 1006 for (_HttpConnection connection in _connections) {
1008 connection._close(); 1007 connection._destroy();
1009 } 1008 }
1010 _connections.clear(); 1009 _connections.clear();
1011 } 1010 }
1012 1011
1013 int get port() { 1012 int get port() {
1014 if (_server === null) { 1013 if (_server === null) {
1015 throw new HttpException("The HttpServer is not listening on a port."); 1014 throw new HttpException("The HttpServer is not listening on a port.");
1016 } 1015 }
1017 return _server.port; 1016 return _server.port;
1018 } 1017 }
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 1647
1649 1648
1650 class _RedirectInfo implements RedirectInfo { 1649 class _RedirectInfo implements RedirectInfo {
1651 const _RedirectInfo(int this.statusCode, 1650 const _RedirectInfo(int this.statusCode,
1652 String this.method, 1651 String this.method,
1653 Uri this.location); 1652 Uri this.location);
1654 final int statusCode; 1653 final int statusCode;
1655 final String method; 1654 final String method;
1656 final Uri location; 1655 final Uri location;
1657 } 1656 }
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