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

Unified Diff: runtime/bin/http_impl.dart

Issue 9965053: Add a new attachTo method to HttpServer, for using an existing ServerSocket. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpServerTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_impl.dart
===================================================================
--- runtime/bin/http_impl.dart (revision 6032)
+++ runtime/bin/http_impl.dart (working copy)
@@ -629,33 +629,42 @@
// 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() : _connections = new Set<_HttpConnection>();
+
void listen(String host, int port, [int backlog = 5]) {
+ listenOn(new ServerSocket(host, port, backlog));
+ _closeServer = true;
+ }
+ void listenOn(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;
+ _server = serverSocket;
+ _closeServer = false;
}
void close() {
- _server.close();
+ if (_server !== null && _closeServer) {
+ _server.close();
+ }
+ _server = null;
for (_HttpConnection connection in _connections) {
connection._socket.close();
}
+ _connections.clear();
}
- int get port() => _server.port;
+ int get port() => _server === null ? -1 : _server.port;
Søren Gjesse 2012/04/02 08:16:45 How about throwing an exception if the server has
Anders Johnsen 2012/04/02 08:24:35 Even better! :)
void set onError(void callback(Exception e)) {
_onError = callback;
@@ -666,6 +675,7 @@
}
ServerSocket _server; // The server listen socket.
+ bool _closeServer = false;
Set<_HttpConnection> _connections; // Set of currently connected clients.
Function _onRequest;
Function _onError;
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpServerTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698