|
24 | 24 | #include <cstdint>
|
25 | 25 | #include <unordered_map>
|
26 | 26 | #include <memory>
|
| 27 | +#include <string_view> |
27 | 28 | #include <functional>
|
28 | 29 | #include <shared_mutex>
|
29 | 30 | #include <dpp/thread_pool.h>
|
@@ -74,6 +75,51 @@ using socket_write_event = std::function<void(dpp::socket fd, const struct socke
|
74 | 75 | */
|
75 | 76 | using socket_error_event = std::function<void(dpp::socket fd, const struct socket_events&, int error_code)>;
|
76 | 77 |
|
| 78 | +/** |
| 79 | + * @brief Contains statistics about the IO loop |
| 80 | + */ |
| 81 | +struct DPP_EXPORT socket_stats { |
| 82 | + /** |
| 83 | + * @brief Number of reads since startup |
| 84 | + */ |
| 85 | + uint64_t reads{0}; |
| 86 | + |
| 87 | + /** |
| 88 | + * @brief Number of writes since startup |
| 89 | + */ |
| 90 | + uint64_t writes{0}; |
| 91 | + |
| 92 | + /** |
| 93 | + * @brief Number of errors since startup |
| 94 | + */ |
| 95 | + uint64_t errors{0}; |
| 96 | + |
| 97 | + /** |
| 98 | + * @brief Number of updates to file descriptors |
| 99 | + */ |
| 100 | + uint64_t updates{0}; |
| 101 | + |
| 102 | + /** |
| 103 | + * @brief Number of deletions of file descriptors |
| 104 | + */ |
| 105 | + uint64_t deletions{0}; |
| 106 | + |
| 107 | + /** |
| 108 | + * @brief Number of loop iterations since startup |
| 109 | + */ |
| 110 | + uint64_t iterations{0}; |
| 111 | + |
| 112 | + /** |
| 113 | + * @brief Number of currently active file descriptors |
| 114 | + */ |
| 115 | + uint64_t active_fds{0}; |
| 116 | + |
| 117 | + /** |
| 118 | + * @brief Socket engine type |
| 119 | + */ |
| 120 | + std::string_view engine_type; |
| 121 | +}; |
| 122 | + |
77 | 123 | /**
|
78 | 124 | * @brief Represents an active socket event set in the socket engine.
|
79 | 125 | *
|
@@ -150,21 +196,6 @@ using socket_container = std::unordered_map<dpp::socket, std::unique_ptr<socket_
|
150 | 196 | */
|
151 | 197 | struct DPP_EXPORT socket_engine_base {
|
152 | 198 |
|
153 |
| - /** |
154 |
| - * @brief Mutex for fds |
155 |
| - */ |
156 |
| - std::shared_mutex fds_mutex; |
157 |
| - |
158 |
| - /** |
159 |
| - * @brief File descriptors, and their states |
160 |
| - */ |
161 |
| - socket_container fds; |
162 |
| - |
163 |
| - /** |
164 |
| - * @brief Number of file descriptors we are waiting to delete |
165 |
| - */ |
166 |
| - size_t to_delete_count{0}; |
167 |
| - |
168 | 199 | /**
|
169 | 200 | * @brief Owning cluster
|
170 | 201 | */
|
@@ -238,21 +269,49 @@ struct DPP_EXPORT socket_engine_base {
|
238 | 269 | */
|
239 | 270 | void prune();
|
240 | 271 |
|
| 272 | + /** |
| 273 | + * @brief Merge new flags in with the given file descriptor |
| 274 | + * @param fd file descriptor |
| 275 | + * @param extra_flags extra flags to add |
| 276 | + */ |
| 277 | + void inplace_modify_fd(dpp::socket fd, uint8_t extra_flags); |
| 278 | + |
| 279 | + /** |
| 280 | + * @brief Get statistics for socket engine |
| 281 | + * @return socket stats |
| 282 | + */ |
| 283 | + const socket_stats& get_stats() const; |
| 284 | + |
241 | 285 | protected:
|
242 | 286 |
|
243 | 287 | /**
|
244 |
| - * @brief Called by the prune() function to remove sockets when safe to do so. |
245 |
| - * This is normally at the end or before an iteration of the event loop. |
246 |
| - * @param fd File descriptor to remove |
| 288 | + * @brief Mutex for fds |
247 | 289 | */
|
248 |
| - virtual bool remove_socket(dpp::socket fd); |
| 290 | + std::shared_mutex fds_mutex; |
| 291 | + |
| 292 | + /** |
| 293 | + * @brief File descriptors, and their states |
| 294 | + */ |
| 295 | + socket_container fds; |
| 296 | + |
| 297 | + /** |
| 298 | + * @brief Socket engine statistics |
| 299 | + */ |
| 300 | + socket_stats stats{}; |
249 | 301 |
|
250 | 302 | /**
|
251 | 303 | * @brief Find a file descriptors socket events
|
252 | 304 | * @param fd file descriptor
|
253 | 305 | * @return file descriptor or nullptr if doesn't exist
|
254 | 306 | */
|
255 | 307 | socket_events* get_fd(dpp::socket fd);
|
| 308 | + |
| 309 | + /** |
| 310 | + * @brief Called by the prune() function to remove sockets when safe to do so. |
| 311 | + * This is normally at the end or before an iteration of the event loop. |
| 312 | + * @param fd File descriptor to remove |
| 313 | + */ |
| 314 | + virtual bool remove_socket(dpp::socket fd); |
256 | 315 | };
|
257 | 316 |
|
258 | 317 | /**
|
|
0 commit comments