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

Unified Diff: services/http_server/http_server_factory_impl.cc

Issue 953513002: http_server: accept full NetAddress in CreateHttpServer. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Address Ben's comments. Created 5 years, 10 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 | « services/http_server/http_server_factory_impl.h ('k') | services/http_server/http_server_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/http_server/http_server_factory_impl.cc
diff --git a/services/http_server/http_server_factory_impl.cc b/services/http_server/http_server_factory_impl.cc
index 8dce240b04ad24a3b3bb5c0211d421203ff6f540..6015de8da5072090202b93056c0c114a9469833b 100644
--- a/services/http_server/http_server_factory_impl.cc
+++ b/services/http_server/http_server_factory_impl.cc
@@ -28,13 +28,15 @@ void HttpServerFactoryImpl::AddBinding(
}
void HttpServerFactoryImpl::DeleteServer(HttpServerImpl* server,
- uint16_t requested_port) {
- if (requested_port) {
- DCHECK(port_indicated_servers_.count(requested_port));
- DCHECK_EQ(server, port_indicated_servers_[requested_port]);
+ mojo::NetAddress* requested_address) {
+ ServerKey key = GetServerKey(requested_address);
+
+ if (key.second) { // If the port is non-zero.
+ DCHECK(port_indicated_servers_.count(key));
+ DCHECK_EQ(server, port_indicated_servers_[key]);
delete server;
- port_indicated_servers_.erase(requested_port);
+ port_indicated_servers_.erase(key);
} else {
DCHECK(port_any_servers_.count(server));
@@ -43,16 +45,44 @@ void HttpServerFactoryImpl::DeleteServer(HttpServerImpl* server,
}
}
+HttpServerFactoryImpl::ServerKey HttpServerFactoryImpl::GetServerKey(
+ mojo::NetAddress* local_address) {
+ DCHECK(local_address);
+
+ if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV6) {
+ return ServerKey(local_address->ipv6->addr, local_address->ipv6->port);
+ } else if (local_address->family == mojo::NET_ADDRESS_FAMILY_IPV4) {
+ return ServerKey(local_address->ipv4->addr, local_address->ipv4->port);
+ } else {
+ return ServerKey();
+ }
+}
+
void HttpServerFactoryImpl::CreateHttpServer(
mojo::InterfaceRequest<HttpServer> server_request,
- uint16_t port) {
- if (port) {
- if (!port_indicated_servers_.count(port)) {
- port_indicated_servers_[port] = new HttpServerImpl(app_, this, port);
+ mojo::NetAddressPtr local_address) {
+ if (!local_address) {
+ local_address = mojo::NetAddress::New();
+ local_address->family = mojo::NET_ADDRESS_FAMILY_IPV4;
+ local_address->ipv4 = mojo::NetAddressIPv4::New();
+ local_address->ipv4->addr.resize(4);
+ local_address->ipv4->addr[0] = 0;
+ local_address->ipv4->addr[1] = 0;
+ local_address->ipv4->addr[2] = 0;
+ local_address->ipv4->addr[3] = 0;
+ local_address->ipv4->port = 0;
+ }
+ ServerKey key = GetServerKey(local_address.get());
+
+ if (key.second) { // If the port is non-zero.
+ if (!port_indicated_servers_.count(key)) {
+ port_indicated_servers_[key] =
+ new HttpServerImpl(app_, this, local_address.Pass());
}
- port_indicated_servers_[port]->AddBinding(server_request.Pass());
+ port_indicated_servers_[key]->AddBinding(server_request.Pass());
} else {
- HttpServerImpl* server = new HttpServerImpl(app_, this, port);
+ HttpServerImpl* server =
+ new HttpServerImpl(app_, this, local_address.Pass());
server->AddBinding(server_request.Pass());
port_any_servers_.insert(server);
}
« no previous file with comments | « services/http_server/http_server_factory_impl.h ('k') | services/http_server/http_server_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698