| 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 // Utility class for encoding a string into UTF-8 byte stream. | 5 // Utility class for encoding a string into UTF-8 byte stream. |
| 6 class _UTF8Encoder { | 6 class _UTF8Encoder { |
| 7 static List<int> encodeString(String string) { | 7 static List<int> encodeString(String string) { |
| 8 int size = _encodingSize(string); | 8 int size = _encodingSize(string); |
| 9 ByteArray result = new ByteArray(size); | 9 ByteArray result = new ByteArray(size); |
| 10 _encodeString(string, result); | 10 _encodeString(string, result); |
| (...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 _connectionOpened(socketConn, connection); | 1055 _connectionOpened(socketConn, connection); |
| 1056 }; | 1056 }; |
| 1057 socket.onError = () { | 1057 socket.onError = () { |
| 1058 if (_onError !== null) { | 1058 if (_onError !== null) { |
| 1059 _onError(HttpStatus.NETWORK_CONNECT_TIMEOUT_ERROR); | 1059 _onError(HttpStatus.NETWORK_CONNECT_TIMEOUT_ERROR); |
| 1060 } | 1060 } |
| 1061 }; | 1061 }; |
| 1062 } else { | 1062 } else { |
| 1063 _SocketConnection socketConn = socketConnections.removeFirst(); | 1063 _SocketConnection socketConn = socketConnections.removeFirst(); |
| 1064 _activeSockets.add(socketConn); | 1064 _activeSockets.add(socketConn); |
| 1065 new Timer((ignored) => _connectionOpened(socketConn, connection), 0); | 1065 new Timer(0, (ignored) => _connectionOpened(socketConn, connection)); |
| 1066 | 1066 |
| 1067 // Get rid of eviction timer if there are no more active connections. | 1067 // Get rid of eviction timer if there are no more active connections. |
| 1068 if (socketConnections.isEmpty()) { | 1068 if (socketConnections.isEmpty()) { |
| 1069 _evictionTimer.cancel(); | 1069 _evictionTimer.cancel(); |
| 1070 _evictionTimer = null; | 1070 _evictionTimer = null; |
| 1071 } | 1071 } |
| 1072 } | 1072 } |
| 1073 | 1073 |
| 1074 return connection; | 1074 return connection; |
| 1075 } | 1075 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1102 _SocketConnection socketConn = connections.last(); | 1102 _SocketConnection socketConn = connections.last(); |
| 1103 if (socketConn._idleTime(now).inMilliseconds > | 1103 if (socketConn._idleTime(now).inMilliseconds > |
| 1104 DEFAULT_EVICTION_TIMEOUT) { | 1104 DEFAULT_EVICTION_TIMEOUT) { |
| 1105 connections.removeLast(); | 1105 connections.removeLast(); |
| 1106 } else { | 1106 } else { |
| 1107 break; | 1107 break; |
| 1108 } | 1108 } |
| 1109 } | 1109 } |
| 1110 }); | 1110 }); |
| 1111 } | 1111 } |
| 1112 _evictionTimer = new Timer.repeating(_handleEviction, 10000); | 1112 _evictionTimer = new Timer.repeating(10000, _handleEviction); |
| 1113 } | 1113 } |
| 1114 | 1114 |
| 1115 // Return connection. | 1115 // Return connection. |
| 1116 _activeSockets.remove(socketConn); | 1116 _activeSockets.remove(socketConn); |
| 1117 sockets.addFirst(socketConn); | 1117 sockets.addFirst(socketConn); |
| 1118 socketConn._markReturned(); | 1118 socketConn._markReturned(); |
| 1119 } | 1119 } |
| 1120 | 1120 |
| 1121 void set onError(void callback(int status)) { | 1121 void set onError(void callback(int status)) { |
| 1122 _onError = callback; | 1122 _onError = callback; |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 Function _onOpen; | 1125 Function _onOpen; |
| 1126 Function _onError; | 1126 Function _onError; |
| 1127 Map<String, Queue<_SocketConnection>> _openSockets; | 1127 Map<String, Queue<_SocketConnection>> _openSockets; |
| 1128 Set<_SocketConnection> _activeSockets; | 1128 Set<_SocketConnection> _activeSockets; |
| 1129 Timer _evictionTimer; | 1129 Timer _evictionTimer; |
| 1130 bool _shutdown; // Has this HTTP client been shutdown? | 1130 bool _shutdown; // Has this HTTP client been shutdown? |
| 1131 } | 1131 } |
| OLD | NEW |