| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/epoll_server/epoll_server.h" | 5 #include "net/tools/epoll_server/epoll_server.h" |
| 6 | 6 |
| 7 #include <unistd.h> // For read, pipe, close and write. | 7 #include <unistd.h> // For read, pipe, close and write. |
| 8 #include <stdlib.h> // for abort | 8 #include <stdlib.h> // for abort |
| 9 #include <errno.h> // for errno and strerror_r | 9 #include <errno.h> // for errno and strerror_r |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 erase_it = i; | 140 erase_it = i; |
| 141 ++i; | 141 ++i; |
| 142 alarm_map_.erase(erase_it); | 142 alarm_map_.erase(erase_it); |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 | 145 |
| 146 EpollServer::~EpollServer() { | 146 EpollServer::~EpollServer() { |
| 147 DCHECK_EQ(in_shutdown_, false); | 147 DCHECK_EQ(in_shutdown_, false); |
| 148 in_shutdown_ = true; | 148 in_shutdown_ = true; |
| 149 #ifdef EPOLL_SERVER_EVENT_TRACING | 149 #ifdef EPOLL_SERVER_EVENT_TRACING |
| 150 LOG(INFO) << "\n" << event_recorder_; | 150 VLOG(0) << "\n" << event_recorder_; |
| 151 #endif | 151 #endif |
| 152 VLOG(2) << "Shutting down epoll server "; | 152 VLOG(2) << "Shutting down epoll server "; |
| 153 CleanupFDToCBMap(); | 153 CleanupFDToCBMap(); |
| 154 | 154 |
| 155 LIST_INIT(&ready_list_); | 155 LIST_INIT(&ready_list_); |
| 156 LIST_INIT(&tmp_list_); | 156 LIST_INIT(&tmp_list_); |
| 157 | 157 |
| 158 CleanupTimeToAlarmCBMap(); | 158 CleanupTimeToAlarmCBMap(); |
| 159 | 159 |
| 160 close(read_fd_); | 160 close(read_fd_); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 | 630 |
| 631 void EpollServer::WaitForEventsAndCallHandleEvents(int64 timeout_in_us, | 631 void EpollServer::WaitForEventsAndCallHandleEvents(int64 timeout_in_us, |
| 632 struct epoll_event events[], | 632 struct epoll_event events[], |
| 633 int events_size) { | 633 int events_size) { |
| 634 if (timeout_in_us == 0 || ready_list_.lh_first != NULL) { | 634 if (timeout_in_us == 0 || ready_list_.lh_first != NULL) { |
| 635 // If ready list is not empty, then don't sleep at all. | 635 // If ready list is not empty, then don't sleep at all. |
| 636 timeout_in_us = 0; | 636 timeout_in_us = 0; |
| 637 } else if (timeout_in_us < 0) { | 637 } else if (timeout_in_us < 0) { |
| 638 LOG(INFO) << "Negative epoll timeout: " << timeout_in_us | 638 VLOG(0) << "Negative epoll timeout: " << timeout_in_us |
| 639 << "us; epoll will wait forever for events."; | 639 << "us; epoll will wait forever for events."; |
| 640 // If timeout_in_us is < 0 we are supposed to Wait forever. This means we | 640 // If timeout_in_us is < 0 we are supposed to Wait forever. This means we |
| 641 // should set timeout_in_us to -1000 so we will | 641 // should set timeout_in_us to -1000 so we will |
| 642 // Wait(-1000/1000) == Wait(-1) == Wait forever. | 642 // Wait(-1000/1000) == Wait(-1) == Wait forever. |
| 643 timeout_in_us = -1000; | 643 timeout_in_us = -1000; |
| 644 } else { | 644 } else { |
| 645 // If timeout is specified, and the ready list is empty. | 645 // If timeout is specified, and the ready list is empty. |
| 646 if (timeout_in_us < 1000) { | 646 if (timeout_in_us < 1000) { |
| 647 timeout_in_us = 1000; | 647 timeout_in_us = 1000; |
| 648 } | 648 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 811 |
| 812 // If the alarm was registered, unregister it. | 812 // If the alarm was registered, unregister it. |
| 813 void EpollAlarm::UnregisterIfRegistered() { | 813 void EpollAlarm::UnregisterIfRegistered() { |
| 814 if (!registered_) { | 814 if (!registered_) { |
| 815 return; | 815 return; |
| 816 } | 816 } |
| 817 eps_->UnregisterAlarm(token_); | 817 eps_->UnregisterAlarm(token_); |
| 818 } | 818 } |
| 819 | 819 |
| 820 } // namespace net | 820 } // namespace net |
| OLD | NEW |