OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_FLIP_SERVER_EPOLL_SERVER_H_ | 5 #ifndef NET_TOOLS_FLIP_SERVER_EPOLL_SERVER_H_ |
6 #define NET_TOOLS_FLIP_SERVER_EPOLL_SERVER_H_ | 6 #define NET_TOOLS_FLIP_SERVER_EPOLL_SERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <sys/queue.h> | 10 #include <sys/queue.h> |
11 #include <ext/hash_map> // it is annoying that gcc does this. oh well. | |
12 #include <ext/hash_set> | |
13 #include <map> | 11 #include <map> |
14 #include <string> | 12 #include <string> |
15 #include <utility> | 13 #include <utility> |
16 #include <set> | 14 #include <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 when doing | 25 // memory. For these reasons, it should only be enabled when doing |
28 // developer debugging at his/her workstation. | 26 // developer debugging at his/her workstation. |
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 <iostream> | 32 #include <iostream> |
35 #include "base/logging.h" | 33 #include "base/logging.h" |
36 #endif | 34 #endif |
37 | 35 |
38 #include "base/basictypes.h" | 36 #include "base/basictypes.h" |
| 37 #include "base/hash_tables.h" |
39 #include "base/scoped_ptr.h" | 38 #include "base/scoped_ptr.h" |
40 #include <sys/epoll.h> | 39 #include <sys/epoll.h> |
41 | 40 |
42 namespace net { | 41 namespace net { |
43 | 42 |
44 class EpollServer; | 43 class EpollServer; |
45 class EpollAlarmCallbackInterface; | 44 class EpollAlarmCallbackInterface; |
46 class ReadPipeCallback; | 45 class ReadPipeCallback; |
47 | 46 |
48 struct EpollEvent { | 47 struct EpollEvent { |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 mutable bool in_use; | 566 mutable bool in_use; |
568 }; | 567 }; |
569 | 568 |
570 // Custom hash function to be used by hash_set. | 569 // Custom hash function to be used by hash_set. |
571 struct CBAndEventMaskHash { | 570 struct CBAndEventMaskHash { |
572 size_t operator()(const CBAndEventMask& cb_and_eventmask) const { | 571 size_t operator()(const CBAndEventMask& cb_and_eventmask) const { |
573 return static_cast<size_t>(cb_and_eventmask.fd); | 572 return static_cast<size_t>(cb_and_eventmask.fd); |
574 } | 573 } |
575 }; | 574 }; |
576 | 575 |
577 typedef __gnu_cxx::hash_set<CBAndEventMask, CBAndEventMaskHash> FDToCBMap; | 576 typedef base::hash_set<CBAndEventMask, CBAndEventMaskHash> FDToCBMap; |
578 | 577 |
579 // the following four functions are OS-specific, and are likely | 578 // the following four functions are OS-specific, and are likely |
580 // to be changed in a subclass if the poll/select method is changed | 579 // to be changed in a subclass if the poll/select method is changed |
581 // from epoll. | 580 // from epoll. |
582 | 581 |
583 // Summary: | 582 // Summary: |
584 // Deletes a file-descriptor from the set of FDs that should be | 583 // Deletes a file-descriptor from the set of FDs that should be |
585 // monitored with epoll. | 584 // monitored with epoll. |
586 // Note that this only deals with modifying data relating -directly- | 585 // Note that this only deals with modifying data relating -directly- |
587 // with the epoll call-- it does not modify any data within the | 586 // with the epoll call-- it does not modify any data within the |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 unsigned int epoll_wrband; | 935 unsigned int epoll_wrband; |
937 unsigned int epoll_msg; | 936 unsigned int epoll_msg; |
938 unsigned int epoll_err; | 937 unsigned int epoll_err; |
939 unsigned int epoll_hup; | 938 unsigned int epoll_hup; |
940 unsigned int epoll_oneshot; | 939 unsigned int epoll_oneshot; |
941 unsigned int epoll_et; | 940 unsigned int epoll_et; |
942 }; | 941 }; |
943 | 942 |
944 std::vector<DebugOutput*> debug_events_; | 943 std::vector<DebugOutput*> debug_events_; |
945 std::vector<Events> unregistered_fds_; | 944 std::vector<Events> unregistered_fds_; |
946 typedef __gnu_cxx::hash_map<int, Events> EventCountsMap; | 945 typedef base::hash_map<int, Events> EventCountsMap; |
947 EventCountsMap event_counts_; | 946 EventCountsMap event_counts_; |
948 int64 num_records_; | 947 int64 num_records_; |
949 int64 record_threshold_; | 948 int64 record_threshold_; |
950 }; | 949 }; |
951 | 950 |
952 void ClearEventRecords() { | 951 void ClearEventRecords() { |
953 event_recorder_.Clear(); | 952 event_recorder_.Clear(); |
954 } | 953 } |
955 void WriteEventRecords(ostream* os) const { | 954 void WriteEventRecords(ostream* os) const { |
956 (*os) << event_recorder_; | 955 (*os) << event_recorder_; |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 private: | 1062 private: |
1064 EpollServer::AlarmRegToken token_; | 1063 EpollServer::AlarmRegToken token_; |
1065 EpollServer* eps_; | 1064 EpollServer* eps_; |
1066 bool registered_; | 1065 bool registered_; |
1067 }; | 1066 }; |
1068 | 1067 |
1069 } // namespace net | 1068 } // namespace net |
1070 | 1069 |
1071 #endif // NET_TOOLS_FLIP_SERVER_EPOLL_SERVER_H_ | 1070 #endif // NET_TOOLS_FLIP_SERVER_EPOLL_SERVER_H_ |
1072 | 1071 |
OLD | NEW |