OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "net/tools/quic/quic_client.h" | 5 #include "net/tools/quic/quic_client.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/files/file_enumerator.h" | 12 #include "base/files/file_enumerator.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/strings/string_util.h" | 14 #include "net/quic/platform/api/quic_text_utils.h" |
15 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
17 #include "net/tools/epoll_server/epoll_server.h" | 17 #include "net/tools/epoll_server/epoll_server.h" |
18 #include "net/tools/quic/test_tools/quic_client_peer.h" | 18 #include "net/tools/quic/test_tools/quic_client_peer.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 namespace test { | 22 namespace test { |
23 namespace { | 23 namespace { |
24 | 24 |
25 const char* kPathToFds = "/proc/self/fd"; | 25 const char* kPathToFds = "/proc/self/fd"; |
26 | 26 |
27 // Counts the number of open sockets for the current process. | 27 // Counts the number of open sockets for the current process. |
28 size_t NumOpenSocketFDs() { | 28 size_t NumOpenSocketFDs() { |
29 base::FileEnumerator fd_entries( | 29 base::FileEnumerator fd_entries( |
30 base::FilePath(kPathToFds), false, | 30 base::FilePath(kPathToFds), false, |
31 base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS); | 31 base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS); |
32 | 32 |
33 size_t socket_count = 0; | 33 size_t socket_count = 0; |
34 for (base::FilePath entry = fd_entries.Next(); !entry.empty(); | 34 for (base::FilePath entry = fd_entries.Next(); !entry.empty(); |
35 entry = fd_entries.Next()) { | 35 entry = fd_entries.Next()) { |
36 base::FilePath fd_path; | 36 base::FilePath fd_path; |
37 if (!base::ReadSymbolicLink(entry, &fd_path)) { | 37 if (!base::ReadSymbolicLink(entry, &fd_path)) { |
38 continue; | 38 continue; |
39 } | 39 } |
40 if (base::StartsWith(fd_path.value(), "socket:", | 40 if (QuicTextUtils::StartsWith(fd_path.value(), "socket:")) { |
41 base::CompareCase::SENSITIVE)) { | |
42 socket_count++; | 41 socket_count++; |
43 } | 42 } |
44 } | 43 } |
45 | 44 |
46 return socket_count; | 45 return socket_count; |
47 } | 46 } |
48 | 47 |
49 // Creates a new QuicClient and Initializes it. Caller is responsible for | 48 // Creates a new QuicClient and Initializes it. Caller is responsible for |
50 // deletion. | 49 // deletion. |
51 QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16_t port) { | 50 QuicClient* CreateAndInitializeQuicClient(EpollServer* eps, uint16_t port) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Clean up UDP sockets. | 110 // Clean up UDP sockets. |
112 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); | 111 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); |
113 EXPECT_EQ(number_of_open_fds + 2, NumOpenSocketFDs()); | 112 EXPECT_EQ(number_of_open_fds + 2, NumOpenSocketFDs()); |
114 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); | 113 QuicClientPeer::CleanUpUDPSocket(client.get(), client->GetLatestFD()); |
115 EXPECT_EQ(number_of_open_fds + 1, NumOpenSocketFDs()); | 114 EXPECT_EQ(number_of_open_fds + 1, NumOpenSocketFDs()); |
116 } | 115 } |
117 | 116 |
118 } // namespace | 117 } // namespace |
119 } // namespace test | 118 } // namespace test |
120 } // namespace net | 119 } // namespace net |
OLD | NEW |