OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/renderer_host/p2p/socket_host_tcp_server.h" | 5 #include "content/browser/renderer_host/p2p/socket_host_tcp_server.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" | 9 #include "content/browser/renderer_host/p2p/socket_host_tcp.h" |
10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" | 10 #include "content/browser/renderer_host/p2p/socket_host_test_utils.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // bases logic on the null-ness of |accept_callback_| in the bound | 40 // bases logic on the null-ness of |accept_callback_| in the bound |
41 // callback. | 41 // callback. |
42 net::CompletionCallback cb = accept_callback_; | 42 net::CompletionCallback cb = accept_callback_; |
43 accept_callback_.Reset(); | 43 accept_callback_.Reset(); |
44 cb.Run(net::OK); | 44 cb.Run(net::OK); |
45 } else { | 45 } else { |
46 incoming_sockets_.push_back(socket); | 46 incoming_sockets_.push_back(socket); |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 virtual int Listen(const net::IPEndPoint& address, int backlog) OVERRIDE { | 50 virtual int Listen(const net::IPEndPoint& address, int backlog) override { |
51 local_address_ = address; | 51 local_address_ = address; |
52 listening_ = true; | 52 listening_ = true; |
53 return net::OK; | 53 return net::OK; |
54 } | 54 } |
55 | 55 |
56 virtual int GetLocalAddress(net::IPEndPoint* address) const OVERRIDE { | 56 virtual int GetLocalAddress(net::IPEndPoint* address) const override { |
57 *address = local_address_; | 57 *address = local_address_; |
58 return net::OK; | 58 return net::OK; |
59 } | 59 } |
60 | 60 |
61 virtual int Accept(scoped_ptr<net::StreamSocket>* socket, | 61 virtual int Accept(scoped_ptr<net::StreamSocket>* socket, |
62 const net::CompletionCallback& callback) OVERRIDE { | 62 const net::CompletionCallback& callback) override { |
63 DCHECK(socket); | 63 DCHECK(socket); |
64 if (!incoming_sockets_.empty()) { | 64 if (!incoming_sockets_.empty()) { |
65 socket->reset(incoming_sockets_.front()); | 65 socket->reset(incoming_sockets_.front()); |
66 incoming_sockets_.pop_front(); | 66 incoming_sockets_.pop_front(); |
67 return net::OK; | 67 return net::OK; |
68 } else { | 68 } else { |
69 accept_socket_ = socket; | 69 accept_socket_ = socket; |
70 accept_callback_ = callback; | 70 accept_callback_ = callback; |
71 return net::ERR_IO_PENDING; | 71 return net::ERR_IO_PENDING; |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 private: | 75 private: |
76 bool listening_; | 76 bool listening_; |
77 | 77 |
78 net::IPEndPoint local_address_; | 78 net::IPEndPoint local_address_; |
79 | 79 |
80 scoped_ptr<net::StreamSocket>* accept_socket_; | 80 scoped_ptr<net::StreamSocket>* accept_socket_; |
81 net::CompletionCallback accept_callback_; | 81 net::CompletionCallback accept_callback_; |
82 | 82 |
83 std::list<net::StreamSocket*> incoming_sockets_; | 83 std::list<net::StreamSocket*> incoming_sockets_; |
84 }; | 84 }; |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 namespace content { | 88 namespace content { |
89 | 89 |
90 class P2PSocketHostTcpServerTest : public testing::Test { | 90 class P2PSocketHostTcpServerTest : public testing::Test { |
91 protected: | 91 protected: |
92 virtual void SetUp() OVERRIDE { | 92 virtual void SetUp() override { |
93 socket_ = new FakeServerSocket(); | 93 socket_ = new FakeServerSocket(); |
94 socket_host_.reset( | 94 socket_host_.reset( |
95 new P2PSocketHostTcpServer(&sender_, 0, P2P_SOCKET_TCP_CLIENT)); | 95 new P2PSocketHostTcpServer(&sender_, 0, P2P_SOCKET_TCP_CLIENT)); |
96 socket_host_->socket_.reset(socket_); | 96 socket_host_->socket_.reset(socket_); |
97 | 97 |
98 EXPECT_CALL(sender_, Send( | 98 EXPECT_CALL(sender_, Send( |
99 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) | 99 MatchMessage(static_cast<uint32>(P2PMsg_OnSocketCreated::ID)))) |
100 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); | 100 .WillOnce(DoAll(DeleteArg<0>(), Return(true))); |
101 | 101 |
102 P2PHostAndIPEndPoint dest; | 102 P2PHostAndIPEndPoint dest; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_EQ(incoming1, GetSocketFormTcpSocketHost( | 165 EXPECT_EQ(incoming1, GetSocketFormTcpSocketHost( |
166 reinterpret_cast<P2PSocketHostTcp*>(new_host1.get()))); | 166 reinterpret_cast<P2PSocketHostTcp*>(new_host1.get()))); |
167 scoped_ptr<P2PSocketHost> new_host2( | 167 scoped_ptr<P2PSocketHost> new_host2( |
168 socket_host_->AcceptIncomingTcpConnection(addr2, kAcceptedSocketId2)); | 168 socket_host_->AcceptIncomingTcpConnection(addr2, kAcceptedSocketId2)); |
169 ASSERT_TRUE(new_host2.get() != NULL); | 169 ASSERT_TRUE(new_host2.get() != NULL); |
170 EXPECT_EQ(incoming2, GetSocketFormTcpSocketHost( | 170 EXPECT_EQ(incoming2, GetSocketFormTcpSocketHost( |
171 reinterpret_cast<P2PSocketHostTcp*>(new_host2.get()))); | 171 reinterpret_cast<P2PSocketHostTcp*>(new_host2.get()))); |
172 } | 172 } |
173 | 173 |
174 } // namespace content | 174 } // namespace content |
OLD | NEW |