OLD | NEW |
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" |
(...skipping 22 matching lines...) Expand all Loading... |
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(HttpServerDelegatePtr delegate) |
41 : delegate_(delegate.Pass()) { | 41 : delegate_(delegate.Pass()) { |
42 DCHECK(delegate_); | 42 DCHECK(delegate_); |
43 delegate_.set_error_handler(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( |
52 new net::TCPServerSocket(nullptr, net::NetLog::Source())); | 52 new net::TCPServerSocket(nullptr, net::NetLog::Source())); |
53 int net_result = socket->Listen(local_address.To<net::IPEndPoint>(), | 53 int net_result = socket->Listen(local_address.To<net::IPEndPoint>(), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const std::string& data) { | 105 const std::string& data) { |
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 void HttpServerImpl::OnConnectionError() { | |
116 delete this; | |
117 } | |
118 | |
119 } // namespace mojo | 115 } // namespace mojo |
OLD | NEW |