Commit 4149fc5a authored by Dan Zhang's avatar Dan Zhang Committed by Commit Bot

Replace current EpollServer with SimpleEpollServer in QUICHE.


R=rch@chromium.org

Change-Id: I345efbb9d5ba4ba21eb50433b6d579307dffbb7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1568848
Commit-Queue: Dan Zhang <danzh@chromium.org>
Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654435}
parent bce20da1
......@@ -3076,8 +3076,20 @@ if (is_linux || is_mac) {
if (is_linux) {
static_library("epoll_server") {
sources = [
"tools/epoll_server/epoll_server.cc",
"tools/epoll_server/epoll_server.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_bug.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_export.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_logging.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_ptr_util.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_thread.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_time.h",
"third_party/quiche/src/epoll_server/simple_epoll_server.cc",
"third_party/quiche/src/epoll_server/simple_epoll_server.h",
"tools/epoll_server/platform/impl/epoll_bug_impl.h",
"tools/epoll_server/platform/impl/epoll_export_impl.h",
"tools/epoll_server/platform/impl/epoll_logging_impl.h",
"tools/epoll_server/platform/impl/epoll_ptr_util_impl.h",
"tools/epoll_server/platform/impl/epoll_thread_impl.h",
"tools/epoll_server/platform/impl/epoll_time_impl.h",
]
deps = [
":net",
......@@ -3199,6 +3211,25 @@ if (is_android || is_linux) {
}
}
source_set("epoll_server_test_tools") {
testonly = true
sources = [
"third_party/quiche/src/epoll_server/platform/api/epoll_address_test_utils.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_expect_bug.h",
"third_party/quiche/src/epoll_server/platform/api/epoll_test.h",
"tools/epoll_server/platform/impl/epoll_address_test_utils_impl.h",
"tools/epoll_server/platform/impl/epoll_expect_bug_impl.h",
"tools/epoll_server/platform/impl/epoll_test_impl.h",
]
deps = [
":net",
":test_support",
"//base",
"//testing/gmock",
"//testing/gtest",
]
}
source_set("spdy_test_tools") {
testonly = true
sources = [
......@@ -3369,6 +3400,8 @@ source_set("quic_test_tools") {
if (is_linux) {
sources += [
"third_party/quiche/src/epoll_server/fake_simple_epoll_server.cc",
"third_party/quiche/src/epoll_server/fake_simple_epoll_server.h",
"third_party/quiche/src/quic/test_tools/bad_packet_writer.cc",
"third_party/quiche/src/quic/test_tools/bad_packet_writer.h",
"third_party/quiche/src/quic/test_tools/limited_mtu_test_writer.cc",
......@@ -3387,8 +3420,6 @@ source_set("quic_test_tools") {
"third_party/quiche/src/quic/test_tools/quic_test_server.h",
"third_party/quiche/src/quic/test_tools/server_thread.cc",
"third_party/quiche/src/quic/test_tools/server_thread.h",
"tools/epoll_server/fake_epoll_server.cc",
"tools/epoll_server/fake_epoll_server.h",
]
deps += [
":epoll_quic_tools",
......@@ -5557,6 +5588,7 @@ test("net_unittests") {
"quic/platform/impl/quic_flags_test.cc",
"quic/platform/impl/quic_linux_socket_utils_test.cc",
"quic/platform/impl/quic_socket_utils_test.cc",
"third_party/quiche/src/epoll_server/simple_epoll_server_test.cc",
"third_party/quiche/src/quic/core/chlo_extractor_test.cc",
"third_party/quiche/src/quic/core/http/end_to_end_test.cc",
"third_party/quiche/src/quic/core/http/quic_spdy_client_session_test.cc",
......@@ -5579,6 +5611,7 @@ test("net_unittests") {
deps += [
":epoll_quic_tools",
":epoll_server",
":epoll_server_test_tools",
]
}
......
......@@ -4,13 +4,13 @@
#include "net/quic/platform/impl/quic_epoll_clock.h"
#include "net/third_party/quiche/src/epoll_server/simple_epoll_server.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_flag_utils.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
#include "net/tools/epoll_server/epoll_server.h"
namespace quic {
QuicEpollClock::QuicEpollClock(net::EpollServer* epoll_server)
QuicEpollClock::QuicEpollClock(epoll_server::SimpleEpollServer* epoll_server)
: epoll_server_(epoll_server), largest_time_(QuicTime::Zero()) {}
QuicEpollClock::~QuicEpollClock() {}
......
......@@ -10,17 +10,19 @@
#include "net/third_party/quiche/src/quic/core/quic_time.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_clock.h"
namespace quic {} // namespace quic
namespace net {
class EpollServer;
} // namespace net
namespace epoll_server {
class SimpleEpollServer;
} // namespace epoll_server
namespace quic {
// Clock to efficiently retrieve an approximately accurate time from an
// net::EpollServer.
class QuicEpollClock : public QuicClock {
public:
explicit QuicEpollClock(net::EpollServer* epoll_server);
explicit QuicEpollClock(epoll_server::SimpleEpollServer* epoll_server);
~QuicEpollClock() override;
// Returns the approximate current time as a QuicTime object.
......@@ -40,7 +42,7 @@ class QuicEpollClock : public QuicClock {
const QuicWallTime& walltime) const override;
protected:
net::EpollServer* epoll_server_;
epoll_server::SimpleEpollServer* epoll_server_;
// Largest time returned from Now() so far.
mutable QuicTime largest_time_;
......
......@@ -4,9 +4,9 @@
#include "net/quic/platform/impl/quic_epoll_clock.h"
#include "net/third_party/quiche/src/epoll_server/fake_simple_epoll_server.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
#include "net/third_party/quiche/src/quic/platform/api/quic_test.h"
#include "net/tools/epoll_server/fake_epoll_server.h"
namespace quic {
namespace test {
......@@ -14,7 +14,7 @@ namespace test {
class QuicEpollClockTest : public QuicTest {};
TEST_F(QuicEpollClockTest, ApproximateNowInUsec) {
FakeEpollServer epoll_server;
epoll_server::test::FakeSimpleEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
epoll_server.set_now_in_usec(1000000);
......@@ -35,7 +35,7 @@ TEST_F(QuicEpollClockTest, ApproximateNowInUsec) {
}
TEST_F(QuicEpollClockTest, NowInUsec) {
FakeEpollServer epoll_server;
epoll_server::test::FakeSimpleEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
epoll_server.set_now_in_usec(1000000);
......@@ -47,7 +47,7 @@ TEST_F(QuicEpollClockTest, NowInUsec) {
TEST_F(QuicEpollClockTest, MonotonicityWithRealEpollClock) {
SetQuicReloadableFlag(quic_monotonic_epoll_clock, true);
net::EpollServer epoll_server;
epoll_server::SimpleEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
quic::QuicTime last_now = clock.Now();
......@@ -61,7 +61,7 @@ TEST_F(QuicEpollClockTest, MonotonicityWithRealEpollClock) {
}
TEST_F(QuicEpollClockTest, MonotonicityWithFakeEpollClock) {
FakeEpollServer epoll_server;
epoll_server::test::FakeSimpleEpollServer epoll_server;
QuicEpollClock clock(&epoll_server);
epoll_server.set_now_in_usec(100);
......
......@@ -10,14 +10,14 @@
#ifndef NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_IMPL_H_
#define NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_IMPL_H_
#include "net/tools/epoll_server/epoll_server.h"
#include "net/third_party/quiche/src/epoll_server/simple_epoll_server.h"
namespace quic {
using QuicEpollServerImpl = ::net::EpollServer;
using QuicEpollEventImpl = ::net::EpollEvent;
using QuicEpollAlarmBaseImpl = ::net::EpollAlarm;
using QuicEpollCallbackInterfaceImpl = ::net::EpollCallbackInterface;
using QuicEpollServerImpl = epoll_server::SimpleEpollServer;
using QuicEpollEventImpl = epoll_server::EpollEvent;
using QuicEpollAlarmBaseImpl = epoll_server::EpollAlarm;
using QuicEpollCallbackInterfaceImpl = epoll_server::EpollCallbackInterface;
} // namespace quic
......
......@@ -5,8 +5,8 @@
#ifndef NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_
#define NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_
#include "net/tools/epoll_server/fake_epoll_server.h"
#include "net/third_party/quiche/src/epoll_server/fake_simple_epoll_server.h"
using QuicFakeEpollServerImpl = quic::test::FakeEpollServer;
using QuicFakeEpollServerImpl = epoll_server::test::FakeSimpleEpollServer;
#endif // NET_QUIC_PLATFORM_IMPL_QUIC_EPOLL_TEST_TOOLS_IMPL_H_
This diff is collapsed.
This diff is collapsed.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/tools/epoll_server/fake_epoll_server.h"
namespace quic {
namespace test {
FakeTimeEpollServer::FakeTimeEpollServer() : now_in_usec_(0) {}
FakeTimeEpollServer::~FakeTimeEpollServer() = default;
int64_t FakeTimeEpollServer::NowInUsec() const {
return now_in_usec_;
}
FakeEpollServer::FakeEpollServer() : until_in_usec_(-1) {}
FakeEpollServer::~FakeEpollServer() = default;
int FakeEpollServer::epoll_wait_impl(int epfd,
struct epoll_event* events,
int max_events,
int timeout_in_ms) {
int num_events = 0;
while (!event_queue_.empty() && num_events < max_events &&
event_queue_.begin()->first <= NowInUsec() &&
((until_in_usec_ == -1) ||
(event_queue_.begin()->first < until_in_usec_))) {
int64_t event_time_in_usec = event_queue_.begin()->first;
events[num_events] = event_queue_.begin()->second;
if (event_time_in_usec > NowInUsec()) {
set_now_in_usec(event_time_in_usec);
}
event_queue_.erase(event_queue_.begin());
++num_events;
}
if (num_events == 0) { // then we'd have waited 'till the timeout.
if (until_in_usec_ < 0) { // then we don't care what the final time is.
if (timeout_in_ms > 0) {
AdvanceBy(timeout_in_ms * 1000);
}
} else { // except we assume that we don't wait for the timeout
// period if until_in_usec_ is a positive number.
set_now_in_usec(until_in_usec_);
// And reset until_in_usec_ to signal no waiting (as
// the AdvanceByExactly* stuff is meant to be one-shot,
// as are all similar net::EpollServer functions)
until_in_usec_ = -1;
}
}
if (until_in_usec_ >= 0) {
CHECK(until_in_usec_ >= NowInUsec());
}
return num_events;
}
} // namespace test
} // namespace quic
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#define NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
#include <stddef.h>
#include <stdint.h>
#include <unordered_map>
#include <unordered_set>
#include "base/logging.h"
#include "base/macros.h"
#include "net/tools/epoll_server/epoll_server.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace quic {
namespace test {
// Unlike the full FakeEpollServer, this only lies about the time but lets
// fd events operate normally. Usefully when interacting with real backends
// but wanting to skip forward in time to trigger timeouts.
class FakeTimeEpollServer : public net::EpollServer {
public:
FakeTimeEpollServer();
~FakeTimeEpollServer() override;
// Replaces the net::EpollServer NowInUsec.
int64_t NowInUsec() const override;
void set_now_in_usec(int64_t nius) { now_in_usec_ = nius; }
// Advances the virtual 'now' by advancement_usec.
void AdvanceBy(int64_t advancement_usec) {
set_now_in_usec(NowInUsec() + advancement_usec);
}
// Advances the virtual 'now' by advancement_usec, and
// calls WaitForEventAndExecteCallbacks.
// Note that the WaitForEventsAndExecuteCallbacks invocation
// may cause NowInUs to advance beyond what was specified here.
// If that is not desired, use the AdvanceByExactly calls.
void AdvanceByAndWaitForEventsAndExecuteCallbacks(int64_t advancement_usec) {
AdvanceBy(advancement_usec);
WaitForEventsAndExecuteCallbacks();
}
private:
int64_t now_in_usec_;
DISALLOW_COPY_AND_ASSIGN(FakeTimeEpollServer);
};
class FakeEpollServer : public FakeTimeEpollServer {
public: // type definitions
using EventQueue = std::unordered_multimap<int64_t, struct epoll_event>;
FakeEpollServer();
~FakeEpollServer() override;
// time_in_usec is the time at which the event specified
// by 'ee' will be delivered. Note that it -is- possible
// to add an event for a time which has already been passed..
// .. upon the next time that the callbacks are invoked,
// all events which are in the 'past' will be delivered.
void AddEvent(int64_t time_in_usec, const struct epoll_event& ee) {
event_queue_.insert(std::make_pair(time_in_usec, ee));
}
// Advances the virtual 'now' by advancement_usec,
// and ensure that the next invocation of
// WaitForEventsAndExecuteCallbacks goes no farther than
// advancement_usec from the current time.
void AdvanceByExactly(int64_t advancement_usec) {
until_in_usec_ = NowInUsec() + advancement_usec;
set_now_in_usec(NowInUsec() + advancement_usec);
}
// As above, except calls WaitForEventsAndExecuteCallbacks.
void AdvanceByExactlyAndCallCallbacks(int64_t advancement_usec) {
AdvanceByExactly(advancement_usec);
WaitForEventsAndExecuteCallbacks();
}
std::unordered_set<AlarmCB*>::size_type NumberOfAlarms() const {
return all_alarms_.size();
}
protected: // functions
// These functions do nothing here, as we're not actually
// using the epoll_* syscalls.
void DelFD(int fd) const override {}
void AddFD(int fd, int event_mask) const override {}
void ModFD(int fd, int event_mask) const override {}
// Replaces the epoll_server's epoll_wait_impl.
int epoll_wait_impl(int epfd,
struct epoll_event* events,
int max_events,
int timeout_in_ms) override;
void SetNonblocking(int fd) override {}
private: // members
EventQueue event_queue_;
int64_t until_in_usec_;
DISALLOW_COPY_AND_ASSIGN(FakeEpollServer);
};
} // namespace test
} // namespace quic
#endif // NET_TOOLS_EPOLL_SERVER_FAKE_EPOLL_SERVER_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_ADDRESS_TEST_UTILS_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_ADDRESS_TEST_UTILS_IMPL_H_
#include <netinet/in.h>
namespace epoll_server {
int AddressFamilyUnderTestImpl() {
return AF_INET;
}
} // namespace epoll_server
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_ADDRESS_TEST_UTILS_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_BUG_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_BUG_IMPL_H_
#include "net/tools/epoll_server/platform/impl/epoll_logging_impl.h"
#define EPOLL_BUG_IMPL EPOLL_LOG_IMPL(DFATAL)
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_BUG_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPECT_BUG_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPECT_BUG_IMPL_H_
#include "net/test/gtest_util.h"
#define EXPECT_EPOLL_BUG_IMPL EXPECT_DFATAL
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPECT_BUG_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/base/net_export.h"
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPORT_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPORT_IMPL_H_
#define EPOLL_EXPORT NET_EXPORT
#define EPOLL_EXPORT_PRIVATE NET_EXPORT_PRIVATE
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_EXPORT_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_LOGGING_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_LOGGING_IMPL_H_
#include "base/logging.h"
#define EPOLL_CHROMIUM_LOG_INFO VLOG(1)
#define EPOLL_CHROMIUM_LOG_WARNING DLOG(WARNING)
#define EPOLL_CHROMIUM_LOG_ERROR DLOG(ERROR)
#define EPOLL_CHROMIUM_LOG_FATAL LOG(FATAL)
#define EPOLL_CHROMIUM_LOG_DFATAL LOG(DFATAL)
#define EPOLL_LOG_IMPL(severity) EPOLL_CHROMIUM_LOG_##severity
#define EPOLL_VLOG_IMPL(verbose_level) VLOG(verbose_level)
#define EPOLL_DVLOG_IMPL(verbose_level) DVLOG(verbose_level)
#define EPOLL_PLOG_IMPL(severity) DVLOG(1)
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_LOGGING_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <memory>
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_PTR_UTIL_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_PTR_UTIL_IMPL_H_
namespace epoll_server {
template <typename T, typename... Args>
std::unique_ptr<T> EpollMakeUniqueImpl(Args&&... args) {
return std::make_unique<T>(std::forward<Args>(args)...);
}
} // namespace epoll_server
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_PTR_UTIL_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TEST_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TEST_IMPL_H_
#include "testing/gtest/include/gtest/gtest.h" // IWYU pragma: export
using EpollTestImpl = ::testing::Test;
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TEST_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_THREAD_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_THREAD_IMPL_H_
#include "base/threading/simple_thread.h"
namespace epoll_server {
// A class representing a thread of execution in epoll_server.
class EpollThreadImpl : public base::SimpleThread {
public:
EpollThreadImpl(const std::string& string) : base::SimpleThread(string) {}
EpollThreadImpl(const EpollThreadImpl&) = delete;
EpollThreadImpl& operator=(const EpollThreadImpl&) = delete;
};
} // namespace epoll_server
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_THREAD_IMPL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TIME_IMPL_H_
#define NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TIME_IMPL_H_
#include "base/time/time.h"
namespace epoll_server {
inline int64_t WallTimeNowInUsecImpl() {
return (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
}
} // namespace epoll_server
#endif // NET_TOOLS_EPOLL_SERVER_PLATFORM_IMPL_EPOLL_TIME_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment