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 #ifndef NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ | 5 #ifndef NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ |
6 #define NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ | 6 #define NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ |
7 | 7 |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <sys/queue.h> | 11 #include <sys/queue.h> |
12 | 12 |
13 #include <map> | 13 #include <map> |
14 #include <string> | 14 #include <string> |
| 15 #include <unordered_map> |
| 16 #include <unordered_set> |
15 #include <vector> | 17 #include <vector> |
16 | 18 |
17 // #define EPOLL_SERVER_EVENT_TRACING 1 | 19 // #define EPOLL_SERVER_EVENT_TRACING 1 |
18 // | 20 // |
19 // Defining EPOLL_SERVER_EVENT_TRACING | 21 // Defining EPOLL_SERVER_EVENT_TRACING |
20 // causes code to exist which didn't before. | 22 // causes code to exist which didn't before. |
21 // This code tracks each event generated by the epollserver, | 23 // This code tracks each event generated by the epollserver, |
22 // as well as providing a per-fd-registered summary of | 24 // as well as providing a per-fd-registered summary of |
23 // events. Note that enabling this code vastly slows | 25 // events. Note that enabling this code vastly slows |
24 // down operations, and uses substantially more | 26 // down operations, and uses substantially more |
25 // memory. For these reasons, it should only be enabled by developers doing | 27 // memory. For these reasons, it should only be enabled by developers doing |
26 // development at their workstations. | 28 // development at their workstations. |
27 // | 29 // |
28 // A structure called 'EventRecorder' will exist when | 30 // A structure called 'EventRecorder' will exist when |
29 // the macro is defined. See the EventRecorder class interface | 31 // the macro is defined. See the EventRecorder class interface |
30 // within the EpollServer class for more details. | 32 // within the EpollServer class for more details. |
31 #ifdef EPOLL_SERVER_EVENT_TRACING | 33 #ifdef EPOLL_SERVER_EVENT_TRACING |
32 #include <ostream> | 34 #include <ostream> |
33 #include "base/logging.h" | 35 #include "base/logging.h" |
34 #endif | 36 #endif |
35 | 37 |
36 #include "base/compiler_specific.h" | 38 #include "base/compiler_specific.h" |
37 #include "base/containers/hash_tables.h" | |
38 #include "base/macros.h" | 39 #include "base/macros.h" |
39 #include "base/memory/scoped_ptr.h" | 40 #include "base/memory/scoped_ptr.h" |
40 #include <sys/epoll.h> | 41 #include <sys/epoll.h> |
41 | 42 |
42 namespace net { | 43 namespace net { |
43 | 44 |
44 class EpollServer; | 45 class EpollServer; |
45 class EpollAlarmCallbackInterface; | 46 class EpollAlarmCallbackInterface; |
46 class ReadPipeCallback; | 47 class ReadPipeCallback; |
47 | 48 |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 mutable bool in_use; | 547 mutable bool in_use; |
547 }; | 548 }; |
548 | 549 |
549 // Custom hash function to be used by hash_set. | 550 // Custom hash function to be used by hash_set. |
550 struct CBAndEventMaskHash { | 551 struct CBAndEventMaskHash { |
551 size_t operator()(const CBAndEventMask& cb_and_eventmask) const { | 552 size_t operator()(const CBAndEventMask& cb_and_eventmask) const { |
552 return static_cast<size_t>(cb_and_eventmask.fd); | 553 return static_cast<size_t>(cb_and_eventmask.fd); |
553 } | 554 } |
554 }; | 555 }; |
555 | 556 |
556 typedef base::hash_set<CBAndEventMask, CBAndEventMaskHash> FDToCBMap; | 557 using FDToCBMap = std::unordered_set<CBAndEventMask, CBAndEventMaskHash>; |
557 | 558 |
558 // the following four functions are OS-specific, and are likely | 559 // the following four functions are OS-specific, and are likely |
559 // to be changed in a subclass if the poll/select method is changed | 560 // to be changed in a subclass if the poll/select method is changed |
560 // from epoll. | 561 // from epoll. |
561 | 562 |
562 // Summary: | 563 // Summary: |
563 // Deletes a file-descriptor from the set of FDs that should be | 564 // Deletes a file-descriptor from the set of FDs that should be |
564 // monitored with epoll. | 565 // monitored with epoll. |
565 // Note that this only deals with modifying data relating -directly- | 566 // Note that this only deals with modifying data relating -directly- |
566 // with the epoll call-- it does not modify any data within the | 567 // with the epoll call-- it does not modify any data within the |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 size_t operator()(AlarmCB*const& p) const { | 658 size_t operator()(AlarmCB*const& p) const { |
658 return reinterpret_cast<size_t>(p); | 659 return reinterpret_cast<size_t>(p); |
659 } | 660 } |
660 }; | 661 }; |
661 | 662 |
662 | 663 |
663 // TOOD(sushantj): Having this hash_set is avoidable. We currently have it | 664 // TOOD(sushantj): Having this hash_set is avoidable. We currently have it |
664 // only so that we can enforce stringent checks that a caller can not register | 665 // only so that we can enforce stringent checks that a caller can not register |
665 // the same alarm twice. One option is to have an implementation in which | 666 // the same alarm twice. One option is to have an implementation in which |
666 // this hash_set is used only in the debug mode. | 667 // this hash_set is used only in the debug mode. |
667 typedef base::hash_set<AlarmCB*, AlarmCBHash> AlarmCBMap; | 668 using AlarmCBMap = std::unordered_set<AlarmCB*, AlarmCBHash>; |
668 AlarmCBMap all_alarms_; | 669 AlarmCBMap all_alarms_; |
669 | 670 |
670 TimeToAlarmCBMap alarm_map_; | 671 TimeToAlarmCBMap alarm_map_; |
671 | 672 |
672 // The amount of time in microseconds that we'll wait before returning | 673 // The amount of time in microseconds that we'll wait before returning |
673 // from the WaitForEventsAndExecuteCallbacks() function. | 674 // from the WaitForEventsAndExecuteCallbacks() function. |
674 // If this is positive, wait that many microseconds. | 675 // If this is positive, wait that many microseconds. |
675 // If this is negative, wait forever, or for the first event that occurs | 676 // If this is negative, wait forever, or for the first event that occurs |
676 // If this is zero, never wait for an event. | 677 // If this is zero, never wait for an event. |
677 int64_t timeout_in_us_; | 678 int64_t timeout_in_us_; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 unsigned int epoll_wrband; | 909 unsigned int epoll_wrband; |
909 unsigned int epoll_msg; | 910 unsigned int epoll_msg; |
910 unsigned int epoll_err; | 911 unsigned int epoll_err; |
911 unsigned int epoll_hup; | 912 unsigned int epoll_hup; |
912 unsigned int epoll_oneshot; | 913 unsigned int epoll_oneshot; |
913 unsigned int epoll_et; | 914 unsigned int epoll_et; |
914 }; | 915 }; |
915 | 916 |
916 std::vector<DebugOutput*> debug_events_; | 917 std::vector<DebugOutput*> debug_events_; |
917 std::vector<Events> unregistered_fds_; | 918 std::vector<Events> unregistered_fds_; |
918 typedef base::hash_map<int, Events> EventCountsMap; | 919 using EventCountsMap = std::unordered_map<int, Events>; |
919 EventCountsMap event_counts_; | 920 EventCountsMap event_counts_; |
920 int64_t num_records_; | 921 int64_t num_records_; |
921 int64_t record_threshold_; | 922 int64_t record_threshold_; |
922 }; | 923 }; |
923 | 924 |
924 void ClearEventRecords() { | 925 void ClearEventRecords() { |
925 event_recorder_.Clear(); | 926 event_recorder_.Clear(); |
926 } | 927 } |
927 void WriteEventRecords(ostream* os) const { | 928 void WriteEventRecords(ostream* os) const { |
928 (*os) << event_recorder_; | 929 (*os) << event_recorder_; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 | 1035 |
1035 private: | 1036 private: |
1036 EpollServer::AlarmRegToken token_; | 1037 EpollServer::AlarmRegToken token_; |
1037 EpollServer* eps_; | 1038 EpollServer* eps_; |
1038 bool registered_; | 1039 bool registered_; |
1039 }; | 1040 }; |
1040 | 1041 |
1041 } // namespace net | 1042 } // namespace net |
1042 | 1043 |
1043 #endif // NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ | 1044 #endif // NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ |
OLD | NEW |