Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 2 | #include <sdeventplus/event.hpp> |
| 3 | #include <sdeventplus/source/io.hpp> |
William A. Kennington III | 32eef71 | 2022-01-24 17:03:03 -0800 | [diff] [blame] | 4 | #include <stdplus/fd/managed.hpp> |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 5 | |
| 6 | namespace phosphor |
| 7 | { |
| 8 | namespace network |
| 9 | { |
William A. Kennington III | 5f165dc | 2022-10-24 15:58:55 -0700 | [diff] [blame] | 10 | namespace netlink |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 11 | { |
| 12 | |
| 13 | constexpr auto BUFSIZE = 4096; |
| 14 | |
| 15 | /** General rtnetlink server which waits for the POLLIN event |
| 16 | and calls the call back once it gets the event. |
| 17 | Usage would be create the server with the call back |
| 18 | and call the run method. |
| 19 | */ |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 20 | class Server |
| 21 | { |
| 22 | |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 23 | public: |
| 24 | /** @brief Constructor |
| 25 | * |
| 26 | * @details Sets up the server to handle incoming RTNETLINK events |
| 27 | * |
| 28 | * @param[in] eventPtr - Unique ptr reference to sd_event. |
| 29 | * @param[in] socket - netlink socket. |
| 30 | */ |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 31 | Server(sdeventplus::Event& event); |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 32 | |
William A. Kennington III | 32eef71 | 2022-01-24 17:03:03 -0800 | [diff] [blame] | 33 | /** @brief Gets the socket associated with this netlink server */ |
| 34 | inline stdplus::Fd& getSock() |
| 35 | { |
| 36 | return sock; |
| 37 | } |
| 38 | |
| 39 | private: |
| 40 | stdplus::ManagedFd sock; |
William A. Kennington III | 217bb3f | 2022-09-29 13:43:13 -0700 | [diff] [blame] | 41 | sdeventplus::source::IO io; |
Ratan Gupta | 0f9dc1b | 2017-09-03 17:57:50 +0530 | [diff] [blame] | 42 | }; |
| 43 | |
William A. Kennington III | 5f165dc | 2022-10-24 15:58:55 -0700 | [diff] [blame] | 44 | } // namespace netlink |
Gunnar Mills | 57d9c50 | 2018-09-14 14:42:34 -0500 | [diff] [blame] | 45 | } // namespace network |
| 46 | } // namespace phosphor |