Chromium Code Reviews| Index: samples/chat/http_impl.dart |
| diff --git a/samples/chat/http_impl.dart b/samples/chat/http_impl.dart |
| index ec4aa9389e563b3539c1f8a8583e02945f6899a8..61193955166e4b7a269c3804460967c6fe2fddf7 100644 |
| --- a/samples/chat/http_impl.dart |
| +++ b/samples/chat/http_impl.dart |
| @@ -1386,17 +1386,12 @@ class HTTPClientImplementation implements HTTPClient{ |
| HTTPClientImplementation() : _openSockets = new Map(), _shutdown = false; |
|
Søren Gjesse
2011/12/01 11:15:43
You should also update http.dart where this interf
Mads Ager (google)
2011/12/01 11:43:59
Done.
|
| - HTTPClientRequest open(String method, |
| - String host, |
| - int port, |
| - String path) { |
| - // TODO(sgjesse): Throw exception. |
| - if (_shutdown) return null; |
| - SocketConnection socketConn = _getSocketConnection(host, port); |
| - HTTPClientConnection connection = |
| - new HTTPClientConnection(this, socketConn); |
| - HTTPClientRequest request = connection.open(method, path); |
| - return request; |
| + void open(String method, String host, int port, String path) { |
| + if (_shutdown && _openHandler) { |
| + _openHandler(null); |
| + return; |
| + } |
| + _getSocketConnection(host, port, method, path); |
| } |
| void shutdown() { |
| @@ -1417,17 +1412,31 @@ class HTTPClientImplementation implements HTTPClient{ |
| return "$host:$port"; |
| } |
| - SocketConnection _getSocketConnection(String host, int port) { |
| - SocketConnection entry; |
| + void _getSocketConnection(String host, int port, String method, String path) { |
| + |
| + void _connectionOpened(SocketConnection socketConn) { |
| + HTTPClientConnection connection = |
| + new HTTPClientConnection(this, socketConn); |
| + HTTPClientRequest request = connection.open(method, path); |
| + if (_openHandler != null) { |
| + _openHandler(request); |
| + } |
| + } |
| // If there are active connections for this key get the first one |
| // otherwise create a new one. |
| Queue socketConnections = _openSockets[_connectionKey(host, port)]; |
| if (socketConnections == null || socketConnections.isEmpty()) { |
| Socket socket = new Socket(host, port); |
| - entry = new SocketConnection(host, port, socket); |
| + print('connect handler set'); |
|
Søren Gjesse
2011/12/01 11:15:43
Remove print.
Mads Ager (google)
2011/12/01 11:43:59
Done.
|
| + socket.connectHandler = () { |
| + print('connect handler'); |
|
Søren Gjesse
2011/12/01 11:15:43
Ditto.
Mads Ager (google)
2011/12/01 11:43:59
Done.
|
| + SocketConnection socketConn = new SocketConnection(host, port, socket); |
| + _connectionOpened(socketConn); |
| + }; |
| } else { |
| - entry = socketConnections.removeFirst(); |
| + SocketConnection socketConn = socketConnections.removeFirst(); |
| + _connectionOpened(socketConn); |
| // Get rid of eviction timer if there are no more active connections. |
| if (socketConnections.isEmpty()) { |
| @@ -1435,8 +1444,6 @@ class HTTPClientImplementation implements HTTPClient{ |
| _evictionTimer = null; |
| } |
| } |
| - |
| - return entry; |
| } |
| void _returnSocketConnection(SocketConnection socketConn) { |
| @@ -1482,6 +1489,12 @@ class HTTPClientImplementation implements HTTPClient{ |
| socketConn._markReturned(); |
| } |
| + void set openHandler(void callback(HTTPClientRequest request)) { |
| + _openHandler = callback; |
| + } |
| + |
| + var _openHandler; |
|
Søren Gjesse
2011/12/01 11:15:43
Remove empty line.
Mads Ager (google)
2011/12/01 11:43:59
Done.
|
| + |
| Map<String, Queue<SocketConnection>> _openSockets; |
| Timer _evictionTimer; |
| bool _shutdown; // Has this HTTP client been shutdown? |