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

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

Issue 1539863002: Convert Pass()→std::move() in mojo/services/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix missing forward declare that was masked by pre-existing incorrect #include ordering. Created 5 years 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/tcp_server_socket_impl.h" 5 #include "mojo/services/network/tcp_server_socket_impl.h"
6 6
7 #include <utility>
8
7 #include "mojo/services/network/net_adapters.h" 9 #include "mojo/services/network/net_adapters.h"
8 #include "mojo/services/network/net_address_type_converters.h" 10 #include "mojo/services/network/net_address_type_converters.h"
9 #include "mojo/services/network/tcp_connected_socket_impl.h" 11 #include "mojo/services/network/tcp_connected_socket_impl.h"
10 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
11 13
12 namespace mojo { 14 namespace mojo {
13 15
14 TCPServerSocketImpl::TCPServerSocketImpl( 16 TCPServerSocketImpl::TCPServerSocketImpl(
15 scoped_ptr<net::TCPSocket> socket, 17 scoped_ptr<net::TCPSocket> socket,
16 scoped_ptr<mojo::AppRefCount> app_refcount, 18 scoped_ptr<mojo::AppRefCount> app_refcount,
17 InterfaceRequest<TCPServerSocket> request) 19 InterfaceRequest<TCPServerSocket> request)
18 : socket_(socket.Pass()), app_refcount_(app_refcount.Pass()), 20 : socket_(std::move(socket)),
19 binding_(this, request.Pass()) { 21 app_refcount_(std::move(app_refcount)),
20 } 22 binding_(this, std::move(request)) {}
21 23
22 TCPServerSocketImpl::~TCPServerSocketImpl() { 24 TCPServerSocketImpl::~TCPServerSocketImpl() {
23 } 25 }
24 26
25 void TCPServerSocketImpl::Accept( 27 void TCPServerSocketImpl::Accept(
26 ScopedDataPipeConsumerHandle send_stream, 28 ScopedDataPipeConsumerHandle send_stream,
27 ScopedDataPipeProducerHandle receive_stream, 29 ScopedDataPipeProducerHandle receive_stream,
28 InterfaceRequest<TCPConnectedSocket> client_socket, 30 InterfaceRequest<TCPConnectedSocket> client_socket,
29 const AcceptCallback& callback) { 31 const AcceptCallback& callback) {
30 // One possible future enhancement would be to enqueue multiple Accept calls 32 // One possible future enhancement would be to enqueue multiple Accept calls
31 // on this object. This would allow the client to accept some number of 33 // on this object. This would allow the client to accept some number of
32 // incoming connections rapidly without doing an IPC round-trip. 34 // incoming connections rapidly without doing an IPC round-trip.
33 if (!pending_callback_.is_null()) { 35 if (!pending_callback_.is_null()) {
34 // Already have a pending accept on this socket. 36 // Already have a pending accept on this socket.
35 callback.Run(MakeNetworkError(net::ERR_UNEXPECTED), NetAddressPtr()); 37 callback.Run(MakeNetworkError(net::ERR_UNEXPECTED), NetAddressPtr());
36 return; 38 return;
37 } 39 }
38 40
39 int result = socket_->Accept( 41 int result = socket_->Accept(
40 &accepted_socket_, &accepted_address_, 42 &accepted_socket_, &accepted_address_,
41 base::Bind(&TCPServerSocketImpl::OnAcceptCompleted, 43 base::Bind(&TCPServerSocketImpl::OnAcceptCompleted,
42 base::Unretained(this))); 44 base::Unretained(this)));
43 if (result == net::OK || result == net::ERR_IO_PENDING) { 45 if (result == net::OK || result == net::ERR_IO_PENDING) {
44 pending_callback_ = callback; 46 pending_callback_ = callback;
45 pending_send_stream_ = send_stream.Pass(); 47 pending_send_stream_ = std::move(send_stream);
46 pending_receive_stream_ = receive_stream.Pass(); 48 pending_receive_stream_ = std::move(receive_stream);
47 pending_client_socket_ = client_socket.Pass(); 49 pending_client_socket_ = std::move(client_socket);
48 if (result == net::OK) 50 if (result == net::OK)
49 OnAcceptCompleted(net::OK); 51 OnAcceptCompleted(net::OK);
50 } else { 52 } else {
51 callback.Run(MakeNetworkError(result), NetAddressPtr()); 53 callback.Run(MakeNetworkError(result), NetAddressPtr());
52 } 54 }
53 } 55 }
54 56
55 void TCPServerSocketImpl::OnAcceptCompleted(int result) { 57 void TCPServerSocketImpl::OnAcceptCompleted(int result) {
56 if (result != net::OK) { 58 if (result != net::OK) {
57 pending_callback_.Run(MakeNetworkError(result), NetAddressPtr()); 59 pending_callback_.Run(MakeNetworkError(result), NetAddressPtr());
58 pending_send_stream_.reset(); 60 pending_send_stream_.reset();
59 pending_receive_stream_.reset(); 61 pending_receive_stream_.reset();
60 pending_client_socket_ = InterfaceRequest<TCPConnectedSocket>(); 62 pending_client_socket_ = InterfaceRequest<TCPConnectedSocket>();
61 } else { 63 } else {
62 new TCPConnectedSocketImpl( 64 new TCPConnectedSocketImpl(
63 accepted_socket_.Pass(), pending_send_stream_.Pass(), 65 std::move(accepted_socket_), std::move(pending_send_stream_),
64 pending_receive_stream_.Pass(), pending_client_socket_.Pass(), 66 std::move(pending_receive_stream_), std::move(pending_client_socket_),
65 app_refcount_->Clone()); 67 app_refcount_->Clone());
66 pending_callback_.Run(MakeNetworkError(net::OK), 68 pending_callback_.Run(MakeNetworkError(net::OK),
67 NetAddress::From(accepted_address_)); 69 NetAddress::From(accepted_address_));
68 } 70 }
69 71
70 pending_callback_ = AcceptCallback(); 72 pending_callback_ = AcceptCallback();
71 } 73 }
72 74
73 } // namespace mojo 75 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/network/tcp_connected_socket_impl.cc ('k') | mojo/services/network/udp_socket_apptest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698