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

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
« runtime/bin/http.dart ('K') | « runtime/bin/http.dart ('k') | no next file » | 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,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;
« runtime/bin/http.dart ('K') | « runtime/bin/http.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698