| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_epoll_connection_helper.h" | 5 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/socket.h> | 8 #include <sys/socket.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "net/base/ip_endpoint.h" | 12 #include "net/base/ip_endpoint.h" |
| 13 #include "net/quic/crypto/quic_random.h" | 13 #include "net/quic/crypto/quic_random.h" |
| 14 #include "net/tools/epoll_server/epoll_server.h" | 14 #include "net/tools/epoll_server/epoll_server.h" |
| 15 #include "net/tools/quic/quic_socket_utils.h" | 15 #include "net/tools/quic/quic_socket_utils.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 namespace tools { | 18 namespace tools { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class QuicEpollAlarm : public QuicAlarm { | 22 class QuicEpollAlarm : public QuicAlarm { |
| 23 public: | 23 public: |
| 24 QuicEpollAlarm(EpollServer* epoll_server, QuicAlarm::Delegate* delegate) | 24 QuicEpollAlarm(EpollServer* epoll_server, |
| 25 : QuicAlarm(delegate), | 25 QuicArenaScopedPtr<Delegate> delegate) |
| 26 : QuicAlarm(std::move(delegate)), |
| 26 epoll_server_(epoll_server), | 27 epoll_server_(epoll_server), |
| 27 epoll_alarm_impl_(this) {} | 28 epoll_alarm_impl_(this) {} |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 void SetImpl() override { | 31 void SetImpl() override { |
| 31 DCHECK(deadline().IsInitialized()); | 32 DCHECK(deadline().IsInitialized()); |
| 32 epoll_server_->RegisterAlarm( | 33 epoll_server_->RegisterAlarm( |
| 33 deadline().Subtract(QuicTime::Zero()).ToMicroseconds(), | 34 deadline().Subtract(QuicTime::Zero()).ToMicroseconds(), |
| 34 &epoll_alarm_impl_); | 35 &epoll_alarm_impl_); |
| 35 } | 36 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 const QuicClock* QuicEpollConnectionHelper::GetClock() const { | 72 const QuicClock* QuicEpollConnectionHelper::GetClock() const { |
| 72 return &clock_; | 73 return &clock_; |
| 73 } | 74 } |
| 74 | 75 |
| 75 QuicRandom* QuicEpollConnectionHelper::GetRandomGenerator() { | 76 QuicRandom* QuicEpollConnectionHelper::GetRandomGenerator() { |
| 76 return random_generator_; | 77 return random_generator_; |
| 77 } | 78 } |
| 78 | 79 |
| 79 QuicAlarm* QuicEpollConnectionHelper::CreateAlarm( | 80 QuicAlarm* QuicEpollConnectionHelper::CreateAlarm( |
| 80 QuicAlarm::Delegate* delegate) { | 81 QuicAlarm::Delegate* delegate) { |
| 81 return new QuicEpollAlarm(epoll_server_, delegate); | 82 return new QuicEpollAlarm(epoll_server_, |
| 83 QuicArenaScopedPtr<QuicAlarm::Delegate>(delegate)); |
| 84 } |
| 85 |
| 86 QuicArenaScopedPtr<QuicAlarm> QuicEpollConnectionHelper::CreateAlarm( |
| 87 QuicArenaScopedPtr<QuicAlarm::Delegate> delegate, |
| 88 QuicConnectionArena* arena) { |
| 89 if (arena != nullptr) { |
| 90 return arena->New<QuicEpollAlarm>(epoll_server_, std::move(delegate)); |
| 91 } else { |
| 92 return QuicArenaScopedPtr<QuicAlarm>( |
| 93 new QuicEpollAlarm(epoll_server_, std::move(delegate))); |
| 94 } |
| 82 } | 95 } |
| 83 | 96 |
| 84 QuicBufferAllocator* QuicEpollConnectionHelper::GetBufferAllocator() { | 97 QuicBufferAllocator* QuicEpollConnectionHelper::GetBufferAllocator() { |
| 85 return &buffer_allocator_; | 98 return &buffer_allocator_; |
| 86 } | 99 } |
| 87 | 100 |
| 88 } // namespace tools | 101 } // namespace tools |
| 89 } // namespace net | 102 } // namespace net |
| OLD | NEW |