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