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

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

Issue 634713002: Implement parts of the Mojo TCP interfaces. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/services/network/tcp_server_socket_impl.h"
6
7 #include "mojo/services/network/net_adapters.h"
8 #include "mojo/services/network/net_address_type_converters.h"
9 #include "mojo/services/network/tcp_connected_socket_impl.h"
10 #include "net/base/net_errors.h"
11
12 namespace mojo {
13
14 TCPServerSocketImpl::TCPServerSocketImpl(scoped_ptr<net::TCPSocket> socket)
15 : socket_(socket.Pass()) {
16 }
17
18 TCPServerSocketImpl::~TCPServerSocketImpl() {
19 }
20
21 void TCPServerSocketImpl::Accept(
22 ScopedDataPipeConsumerHandle send_stream,
23 ScopedDataPipeProducerHandle receive_stream,
24 InterfaceRequest<TCPConnectedSocket> client_socket,
25 const AcceptCallback& callback) {
26 // One possible future enhancement would be to enqueue multiple Accept calls
27 // on this object. This would allow the client to accept some number of
28 // incoming connections rapidly without doing an IPC round-trip.
29 if (!pending_callback_.is_null()) {
30 // Already have a pending accept on this socket.
31 callback.Run(MakeNetworkError(net::ERR_UNEXPECTED), NetAddressPtr());
32 return;
33 }
34
35 int result = socket_->Accept(
36 &accepted_socket_, &accepted_address_,
37 base::Bind(&TCPServerSocketImpl::OnAcceptCompleted,
38 base::Unretained(this)));
39 if (result == net::ERR_IO_PENDING) {
40 pending_callback_ = callback;
41 pending_send_stream_ = send_stream.Pass();
42 pending_receive_stream_ = receive_stream.Pass();
43 pending_client_socket_ = client_socket.Pass();
44 } else {
45 callback.Run(MakeNetworkError(result), NetAddressPtr());
yzshen1 2014/10/07 20:14:34 We need to call into OnAcceptCompleted for this ca
46 }
47 }
48
49 void TCPServerSocketImpl::OnAcceptCompleted(int result) {
50 if (result != net::OK) {
51 pending_callback_.Run(MakeNetworkError(result), NetAddressPtr());
yzshen1 2014/10/07 20:14:34 Please release those pending_XXX members.
52 } else {
53 BindToRequest(new TCPConnectedSocketImpl(
54 accepted_socket_.Pass(),
55 pending_send_stream_.Pass(),
56 pending_receive_stream_.Pass()), &pending_client_socket_);
57 pending_callback_.Run(
58 MakeNetworkError(net::OK),
59 mojo::TypeConverter<NetAddressPtr, net::IPEndPoint>::Convert(
yzshen1 2014/10/07 20:14:34 you could do NetAddress::From(blah).
60 accepted_address_));
61 }
62
63 pending_callback_ = AcceptCallback();
64 }
65
66 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698