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

Side by Side Diff: net/socket/transport_client_socket_unittest.cc

Issue 10108015: Upstream changes making ListenSocket an abstract class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add listen_socket.cc. Created 8 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 | Annotate | Revision Log
« no previous file with comments | « net/server/http_server.cc ('k') | net/tools/fetch/http_listen_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "net/socket/tcp_client_socket.h" 5 #include "net/socket/tcp_client_socket.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
8 #include "net/base/address_list.h" 10 #include "net/base/address_list.h"
9 #include "net/base/host_resolver.h" 11 #include "net/base/host_resolver.h"
10 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
11 #include "net/base/listen_socket.h"
12 #include "net/base/net_log.h" 13 #include "net/base/net_log.h"
13 #include "net/base/net_log_unittest.h" 14 #include "net/base/net_log_unittest.h"
14 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/tcp_listen_socket.h"
15 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
16 #include "net/base/winsock_init.h" 18 #include "net/base/winsock_init.h"
17 #include "net/socket/client_socket_factory.h" 19 #include "net/socket/client_socket_factory.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 #include "testing/platform_test.h" 21 #include "testing/platform_test.h"
20 22
21 namespace net { 23 namespace net {
22 24
23 namespace { 25 namespace {
24 26
(...skipping 13 matching lines...) Expand all
38 net_log_(CapturingNetLog::kUnbounded), 40 net_log_(CapturingNetLog::kUnbounded),
39 socket_factory_(ClientSocketFactory::GetDefaultFactory()), 41 socket_factory_(ClientSocketFactory::GetDefaultFactory()),
40 close_server_socket_on_next_send_(false) { 42 close_server_socket_on_next_send_(false) {
41 } 43 }
42 44
43 ~TransportClientSocketTest() { 45 ~TransportClientSocketTest() {
44 } 46 }
45 47
46 // Implement ListenSocketDelegate methods 48 // Implement ListenSocketDelegate methods
47 virtual void DidAccept(ListenSocket* server, ListenSocket* connection) { 49 virtual void DidAccept(ListenSocket* server, ListenSocket* connection) {
48 connected_sock_ = connection; 50 connected_sock_ = reinterpret_cast<TCPListenSocket*>(connection);
49 } 51 }
50 virtual void DidRead(ListenSocket*, const char* str, int len) { 52 virtual void DidRead(ListenSocket*, const char* str, int len) {
51 // TODO(dkegel): this might not be long enough to tickle some bugs. 53 // TODO(dkegel): this might not be long enough to tickle some bugs.
52 connected_sock_->Send(kServerReply, arraysize(kServerReply) - 1, 54 connected_sock_->Send(kServerReply, arraysize(kServerReply) - 1,
53 false /* Don't append line feed */); 55 false /* Don't append line feed */);
54 if (close_server_socket_on_next_send_) 56 if (close_server_socket_on_next_send_)
55 CloseServerSocket(); 57 CloseServerSocket();
56 } 58 }
57 virtual void DidClose(ListenSocket* sock) {} 59 virtual void DidClose(ListenSocket* sock) {}
58 60
(...skipping 24 matching lines...) Expand all
83 close_server_socket_on_next_send_ = close; 85 close_server_socket_on_next_send_ = close;
84 } 86 }
85 87
86 protected: 88 protected:
87 int listen_port_; 89 int listen_port_;
88 CapturingNetLog net_log_; 90 CapturingNetLog net_log_;
89 ClientSocketFactory* const socket_factory_; 91 ClientSocketFactory* const socket_factory_;
90 scoped_ptr<StreamSocket> sock_; 92 scoped_ptr<StreamSocket> sock_;
91 93
92 private: 94 private:
93 scoped_refptr<ListenSocket> listen_sock_; 95 scoped_refptr<TCPListenSocket> listen_sock_;
94 scoped_refptr<ListenSocket> connected_sock_; 96 scoped_refptr<TCPListenSocket> connected_sock_;
95 bool close_server_socket_on_next_send_; 97 bool close_server_socket_on_next_send_;
96 }; 98 };
97 99
98 void TransportClientSocketTest::SetUp() { 100 void TransportClientSocketTest::SetUp() {
99 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp(); 101 ::testing::TestWithParam<ClientSocketTestTypes>::SetUp();
100 102
101 // Find a free port to listen on 103 // Find a free port to listen on
102 ListenSocket *sock = NULL; 104 TCPListenSocket *sock = NULL;
103 int port; 105 int port;
104 // Range of ports to listen on. Shouldn't need to try many. 106 // Range of ports to listen on. Shouldn't need to try many.
105 const int kMinPort = 10100; 107 const int kMinPort = 10100;
106 const int kMaxPort = 10200; 108 const int kMaxPort = 10200;
107 #if defined(OS_WIN) 109 #if defined(OS_WIN)
108 EnsureWinsockInit(); 110 EnsureWinsockInit();
109 #endif 111 #endif
110 for (port = kMinPort; port < kMaxPort; port++) { 112 for (port = kMinPort; port < kMaxPort; port++) {
111 sock = ListenSocket::Listen("127.0.0.1", port, this); 113 sock = TCPListenSocket::CreateAndListen("127.0.0.1", port, this);
112 if (sock) 114 if (sock)
113 break; 115 break;
114 } 116 }
115 ASSERT_TRUE(sock != NULL); 117 ASSERT_TRUE(sock != NULL);
116 listen_sock_ = sock; 118 listen_sock_ = sock;
117 listen_port_ = port; 119 listen_port_ = port;
118 120
119 AddressList addr; 121 AddressList addr;
120 scoped_ptr<HostResolver> resolver( 122 scoped_ptr<HostResolver> resolver(
121 CreateSystemHostResolver(HostResolver::kDefaultParallelism, 123 CreateSystemHostResolver(HostResolver::kDefaultParallelism,
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 // Close the server socket, so there will at least be a 0-byte read. 441 // Close the server socket, so there will at least be a 0-byte read.
440 CloseServerSocket(); 442 CloseServerSocket();
441 443
442 rv = callback.WaitForResult(); 444 rv = callback.WaitForResult();
443 EXPECT_GE(rv, 0); 445 EXPECT_GE(rv, 0);
444 } 446 }
445 447
446 } // namespace 448 } // namespace
447 449
448 } // namespace net 450 } // namespace net
OLDNEW
« no previous file with comments | « net/server/http_server.cc ('k') | net/tools/fetch/http_listen_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698