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

Side by Side Diff: mojo/services/network/http_server_impl.cc

Issue 1841863002: Update monet. (Closed) Base URL: https://github.com/domokit/monet.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/services/network/http_server_impl.h" 5 #include "mojo/services/network/http_server_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "mojo/services/network/http_connection_impl.h" 8 #include "mojo/services/network/http_connection_impl.h"
9 #include "mojo/services/network/net_adapters.h" 9 #include "mojo/services/network/net_adapters.h"
10 #include "mojo/services/network/net_address_type_converters.h" 10 #include "mojo/services/network/net_address_type_converters.h"
11 #include "net/base/ip_endpoint.h" 11 #include "net/base/ip_endpoint.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/log/net_log.h" 13 #include "net/log/net_log.h"
14 #include "net/socket/tcp_server_socket.h" 14 #include "net/socket/tcp_server_socket.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 namespace { 18 namespace {
19 19
20 const int kBackLog = 10; 20 const int kBackLog = 10;
21 21
22 } // namespace 22 } // namespace
23 23
24 // static 24 // static
25 void HttpServerImpl::Create( 25 void HttpServerImpl::Create(
26 NetAddressPtr local_address, 26 NetAddressPtr local_address,
27 HttpServerDelegatePtr delegate, 27 InterfaceHandle<HttpServerDelegate> delegate,
28 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) { 28 const Callback<void(NetworkErrorPtr, NetAddressPtr)>& callback) {
29 HttpServerImpl* http_server = new HttpServerImpl(delegate.Pass()); 29 HttpServerImpl* http_server = new HttpServerImpl(delegate.Pass());
30 30
31 int net_error = http_server->Start(local_address.Pass()); 31 int net_error = http_server->Start(local_address.Pass());
32 if (net_error != net::OK) { 32 if (net_error != net::OK) {
33 callback.Run(MakeNetworkError(net_error), nullptr); 33 callback.Run(MakeNetworkError(net_error), nullptr);
34 delete http_server; 34 delete http_server;
35 return; 35 return;
36 } 36 }
37 callback.Run(MakeNetworkError(net::OK), http_server->GetLocalAddress()); 37 callback.Run(MakeNetworkError(net::OK), http_server->GetLocalAddress());
38 } 38 }
39 39
40 HttpServerImpl::HttpServerImpl(HttpServerDelegatePtr delegate) 40 HttpServerImpl::HttpServerImpl(InterfaceHandle<HttpServerDelegate> delegate)
41 : delegate_(delegate.Pass()) { 41 : delegate_(HttpServerDelegatePtr::Create(delegate.Pass())) {
42 DCHECK(delegate_); 42 DCHECK(delegate_);
43 delegate_.set_connection_error_handler([this]() { delete this; }); 43 delegate_.set_connection_error_handler([this]() { delete this; });
44 } 44 }
45 45
46 HttpServerImpl::~HttpServerImpl() {} 46 HttpServerImpl::~HttpServerImpl() {}
47 47
48 int HttpServerImpl::Start(NetAddressPtr local_address) { 48 int HttpServerImpl::Start(NetAddressPtr local_address) {
49 DCHECK(local_address); 49 DCHECK(local_address);
50 50
51 scoped_ptr<net::ServerSocket> socket( 51 scoped_ptr<net::ServerSocket> socket(
(...skipping 16 matching lines...) Expand all
68 int net_result = server_->GetLocalAddress(&address); 68 int net_result = server_->GetLocalAddress(&address);
69 if (net_result != net::OK) 69 if (net_result != net::OK)
70 return nullptr; 70 return nullptr;
71 71
72 return NetAddress::From(address); 72 return NetAddress::From(address);
73 } 73 }
74 74
75 void HttpServerImpl::OnConnect(int connection_id) { 75 void HttpServerImpl::OnConnect(int connection_id) {
76 DCHECK(connections_.find(connection_id) == connections_.end()); 76 DCHECK(connections_.find(connection_id) == connections_.end());
77 77
78 HttpConnectionPtr connection; 78 InterfaceHandle<HttpConnection> connection;
79 HttpConnectionDelegatePtr connection_delegate; 79 HttpConnectionDelegatePtr connection_delegate;
80 InterfaceRequest<HttpConnectionDelegate> delegate_request = 80 InterfaceRequest<HttpConnectionDelegate> delegate_request =
81 GetProxy(&connection_delegate); 81 GetProxy(&connection_delegate);
82 linked_ptr<HttpConnectionImpl> connection_impl( 82 linked_ptr<HttpConnectionImpl> connection_impl(
83 new HttpConnectionImpl(connection_id, this, connection_delegate.Pass(), 83 new HttpConnectionImpl(connection_id, this, connection_delegate.Pass(),
84 &connection)); 84 &connection));
85 85
86 connections_[connection_id] = connection_impl; 86 connections_[connection_id] = connection_impl;
87 87
88 delegate_->OnConnected(connection.Pass(), delegate_request.Pass()); 88 delegate_->OnConnected(connection.Pass(), delegate_request.Pass());
(...skipping 17 matching lines...) Expand all
106 DCHECK(connections_.find(connection_id) != connections_.end()); 106 DCHECK(connections_.find(connection_id) != connections_.end());
107 connections_[connection_id]->OnReceivedWebSocketMessage(data); 107 connections_[connection_id]->OnReceivedWebSocketMessage(data);
108 } 108 }
109 109
110 void HttpServerImpl::OnClose(int connection_id) { 110 void HttpServerImpl::OnClose(int connection_id) {
111 DCHECK(connections_.find(connection_id) != connections_.end()); 111 DCHECK(connections_.find(connection_id) != connections_.end());
112 connections_.erase(connection_id); 112 connections_.erase(connection_id);
113 } 113 }
114 114
115 } // namespace mojo 115 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/http_server_impl.h ('k') | mojo/services/network/interfaces/host_resolver.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698