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