Benjamin Fair | 545f565 | 2019-10-09 14:18:54 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "data_handler.hpp" |
| 4 | |
| 5 | #include <unistd.h> |
| 6 | |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 7 | #include <stdplus/handle/managed.hpp> |
| 8 | |
Benjamin Fair | 545f565 | 2019-10-09 14:18:54 -0700 | [diff] [blame] | 9 | #include <cstdint> |
| 10 | #include <optional> |
Benjamin Fair | 545f565 | 2019-10-09 14:18:54 -0700 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
| 13 | namespace ipmi_flash |
| 14 | { |
| 15 | |
| 16 | /** |
| 17 | * Data Handler for receiving the image over a network port |
| 18 | */ |
| 19 | class NetDataHandler : public DataInterface |
| 20 | { |
| 21 | public: |
Patrick Williams | 1038836 | 2023-05-10 07:51:09 -0500 | [diff] [blame^] | 22 | NetDataHandler() : listenFd(std::nullopt), connFd(std::nullopt) {} |
Benjamin Fair | 545f565 | 2019-10-09 14:18:54 -0700 | [diff] [blame] | 23 | |
| 24 | bool open() override; |
| 25 | bool close() override; |
| 26 | std::vector<std::uint8_t> copyFrom(std::uint32_t length) override; |
| 27 | bool writeMeta(const std::vector<std::uint8_t>& configuration) override; |
| 28 | std::vector<std::uint8_t> readMeta() override; |
| 29 | |
| 30 | static constexpr std::uint16_t listenPort = 623; |
| 31 | static constexpr int timeoutS = 5; |
| 32 | |
| 33 | private: |
| 34 | static void closefd(int&& fd) |
| 35 | { |
| 36 | ::close(fd); |
| 37 | } |
| 38 | using Fd = stdplus::Managed<int>::Handle<closefd>; |
| 39 | |
| 40 | Fd listenFd; |
| 41 | Fd connFd; |
| 42 | }; |
| 43 | |
| 44 | } // namespace ipmi_flash |