Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 // Client closed socket for writing. Socket should still be open | 502 // Client closed socket for writing. Socket should still be open |
| 503 // for writing the response. | 503 // for writing the response. |
| 504 _closing = true; | 504 _closing = true; |
| 505 } else { | 505 } else { |
| 506 // The connection is currently not used by any request just close it. | 506 // The connection is currently not used by any request just close it. |
| 507 _socket.close(); | 507 _socket.close(); |
| 508 } | 508 } |
| 509 if (_onDisconnectCallback != null) _onDisconnectCallback(); | 509 if (_onDisconnectCallback != null) _onDisconnectCallback(); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void _onError() { | 512 void _onError(Exception e) { |
| 513 // If an error occours, treat the socket as closed. | 513 // If an error occours, treat the socket as closed. |
| 514 _onClosed(); | 514 _onClosed(); |
| 515 if (_onErrorCallback != null) { | 515 if (_onErrorCallback != null) { |
| 516 _onErrorCallback("Connection closed while sending data to client."); | 516 _onErrorCallback("Connection closed while sending data to client ($e)."); |
| 517 } | 517 } |
| 518 } | 518 } |
| 519 | 519 |
| 520 void set onDisconnect(void callback()) { | 520 void set onDisconnect(void callback()) { |
| 521 _onDisconnectCallback = callback; | 521 _onDisconnectCallback = callback; |
| 522 } | 522 } |
| 523 | 523 |
| 524 void set onError(void callback(String errorMessage)) { | 524 void set onError(void callback(String errorMessage)) { |
| 525 _onErrorCallback = callback; | 525 _onErrorCallback = callback; |
| 526 } | 526 } |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1063 Queue socketConnections = _openSockets[_connectionKey(host, port)]; | 1063 Queue socketConnections = _openSockets[_connectionKey(host, port)]; |
| 1064 if (socketConnections == null || socketConnections.isEmpty()) { | 1064 if (socketConnections == null || socketConnections.isEmpty()) { |
| 1065 Socket socket = new Socket(host, port); | 1065 Socket socket = new Socket(host, port); |
| 1066 socket.onConnect = () { | 1066 socket.onConnect = () { |
| 1067 socket.onError = null; | 1067 socket.onError = null; |
| 1068 _SocketConnection socketConn = | 1068 _SocketConnection socketConn = |
| 1069 new _SocketConnection(host, port, socket); | 1069 new _SocketConnection(host, port, socket); |
| 1070 _activeSockets.add(socketConn); | 1070 _activeSockets.add(socketConn); |
| 1071 _connectionOpened(socketConn, connection); | 1071 _connectionOpened(socketConn, connection); |
| 1072 }; | 1072 }; |
| 1073 socket.onError = () { | 1073 socket.onError = (Exception e) { |
| 1074 if (_onError !== null) { | 1074 if (_onError !== null) { |
| 1075 _onError(HttpStatus.NETWORK_CONNECT_TIMEOUT_ERROR); | 1075 _onError(HttpStatus.NETWORK_CONNECT_TIMEOUT_ERROR); |
|
Mads Ager (google)
2012/03/14 12:51:51
Do interpolation as above? Or doens't it make sens
Søren Gjesse
2012/03/19 10:05:43
For some odd reason this onError currently takes a
| |
| 1076 } | 1076 } |
| 1077 }; | 1077 }; |
| 1078 } else { | 1078 } else { |
| 1079 _SocketConnection socketConn = socketConnections.removeFirst(); | 1079 _SocketConnection socketConn = socketConnections.removeFirst(); |
| 1080 _activeSockets.add(socketConn); | 1080 _activeSockets.add(socketConn); |
| 1081 new Timer(0, (ignored) => _connectionOpened(socketConn, connection)); | 1081 new Timer(0, (ignored) => _connectionOpened(socketConn, connection)); |
| 1082 | 1082 |
| 1083 // Get rid of eviction timer if there are no more active connections. | 1083 // Get rid of eviction timer if there are no more active connections. |
| 1084 if (socketConnections.isEmpty()) { | 1084 if (socketConnections.isEmpty()) { |
| 1085 _evictionTimer.cancel(); | 1085 _evictionTimer.cancel(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 _onError = callback; | 1138 _onError = callback; |
| 1139 } | 1139 } |
| 1140 | 1140 |
| 1141 Function _onOpen; | 1141 Function _onOpen; |
| 1142 Function _onError; | 1142 Function _onError; |
| 1143 Map<String, Queue<_SocketConnection>> _openSockets; | 1143 Map<String, Queue<_SocketConnection>> _openSockets; |
| 1144 Set<_SocketConnection> _activeSockets; | 1144 Set<_SocketConnection> _activeSockets; |
| 1145 Timer _evictionTimer; | 1145 Timer _evictionTimer; |
| 1146 bool _shutdown; // Has this HTTP client been shutdown? | 1146 bool _shutdown; // Has this HTTP client been shutdown? |
| 1147 } | 1147 } |
| OLD | NEW |