| 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 <memory> |
| 14 #include <string> | 15 #include <string> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 // #define EPOLL_SERVER_EVENT_TRACING 1 | 18 // #define EPOLL_SERVER_EVENT_TRACING 1 |
| 18 // | 19 // |
| 19 // Defining EPOLL_SERVER_EVENT_TRACING | 20 // Defining EPOLL_SERVER_EVENT_TRACING |
| 20 // causes code to exist which didn't before. | 21 // causes code to exist which didn't before. |
| 21 // This code tracks each event generated by the epollserver, | 22 // This code tracks each event generated by the epollserver, |
| 22 // as well as providing a per-fd-registered summary of | 23 // as well as providing a per-fd-registered summary of |
| 23 // events. Note that enabling this code vastly slows | 24 // events. Note that enabling this code vastly slows |
| 24 // down operations, and uses substantially more | 25 // down operations, and uses substantially more |
| 25 // memory. For these reasons, it should only be enabled by developers doing | 26 // memory. For these reasons, it should only be enabled by developers doing |
| 26 // development at their workstations. | 27 // development at their workstations. |
| 27 // | 28 // |
| 28 // A structure called 'EventRecorder' will exist when | 29 // A structure called 'EventRecorder' will exist when |
| 29 // the macro is defined. See the EventRecorder class interface | 30 // the macro is defined. See the EventRecorder class interface |
| 30 // within the EpollServer class for more details. | 31 // within the EpollServer class for more details. |
| 31 #ifdef EPOLL_SERVER_EVENT_TRACING | 32 #ifdef EPOLL_SERVER_EVENT_TRACING |
| 32 #include <ostream> | 33 #include <ostream> |
| 33 #include "base/logging.h" | 34 #include "base/logging.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 #include "base/compiler_specific.h" | 37 #include "base/compiler_specific.h" |
| 37 #include "base/containers/hash_tables.h" | 38 #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 <sys/epoll.h> | 40 #include <sys/epoll.h> |
| 41 | 41 |
| 42 namespace net { | 42 namespace net { |
| 43 | 43 |
| 44 class EpollServer; | 44 class EpollServer; |
| 45 class EpollAlarmCallbackInterface; | 45 class EpollAlarmCallbackInterface; |
| 46 class ReadPipeCallback; | 46 class ReadPipeCallback; |
| 47 | 47 |
| 48 struct EpollEvent { | 48 struct EpollEvent { |
| 49 EpollEvent(int events, bool is_epoll_wait) | 49 EpollEvent(int events, bool is_epoll_wait) |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 #endif | 933 #endif |
| 934 | 934 |
| 935 private: | 935 private: |
| 936 // Helper functions used in the destructor. | 936 // Helper functions used in the destructor. |
| 937 void CleanupFDToCBMap(); | 937 void CleanupFDToCBMap(); |
| 938 void CleanupTimeToAlarmCBMap(); | 938 void CleanupTimeToAlarmCBMap(); |
| 939 | 939 |
| 940 // The callback registered to the fds below. As the purpose of their | 940 // The callback registered to the fds below. As the purpose of their |
| 941 // registration is to wake the epoll server it just clears the pipe and | 941 // registration is to wake the epoll server it just clears the pipe and |
| 942 // returns. | 942 // returns. |
| 943 scoped_ptr<ReadPipeCallback> wake_cb_; | 943 std::unique_ptr<ReadPipeCallback> wake_cb_; |
| 944 | 944 |
| 945 // A pipe owned by the epoll server. The server will be registered to listen | 945 // A pipe owned by the epoll server. The server will be registered to listen |
| 946 // on read_fd_ and can be woken by Wake() which writes to write_fd_. | 946 // on read_fd_ and can be woken by Wake() which writes to write_fd_. |
| 947 int read_fd_; | 947 int read_fd_; |
| 948 int write_fd_; | 948 int write_fd_; |
| 949 | 949 |
| 950 // This boolean is checked to see if it is false at the top of the | 950 // This boolean is checked to see if it is false at the top of the |
| 951 // WaitForEventsAndExecuteCallbacks function. If not, then it either returns | 951 // WaitForEventsAndExecuteCallbacks function. If not, then it either returns |
| 952 // without doing work, and logs to ERROR, or aborts the program (in | 952 // without doing work, and logs to ERROR, or aborts the program (in |
| 953 // DEBUG mode). If so, then it sets the bool to true, does work, and | 953 // DEBUG mode). If so, then it sets the bool to true, does work, and |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1034 |
| 1035 private: | 1035 private: |
| 1036 EpollServer::AlarmRegToken token_; | 1036 EpollServer::AlarmRegToken token_; |
| 1037 EpollServer* eps_; | 1037 EpollServer* eps_; |
| 1038 bool registered_; | 1038 bool registered_; |
| 1039 }; | 1039 }; |
| 1040 | 1040 |
| 1041 } // namespace net | 1041 } // namespace net |
| 1042 | 1042 |
| 1043 #endif // NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ | 1043 #endif // NET_TOOLS_EPOLL_SERVER_EPOLL_SERVER_H_ |
| OLD | NEW |