Chromium Code Reviews| Index: runtime/bin/http_impl.dart |
| =================================================================== |
| --- runtime/bin/http_impl.dart (revision 6032) |
| +++ runtime/bin/http_impl.dart (working copy) |
| @@ -629,30 +629,38 @@ |
| // HTTP server waiting for socket connections. The connections are |
| // managed by the server and as requests are received the request. |
| class _HttpServer implements HttpServer { |
| + _HttpServer() : |
|
Søren Gjesse
2012/04/02 07:42:15
Fits on one line?
Anders Johnsen
2012/04/02 08:12:34
Done.
|
| + _connections = new Set<_HttpConnection>(); |
| + |
| void listen(String host, int port, [int backlog = 5]) { |
| + _server = new ServerSocket(host, port, backlog); |
| + attachTo(_server); |
| + } |
| + void attachTo(ServerSocket serverSocket) { |
| void onConnection(Socket socket) { |
| // Accept the client connection. |
| _HttpConnection connection = new _HttpConnection(this); |
| - connection._connectionEstablished(socket); |
| connection.requestReceived = _onRequest; |
| - _connections.add(connection); |
| connection.onDisconnect = () => _connections.remove(connection); |
| connection.onError = (e) { |
| if (_onError != null) _onError(e); |
| }; |
| + connection._connectionEstablished(socket); |
| + _connections.add(connection); |
| } |
| - |
| - _connections = new Set<_HttpConnection>(); |
| - _server = new ServerSocket(host, port, backlog); |
| - _server.onConnection = onConnection; |
| + serverSocket.onConnection = onConnection; |
| } |
| void close() { |
| - _server.close(); |
| + if (_server !== null) { |
| + _server.close(); |
| + _server = null; |
| + } |
| for (_HttpConnection connection in _connections) { |
| connection._socket.close(); |
| } |
| + _connections.clear(); |
| } |
| int get port() => _server.port; |
|
Søren Gjesse
2012/04/02 07:42:15
This will give an exception if _server is null. Yo
Anders Johnsen
2012/04/02 08:12:34
Agreed, I've changed the logic a bit.
|
| @@ -665,7 +673,7 @@ |
| _onRequest = callback; |
| } |
| - ServerSocket _server; // The server listen socket. |
| + ServerSocket _server; // The server listen socket, if created internally. |
| Set<_HttpConnection> _connections; // Set of currently connected clients. |
| Function _onRequest; |
| Function _onError; |